Ceci est une ancienne révision du document !
The “LAMP Stack” is traditionally Linux, Apache, MySQL, and PHP. This is the most necessary portion of any server to any web developer, whether you’re specializing in PHP or even mobile development. You just simply cannot develop a web site or web app without a web server. Of course, there are other flavors of web servers that use other technology, but this is the standard and will be our starting point.
For the sake of this new column, I have set up a new Virtual Server to go through with you as we go. My server is running Ubuntu Server 64bit 10.10. This month we will get Apache2 installed and configured. I am also assuming you know how to edit files using terminal and vi, this is what we will be using the whole time. Let’s jump right into that.
If you are not root (and you shouldn’t be for security reasons), you need to run apt-get commands using sudo, and all my examples will assume you are logged in as a user. Run the following code to install apache2:
sudo apt-get install apache2
By default, now it works. It is listening to all IP’s available to it, anything coming to that box on port 80 will now go to the default web site. Pretty easy stuff so far. All of your files will be located in the following directory:
/srv/www/
I have a feeling that we will want a few different sites to play around with, so I am going to show you how I set things up. Instead of using the default path and apache config setup, we will use virtual hosts. From here on out, I will use example.com. You will want to replace that with your own domain name.
Make a new virtual host config file into /etc/apache2/sites-available/ with the following command:
sudo vi /etc/apache2/sites-available/example.com
Now let’s get some config in there. Go ahead and use the simple sample configuration shown above.
Remember to change example.com to your doman name. This stuff is kind of boring so I am just going to run through it really quickly. ServerAdmin is for the email address of who (or a group that) maintains the site. ServerName should be the base name of the site. Please note, if your site is a sub-domain then you will need to put x.example.com in the ServerName. The ServerAlias is the full web address that will be going to your site. DocumentRoot is where all of your public files will be held. I took the liberty of giving you error log reporting to make finding and fixing problems easier in the future. Before any of that will work, we need to create those directories for real. That, of course, is as easy as making directories:
mkdir -p /srv/www/example.com/public_html
mkdir /srv/www/example.com/logs
Sweet, now we got some stuff going on. Now let’s activate that bad boy:
sudo a2ensite example.com
sudo /etc/init.d/apache2 reload
The a2ensite is actually a really cool command. It says apache2, enable site x. There is also a2dissite for disabling. This will use the site config files we made in the sites-available directory and copy them into the sites-enabled directory. Although we could do it ourselves, it is just good practice to let apache handle its own files when it is able. The other statement there is telling apache to reload its configuration files.
Well, that is it for this month.
Next time we will be installing PHP and MySQL to complete the LAMP stack.