Installing a LAMP Server on Ubuntu
Ubuntu LAMP Server
When working on web development, I prefer to work within the privacy of my own development environment located on my computer. I'd rather make the majority of my mistakes where no one else can see them rather than out in the wild of the Internet. In order to have that private development environment, I install a LAMP configuration. If you're not familiar with LAMP, it stands for Linux, Apache, MySQL, php (and/or Perl). LAMP is one of the most common web hosting platforms on the Internet, so it's a great environment to build and test your website.
Follow these step by step instructions to install and configure LAMP on Ubuntu 12.04-Precise Pangolin. This process has also been tested and works on Linux Mint 13, Linux Mint 14, Ubuntu 12.10-Quantal Quetzal and Ubuntu 13.04 Raring Ringtail. If you have a reasonably fast broadband connection, you should be done in less than half an hour.
Ubuntu LAMP Installation
The developers at Ubuntu have made it really easy to install and configure the packages for LAMP with a single terminal command. So open up a terminal window and let's get started.
Yes, you read that right. Don't leave out the caret (^) at the end. The command won't work without it. It's magical!
The apt package manager will now show the packages to be installed and ask for confirmation. Hit <Enter> to confirm and continue with the install.
After some time downloading packages, you will be prompted to set a password for the root user for MySQL.
Enter the password you want to use for MySQL. Do not leave it blank. You'll be prompted a second time to confirm your password.
After confirming your password, apt will continue installing the remaining packages.
Your LAMP installation is now complete. Wow, that was easy! Now there's just a few more steps to get things configured to make it easy to work with your system.
Test Apache
Open a web browser window and enter the address http://localhost/. You should see a web page that says "It Works!"
Test php
Now that you've confirmed that the Apache web server works, you want to make sure that your php installation is working. To do that you need to create a file in /var/www called testing.php. You can use your favorite text editor as root, or you can use the following terminal command:
After that you need to restart the Apache web server.
Go back to your web browser and enter the address http://localhost/testing.php/ and you should see a page displaying information about your php installation.
Fix Apache fully qualified domain name
You may have noticed an error message from Apache about the server's fully qualified domain name.
apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
This is not a big deal, but if it bothers you, you can fix it with the following commands.
Now reload the Apache web server.
You should no longer see the error message.
Configure MySQL
Since this tutorial is for setting up a local web development environment, the MySQL needs to be bound to the localhost IP address. By default this should be 127.0.0.1 on your system. Just in case, you can verify it with these commands.
You should see something like
127.0.0.1 localhost
::1 ip6-localhost ip6-loopback
You now want to verify that you have the correct bind address in MySQL's my.cnf file.
You should see:
bind-address = 127.0.0.1
If the bind address doesn't match the one set for localhost on your system, you'll need to edit /etc/mysql/my.cnf as root to correct it.
Install phpMyAdmin
You don't need to install phpMyAdmin, but unless you're a wizard with SQL, you'll want it to do administrative tasks on your MySQL databases.
You can install phpMyAdmin with this terminal command:
You'll be prompted to confirm that you want to install the packages. Hit <Enter> to continue.
You'll next be prompted to select a web server to configure with phpMyAdmin. This is important! Use the arrow keys on your keyboard to highlight apache2 and then used the space bar to select it. Then hit <Enter> to continue. Make sure to click the picture below to see it in full size to see what I'm describing.
The next screen will ask if you want to configure phpMyAdmin with a database called dbconfig-common. Select "Yes" and hit <Enter>.
You'll next be prompted to enter the MySQL root password you created earlier so that the new database can be created. So enter your MySQL root password and hit <Enter>.
The next prompt is to create a MySQL application password for phpMyAdmin. You can hit <Enter> if you want a random password to be created. I usually use the same password that I used for the MySQL root password. It's probably not the greatest idea in terms of security, but since this is for a closed development environment, it's probably low risk.
Finally, you'll be prompted to confirm your MySQL application password. Type the same password as the previous step and hit <Enter>.
Installing and configuring phpMyAdmin is now complete.
Testing phpMyAdmin
The last step is to make sure that phpMyAdmin is working. Open a web browser and enter the address http://localhost/phpmyadmin/. You should see a page that looks like this.
You should now be able to log in with the username root and the root password that you created earlier.
Congratulations, you are now done installing and configuring LAMP and phpMyAdmin on Ubuntu 12.04. You can now start building the local version of your website. If you are only working on one site, you can place your files in /var/www. Note that /var/www is owned by the user and group root, so you will either need to copy files over as root, or change the ownership and/or permissions of that directory so you can write your files there. As an alternative, you can do some additional Apache configuration so that you can keep your files somewhere under your home directory. You can even set up multiple sites that way.
If you've run into some problems, check out Fixing Common Problems with LAMP on Ubuntu. If things seem horribly broken and you want to start fresh, try Uninstalling LAMP from Ubuntu.


















