Introduction
In this brief article, we'll see how to install a LAMP server (acronym for "Linux Apache MySQL PHP") with a single shell command, resulting in a perfectly working webserver. The following instructions applies to any Debian-based Linux distribution, such as Ubuntu and the like.
Update package list
Before we proceed, it's useful to resynchronize our package index file, to be sure the software we'll install later is up-to-date. This operation can be done by opening a Terminal and executing in the shell the command:
Note: the operations we are doing here requires root privileges, so the user we use must be in the sudoers group, or alternatively we could rely directly on the root user (strongly discouraged, but there may be cases in which there are no alternatives).
Install LAMP server
As I stated above, the procedure to install a full LAMP server will be a one-liner. In your shell, enter the following instruction:
- sudo apt-get install apache2 mysql-server php5 php5-mysql
Or, if you wish to install phpMyAdmin along with the other packages, to have a useful web frontend for your MySQL server, you could execute the following:
- sudo apt-get install apache2 mysql-server php5 php5-mysql phpmyadmin
Pressing "Enter", the setup will start. The only information it will require is a password for the user root in MySQL (the following screenshot is in Italian, but its pretty self-explanatory. Let's just enter a password we will use later).
That's it, our installation is finished. To be sure everything will work correctly, just restart the Apache service as in the following:
- sudo service apache2 restart
Test PHP functionality
The last thing to do is to verify the PHP configuration, along with the webserver capability to interpret PHP syntax. We can create a PHP file under the /var/www folder that will be web-accessible.
Inside that file, write the following:
Then exit and save by pressing Ctrl + X, confirming the intent to write changes to the disk. What we've done here is simply to call the phpinfo() function that will provide us a list of the status of every parameter configured.
We can access that webpage by executing a web browser and navigating to localhost/index.php. If you see an output like the following, everything went OK.
We are now ready to use our brand new personal web server.