The acronym LAMP refers to the first letters of Linux (operating system), Apache HTTP Server, MySQL (database software, but now sometimes MariaDB) and PHP, Perl or Python, principal components to build a viable general purpose web server.
This article explains how to install LAMP on Ubuntu, and has been updated for Ubuntu 12.10. With a few minor modifications to the post, it also equally applies to explain how to install LAMP on Debian or other Ubuntu versions.
Installing LAMP on Ubuntu is pretty straight-forward. Once you install tasksel, installing LAMP on Ubuntu becomes very simple.
sudo apt-get install tasksel sudo apt-get update
Now install the task:
You can either go for the interactive prompt by starting up tasksel:
sudo tasksel install lamp-server
You will be asked for mysql password thrice:
Now install the following for completion’s sake (I found that a couple of these didnt auto-install on my PC):
sudo apt-get install mysql-server libapache2-mod-auth-mysql php5-mysql phpmyadmin
When asked about which server to reconfigure, choose apache2.
Also choose “Yes” when asked: Configure database for phpmyadmin with dbconfig-common?
You will again be asked for the mysql root password twice.
At this point, LAMP has been installed without any configuration. You can see that it was successful by calling up
from any web browser.
Now, Phpmyadmin (if you didnt install it earlier):
sudo apt-get install phpmyadmin
sudo service apache2 restart
Optionally now edit:
sudo emacs /etc/apache2/httpd.conf
And add this:
This is the fix for the message:
* Restarting web server apache2 apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName ... waiting apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
Run web content stored in your user directory
To run content from your user directory, do the following:
Enable the module:
a2enmod userdir service apache2 restart
Now edit /etc/apache2/mods-enabled/userdir.conf
emacs /etc/apache2/mods-enabled/userdir.conf[/code] Make sure that it looks like this:<IfModule mod_userdir.c> UserDir public_html UserDir disabled root <Directory /home/*/public_html> AllowOverride All Options MultiViews Indexes SymLinksIfOwnerMatch <Limit GET POST OPTIONS> Order allow,deny Allow from all </Limit> <LimitExcept GET POST OPTIONS> Order deny,allow Deny from all </LimitExcept> </Directory> </IfModule>[/code] Note that you will have to delete parts of a few lines. Or you can exec the following:sudo cat /etc/apache2/mods-enabled/userdir.conf | sed 's/AllowOverride FileInfo.*/AllowOverride All/' >test.txt sudo mv test.txt /etc/apache2/mods-enabled/userdir.conf sudo cat /etc/apache2/mods-enabled/userdir.conf | sed 's/Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec.*/Options MultiViews Indexes SymLinksIfOwnerMatch/' >test.txt sudo mv test.txt /etc/apache2/mods-enabled/userdir.conf[/code] which does the edit automatically. Now as normal user, create a public_html folder:exit mkdir /home/$USER/public_html[/code] Now change group and restart the web server:su chgrp www-data /home/$USER/public_html service apache2 restart[/code]
Run php scripts from user directoriesTo allow running php scripts from user directories, Configure the file /etc/apache2/mods-available/php5.conf :emacs /etc/apache2/mods-available/php5.conf[/code]<IfModule mod_php5.c> <FilesMatch "\.ph(p3?|tml)$"> SetHandler application/x-httpd-php </FilesMatch> <FilesMatch "\.phps$"> SetHandler application/x-httpd-php-source </FilesMatch> # To re-enable php in user directories comment the following lines # (from <IfModule ...> to </IfModule>.) Do NOT set it to On as it # prevents .htaccess files from disabling it. #<IfModule mod_userdir.c> # <Directory /home/*/public_html> # php_admin_value engine Off # </Directory> #</IfModule> </IfModule>[/code] As mentioned in the instructions in this file, you need to comment out the later part.
Check that everything works:Check that public_html can be accessed from localhost. Create a file index.html in ~/public_html:<html> <h2> Test succeeded </h2> </html>[/code] Now, type in the browser address bar:http://localhost/~droidzone/[/code] If all goes well, you should get the success message. Now test php. Create the file ~/public_html/phptest.php:<?php phpinfo(); ?>[/code] Now restart the web serversudo service apache2 restart[/code] and enter the following address in the browser:http://localhost/~droidzone/phptest[/code] Of course you have to replace your username for droidzone. If it gives an error message or the file browser is displayed instead of a webpage, recheck the instructions. If they were correct, in most cases, you need to just restart apache2 service.
Configure a passwordless login with phpmyadmin (Not recommended, Optional):cat /etc/phpmyadmin/config.inc.php | grep -ni --color 'AllowNoPassword' 65: // $cfg['Servers'][$i]['AllowNoPassword'] = TRUE; 94:// $cfg['Servers'][$i]['AllowNoPassword'] = TRUE;[/code] Now change the Line #65 (the first hit) to remove the comment tag at the beginning. You can login to phpmyadmin at http://localhost/phpmyadmin
Bugs and fixes:If tasksel didnt work, you can install the following to get the same effect:sudo apt-get install libmysqlclient18 apache2 php5-cli apache2.2-common apache2-utils libswitch-perl php5-common libaprutil1-ldap libdbi-perl mysql-server apache2.2-bin libdbd-mysql-perl libhtml-template-perl perl-modules libnet-daemon-perl libxml2 libapr1 mysql-server-core-5.5 libaio1 libterm-readkey-perl apache2-mpm-prefork libwrap0 libaprutil1-dbd-sqlite3 tcpd xml-core libapache2-mod-php5 libaprutil1 libclass-isa-perl php5-mysql libplrpc-perl sgml-base mysql-client-5.5 mysql-server-5.5 libcap2 perl mysql-client-core-5.5 ssl-cert mysql-common mysql-server libapache2-mod-auth-mysql php5-mysql phpmyadmin
Joel G Mathew, known in tech circles by the pseudonym Droidzone, is an opensource and programming enthusiast.
His favorite pastime is grappling with GNU compilers, discovering newer Linux secrets, writing scripts, hacking roms, and programs (nothing illegal), reading, blogging. and testing out the latest gadgets.
When away from the tech world, Dr Joel G. Mathew is a practising ENT Surgeon, busy with surgeries and clinical practise.