thank you so much!. Excelent!
Very many thanks for this. Most useful.
Best wishes
Peter Jones
Crawley, West Sussex
UK
Interesting one!!!
Helpful for me !!
Thanks
Why restarting Apache after creating the testing.php file???
As to the real why, I don't know. I just know I've needed to do that since Ubuntu 9.04 and honestly, I haven't tried not restarting Apache at this step. Maybe I'll try it tonight and see if it's still required. Thanks for your comment/question.
Excellent question! There was no need at all to restart Apache. I've updated the tutorial. Thanks again for your question.
Just added the Apache restart back to my post as some people were having problems with php files without the restart.
Thank you
I like your way of creating tutorials.
Very Helpful
very grateful because since long time I've been trying to resolve this problem that appeared when I upgrade to Ubuntu 12.04. Before this aplication was working well.
Thanks again.
Francisco Pérez
Programador
Great tutorial! Thank you so much! I love it.
One little thing: The link under 'Apache Configuration' isn't working anymore.
I love you!
Thank you so much for the work, clear and objective, I would give a little help to improve this tutorial.
For those who could not access phpmyadmin after installation, as I researched a simple solution in a forum here in Brazil:
macquley: "you must create a symbolic link to /var/www by default because phpmyadmin is installed in usr/share/ follows the command:
sudo ln-s /usr/share/phpmyadmin /var/www/phpmyadmin
, now in just access your browser http://localhost/phpmyadmin"
link references: http://www.vivaolinux.com.br/topico/MySQL/Problemas-na-instalacao-do-PHPMyAdmin
I hope this helps.
You can also easily fix the phpMyAdmin 404 error by following this process: http://tuxtweaks.com/2012/05/fixing-common-problems-with-lamp-on-ubuntu/
I found your site by accident after following another lamp install wicki, that caused endless problems. Your un-install link worked great. I did not want to try and un-install loads of seperate files (not clever enough !)
If I now have a lamp server, could you do a tutorial on how to get my web page on to it ?
All the how too? assume we all know how to do it I am a learner and am not sure what to do next.
Your tutorial was very clear just what is needed,thank you.
If you'd like to make a website using WordPress, you can follow my tutorial. http://tuxtweaks.com/2009/11/how-to-install-wordpress-on-ubuntu-part-1/
Good work here!!!
Really very nice............
great tutorial. i think you forgot to include installing phpmyadmin
sudo apt-get install phpmyadmin
so you'll not get phpmyadmin 404 error.
phpMyAdmin installation is shown on page two of this post: http://tuxtweaks.com/2012/04/installing-lamp-on-ubuntu-12-04-precise-pangolin/2/
Thanks very much! The exact steps installations on the newly installed ubuntu 12.04. Thank you!
This worked great - thanks.
Thanks Aloat
Thanks for this post. Just so that others may benefit, the installation did not put phpmyadmin. I had to do this separately.
Installation of phpMyAdmin is covered on page 2 of this post.
This is very excellent LAMP installing process. I think it is more user friendly process than ever, everybody will install it easily by having little command in English and about command line. I again thank the developers for contributing in this respect.
The content was really useful and clearly explained.Thank you ....
WOW! That's work on my Computer...Thanks a lot..