Practice
So, we have Linux Debian (in our example - this is 6.0 Squeeze). It doesn't have MySQL, Apache, or PHP installed by default. And we need it to have them.
Let's make it happen.
MySQL
First, let's install MySQL:
During the MySQL installation, it will ask for a password for the local root user. Enter this password carefully - this is the only user that will exist right after installing "mysql" and under which you will administer the server.
After installation, let's check that aptitude started the MySQL server on its own:
If a bunch of various info shows up - that means the server is running. If not - let's start it:
And, finally, let's check the connection to the server:
Here we enter the password set above. If everything is fine (we were let into MySQL and saw the cherished "mysql>" prompt) - then you did everything right.
If you need to change the MySQL settings, it's worth knowing where they are. The server settings are located at:
Now let's run the script:
Enter the previously set password and perform the actions suggested by the script (temporary databases are removed, external access is removed, etc.)
Apache
Besides MySQL, LAMP also includes Apache and PHP. Now let's take care of installing the first one - Apache, in our case - Apache 2.
Again we turn to aptitude for help:
Actually, this way we're installing Apache without SSL support. I won't describe setting up SSL support here - there's a detailed article on this topic on this same site (SSL Apache Debian).
Now let's go to the /etc/apache2 directory and open the apache2.conf file. We need to add the "ServerName" option here and set the server name in it. Apache can, of course, read it itself from hostname or hostname.domain, but it's better to statically define yourself how the server will be named. The thing is, the server name will appear in messages and error pages.
After this, let's restart the Apache server:
In the default configuration we have a site named default. The site description (configuration) is located in the /etc/init.d/apache2/sites-available directory and a symbolic link is made in the /etc/init.d/apache2/sites-enabled directory.
Thus, the /etc/init.d/apache2/sites-available directory holds all the sites,
while the /etc/init.d/apache2/sites-enabled directory holds only those that Apache should actually serve. Or more precisely - symbolic links to files from the available sites directory.
To create a site you will need a directory for this site in the Linux file system and a site configuration file. So, for example, we want to place a site in the /www/mysite.ru directory.
1) Create the /www directory (by default it doesn't exist and Apache takes the default site from the /var/www folder):
Here we create a directory for all the sites, make Apache the owner of the directory (so the server itself can do whatever it wants inside it - a debatable security model, but for simplicity we do it this way) and assign write permissions to the www-data user and all users in the www-data group and read permissions for everyone else.
And here we create the site's folder. Yes, we need to assign the owner and permissions again - since we create it under sudo (root), the owner user is automatically set to root, which is not good for Apache (it will work, but if your site is supposed to write anything to it - it will immediately fail).
2) Create the site's configuration file:
Here we create a file mysite.ru with the following content:
Here we specified that connections to the mysite.ru site should be accepted, that www.mysite.ru is the same thing as mysite.ru, that index.php should be used as the starting page, and that the site itself is located at /www/mysite.ru
For the site to work - you need to create a symbolic link to it in the /etc/apache2/sites-enabled directory. For example, if we named the configuration file mysite.ru, then we create the symbolic link like this:
After any configuration changes, you need to ask Apache to reload its configs, which we do with the following command:
At this point we can conclude the initial Apache setup - after all, this article only describes installing LAMP, not the finer points of configuration.
To check that Apache is working - go through your browser to the IP address of your server - you should see a message something like "Hooray, I'm Apache and I'm working, rejoice, admin".
PHP
It is assumed that PHP 5.3 will be used (version 5.2 has been discontinued and its last version is 5.2.17).
By default Debian offers packages for installing PHP 5.3, however the PHP version in this OS is updated extremely rarely, which is not great from a security and functionality standpoint.
If you're fine with PHP 5.3.3 (or whatever version is the latest in Debian Squeeze at the time you're reading this article) - then it's simple - do this:
It will pull in everything it needs on its own and make a link to the configuration in /etc/apache2/mods-enabled.
If you want to have an updatable, always-latest PHP 5.3, there are 2 options: either regularly check for updates on the PHP website and download the distributions, installing from source, or find a repository that does this for us. I'll take you down the second path, as the simpler one.
A repository already exists and is located at www.dotdeb.org.
The site is confusing and it's not that easy to find the installation links there, so I'll give you the ready-made version.
So, to install PHP 5.3 from this site, do the following.
1) First you need to install the digital signature for packages from this site:
If it didn't work (it happens... for various reasons - the server is busy, for example) - you can do it manually:
2) Now let's go to /etc/apt and edit the sources.list file
We need to add the following lines to the file:
3) Update the package list
4) Install PHP
This will install the Apache plugin and the minimal set of functionality.
If the utility asks whether to remove apache2-worker - agree - its own package will be installed instead.
With the command
you can see how many more PHP plugins can be installed. For example, the following ones are often used (here's the command to install them right away):
After this we restart Apache to apply the changes (so it understands that PHP has appeared).
P.S. Technically, the graceful command is used to reload configs, but I prefer to make serious changes via a full service restart.
phpmyadmin
The next step is to install a web console for working with the MySQL server. The time-tested phpmyadmin is used on most hosting providers. Even though it's often faster to do everything by hand via ssh and mysql, the web console can be indispensable. And, of course, it's more intuitive than low-level sql commands.
During installation you will be asked which web servers (apache, lighthttpd) to immediately hook up the phpmyadmin configuration to. Select Apache and move on.
The next question will be whether to set up the phpmyadmin database by default. If you don't have a clue what this database is or what to do with it - answer "Yes".
And the last questions will be about passwords. First - the password for the MySQL server. Enter the password we specified in the MySQL installation section. Next it asks for a password for phpmyadmin itself to access the database. If we leave the field empty - it will be generated randomly. You won't need to enter this password anywhere - it's solely for the service's own needs, so we can safely press Enter.
That's it, such a useful thing as phpmyadmin is installed. You can access it through the site at YOUR_IP/phpmyadmin, where instead of YOUR_IP you put the IP address of your server.
This concludes our efforts to install a LAMP server. As a bonus, I'd like to say that all of this happens almost automatically when you select the corresponding menu items during Debian system installation, but if we want to do it manually, or if the OS is already installed and now we need to set up a web server - then the guide above shows how to do it.
P.S. Just so you know, a web server is not a DNS server, that's something to keep in mind. It is assumed that you already have a DNS server, on which you can specify the domain zones that this web server will serve. If not - on this same site there's an article about setting up (and installing) a bind server (named), which can be installed on the same machine as the web server, and which will faithfully and enthusiastically serve as your DNS server.
Comments