How to install LAMP manually in 60 seconds

How to install LAMP manually in 60 seconds

It usually takes me a few good minutes to get the LAMP stack (Linux Apache MySQL PHP) installed and many more to get it configured to fit my needs. Well, I’ve finally managed to get it all together into a little something that can be done in under a minute. Assuming you’re doing this on a reasonably fresh Linux installation, these following lines will get you through with no problems and you’ll be the proud user of Apache 2.4 + PHP 5.6 + MySQL 5.6 in no time:

First, install a mother-load of packages (basically Apache, PHP, MySQL, phpMyAdmin and MySQL Workbench):

sudo apt-get install apache2 mysql-server mysql-workbench php5 curl php5-curl mcrypt php5-mcrypt php5-imagick php5-gd php5-xdebug phpmyadmin

Then, a few useful Apache modules:

sudo a2enmod rewrite headers expires deflate

Yeah… we might get a nasty looking message every time we restart the apache server, something like this:

apache2: Could not reliably determine the server’s fully qualified domain name, using Set the ‘ServerName’ directive globally to suppress this message.

To get rid of that, we have to define the ServerName and include it in our configuration file.


sudo nano /etc/apache2/httpd.conf

This file might be blank, but add the following line to it anyway:

ServerName localhost

Then add these references to the apache2.conf file


Include httpd.conf
Include /etc/phpmyadmin/apache.conf

Cool, now as a security measure, it would seem that in newer Apache releases, the default document root points to /var/www/html instead of directly to /var/www. We might as well rename that html to public_html and update some configs.


sudo nano /etc/apache2/sites-available/000-default.conf

And change the DocumentRoot to this:

DocumentRoot /var/www/public_html

Also, while we’re in here we should add a few lines to prevent mod_rewrite from having girl problems later in life:

<Directory />
    Options FollowSymLinks
    AllowOverride None
<Directory /var/www/public_html/>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride all
    Order allow,deny
    allow from all

Also, there might be some trouble with PHP’s mcrypt extension, so let’s make sure it actually gets loaded:


sudo nano /etc/php5/apache2/php.ini

Go down to Dynamic Extensions and add this line if it doesn’t exist:


And… that should be it – restart the web server and go to http://localhost/ to test the installation:

sudo service apache2 restart

Also, just for the thrill, you can make a phpinfo.php file in /var/www/public_html with just this:

<?php phpinfo(); ?>

to review all the modules and extensions that have been miraculously installed on your system.

Also, a quick tip on the nano editor if you haven’t moved on to vim already. Tab size should be 4 spaces – that’s it – period. If there’s already a .nanorc file in your home directory, add this line to it or create if first otherwise (dooh~)

set tabsize 4