Setting Up CentOS 6.4 For Web Development
CentOS 6.4 has been out for a while, and two production servers I use frequently both run CentOS. Where Linux is concerned, I’ve tended to stick with Ubuntu. So, I decided to have a go at setting up CentOS for web development. Here’s the first part of how I got on.
I chose to download the 64-bit live DVD because… Well, I’m a total noob with CentOS so I figured it was the best option.
The installation was easy, perhaps not quite Ubuntu easy, but still easy. You get asked questions like this:
That are easy to answer when you are installing inside a virtual machine. The installation itself runs through quite quickly:
When it finishes, it just a case of re-starting the VM, creating a user and adding a root password. All of which are completed using a pleasant GUI interface.
Then, you land on the attractive Gnome desktop:
What About Apache and MySQL on CentOS ?
I assumed that they would already be installed, and I assumed correctly. However, there is some work to do to get things working how I like them.
We’ll deal with the basics first.
To start Apache, drop on the command line and do:
service httpd start
You need to be root to do that. There is no
sudo by default, but you can enable it, so let’s do that.
First, in Terminal,
su as the root user. Then type:
You need to scroll down until you see this:
root ALL=(ALL) ALL
And copy the line using your own name:
yourname ALL=(ALL) ALL
Save the file, an now you can use
sudo for typing root user commands.
To continue with our Apache configuration, we need to edit the
.conf file. So in terminal do:
sudo gedit /etc/httpd/conf/httpd.conf
First, make sure all instances of
AllowOverride are set to
All. That’s so you can use .htaccess files with your web apps.
Next, find this section:
<IfModule mod_userdir.c> # # UserDir is disabled by default since it can confirm the presence # of a username on the system (depending on home directory # permissions). # #UserDir disabled UserDir "enabled *" UserDir "disabled root" # # To enable requests to /~user/ to serve the user's public_html # directory, remove the "UserDir disabled" line above, and uncomment # the following line instead: # UserDir public_html </IfModule>
And make yours look like mine above. What this does, is makes sure that you can use a folder called
public_html in your home directory to store your web apps. It also makes sure that it’s disabled for the root user for security reasons.
Next, we need to deal with permissions.
This section is important because nothing will work quite the way you might think without setting the following:
chmod 711 /home chmod 711 /home/yourusername chmod 755 /home/yourusername/public_html
What are we setting here? First, your home directory gets:
- 7 = 4+2+1: you can read/write/execute
- 1 = Other users in your group can cd/execute but not read or write
- 1 = Other users not in your group can cd/execute but not read or write
- 7 = 4+2+1: You can read/write/execute
- 5 = 4+1: Other users in your group can cd/execute/read but not write
- 5 = 4+1: Other users not in your group can cd/execute/read but not write
You are probably going to want to be able to set up more than one web app for local development. That means you’ll need to virtual hosts.
So, it’s back to Terminal, and open the Apache conf file once more:
sudo gedit /etc/httpd/conf/httpd.conf
Right at the bottom of the file you should add this:
<VirtualHost *:80> Servername yourname.dev ServerAlias yourname.dev DocumentRoot /home/yourname/public_html </VirtualHost>
Save and close the file. Next, open:
sudo gedit /etc/hosts and add this line:
Then we restart Apache with:
service httpd restart. Now you should be able to go to:
http://yourname.dev and be greeted by the Apache welcome page.
As I said, I’m a complete noob with CentOS. That means there are other/better ways to get this stuff done. However, the above worked for me, so in the next post, we’ll install PHP.
(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)