LAMP Installation On Ubuntu
The acronym LAMP refers to a set of free software programs commonly used together to run dynamic Web sites or servers Linux, the operating system; Apache, the Web server; MySQL, the database management system (or database server) and Perl, PHP, and/or Python, scripting languages.
This tutorial is how to install LAMP on Ubuntu Desktop.
Linux
Here are several steps to install Ubuntu Linux Desktop if you have not already done so.
- First download and burn your own installation CD file from the Ubuntu Linux site or order a free CD from Shipit – Free CDs.
- Second, try out your new Ubuntu Linux without changing anything on your computer by booting the installation CD. This is a great way to test compatibility with your computer.
- Third, install Ubuntu Linux permanently on your computer by double-clicking the install icon on your temporary desktop.
- Download the Ubuntu Linux Desktop ISO CD image from the Ubuntu Linux site.
- Burn a bootable CD from the ISO CD image.
- Boot the CD on the target machine. Make sure the network is connected. If all is successful, Ubuntu Linux will start up in a fully functional friendly desktop environment. Experiment for a while if you like.
- Double-click on the installer icon on the desktop to permanently install Linux.
- Enter Name, Username, Password, and Time Zone. Set the clock if necessary. Choose automatic partition and format to erase the previous operating system.
- WARNING – This will wipe out everything on the target machine hard drive.
- Wait.
- Restart.
- Remove the CD to prevent starting over.
- Type Enter to boot.
- Login.
Apache
Install Apache
sudo apt-get install apache2
Testing HTTP Server by open a web browser and enter http://localhost
PHP
Install PHP5
sudo apt-get install php5 libapache2-mod-php5
Stop/Restart Apache
sudo /etc/init.d/apache2 restart
Test the installation
sudo gedit /var/www/testphp.php
Insert this following line into testphp.php file.
<?php phpinfo(); ?>
Save this new file.
Open a web browser and enter http://localhost/testphp.php
Be sure to remove the file afterwards, as it may pose a security risk.
sudo rm /var/www/testphp.php
MySQL
Install MySQL Server
sudo apt-get install mysql-server
MySQL initially only allows connections from the localhost (127.0.0.1). We’ll need to remove that restriction if you wish to make it accessible to everyone on the internet. Open the file /etc/mysql/my.cnf
gksudo gedit /etc/mysql/my.cnf
Find the line bind-address = 127.0.0.1 and comment it out then save the file.
MySQL comes with no root password as default. This is a huge security risk. You’ll need to set one. So that the local computer gets root access as well, you’ll need to set a password for that too. The local-machine-name is the name of the computer you’re working on.
mysqladmin -u root password newpassword mysqladmin -h root@local-machine-name -u root -p password newpassword sudo /etc/init.d/mysql restart
MySQL Administrator
Install MySQL Administrator
sudo apt-get install mysql-admin
Refresh Gnome Panel
killall gnome-panel
Run MySQL Administrator
Applications -> System Tools -> MySQL Administrator
MySQL for Apache HTTP Server
sudo apt-get install libapache2-mod-auth-mysql php5-mysql phpmyadmin
To get PHP to work with MySQL, open the php.ini file
gksudo gedit /etc/php5/apache2/php.ini
You’ll need to uncomment the “;extension=mysql.so” line so that it looks like this
extension=mysql.so
Restart Apache
sudo /etc/init.d/apache2 restart
Well done!

Hi, i have a problem regarding this 2 command
mysqladmin -u root password newpassword
mysqladmin -h root@local-machine-name -u root -p password newpassword
when you mean “password newpassword”
do u want me to type that into my console as is??
or should i change password to my PASSWORD e.g.”apple”
and newpassword to something else?!!?
and for local-machine-name can i type my ip like “192.168.2.5″ ?
thanks for this easy to follow tutorial
anyways, I interpreted you to mean type password as is, and in place for newpassword, we put in our own password, our choice.
so what i did was
mysqladmin -u root password apple
mysqladmin -h root@192.168.2.5 -u root -p password apple
after the 2nd command, i was prompt to enter a password. Which i inputted apple.
However, i got the error of
“mysqladmin: connect to server at ‘root@klalaiold-desktop’ failed
error: ‘Unknown MySQL server host ‘root@klalaiold-desktop’ (1)’
Check that mysqld is running on root@klalaiold-desktop and that the port is 3306.
You can check this by doing ‘telnet root@klalaiold-desktop 3306′
”
for your info,,
“root@klalaiold-desktop:/etc# netstat -tap | grep sql
tcp 0 0 localhost:mysql *:* LISTEN 7648/mysqld ”
Thanks for this great tutorial
moreover, oh the 2nd time running the following command, i get the following error
root@klalaiold-desktop:/home/klalaiold# mysqladmin -u root password apple
mysqladmin: connect to server at ‘localhost’ failed
error: ‘Access denied for user ‘root’@'localhost’ (using password: NO)’
root@klalaiold-desktop:/home/klalaiold# mysqladmin -h root@klalaiold-desktop -p password laiking1
Enter password:
mysqladmin: connect to server at ‘root@klalaiold-desktop’ failed
error: ‘Unknown MySQL server host ‘root@klalaiold-desktop’ (1)’
Check that mysqld is running on root@klalaiold-desktop and that the port is 3306.
You can check this by doing ‘telnet root@klalaiold-desktop 3306′
root@klalaiold-desktop:/home/klalaiold# telnet root@klalaiold-desktop 3306
telnet: could not resolve root@klalaiold-desktop/3306: Name or service not known
root@klalaiold-desktop:/home/klalaiold# netstat -tap | grep sql
tcp 0 0 *:mysql *:* LISTEN 4182/mysqld
Mysql Administrator also hangs when you click on “User Administration.
I fixed this by adding the following line to /etc/environment
DEBUG_DONT_SPAWN_FETCHES=1
heads up, if your installing on a vanilla Ubuntu install make sure you have your repositories set up to grab the community maintained repositories, if not you probably wont be able to install the mysql-admin package
Yea, Mysql Administrator is hanging for me as well.
I made the DEBUG_DONT_SPAWN_FETCHES=1 adjustment but it is still hanging when I click on User Administration.
Anyone else?
Hrm, this was helpfull:
https://launchpad.net/ubuntu/+source/mysql-admin/+bug/29802
Best,
Jason
I think these blog is really useful for new comers and Excellent resource list.
AlanLai,
Let’s try to solve this
You can try this:
or you can remove -h attribute:
So far, so good. Everything seems to be in order, so it’s time to push on and install WordPress. Many thanks for this excellent tutorial.
Installing mysql also forced installing postfix. Installing config needs configuring it with debconf. I had no idea how or why to do this, as I don’t need a mail server, need I? It would have been nice, if you had mention it or given some more info about it. Otherwise, thanks for the nice guide on installing lamp.
Typo: of course, on the second sentence I mean “Installing postfix” and not “Installing config”. Sorry.
As a security precaution, I would advise against setting mysql to listen to the entire internet, instead, just make sure that all your PHP scripts reference the server as “localhost” or “127.0.0.1″ and it should work fine.
Cheers,
Matt
This procedure is to do LAMP install. Thanks..
Does anybody know how to create a database after the installation is complete?
I am a Windows pro, Webmaster pro, and total Linux n00b.
May I suggest that you also include instructions on how to modify apt-get to point to universe (and subsequently, to apt-get update)? In my installation, your instructions didn’t work because phpmyadmin and mysql-admin packages were not available.
Took me a good half hour to figure out the whole universe thing.
Thanks for the instructions, though.
why did i get did msg
mysqladmin: connect to server at ‘localhost’ failed
error: ‘Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (2)’
Check that mysqld is running and that the socket: ‘/var/run/mysqld/mysqld.sock’ exists!
and also. when i try to change to password again. i get this msg.
one more thing. how can i delete all the installation and do one more clean installation.
To Create a Database:
The easy way is through PHP MyAdmin, a web based MySQL front-end interface (and one of the packages installed in this tutorial.
http://localhost/phpmyadmin/
Log in with the root mysql account you created above. About half way down on the right side frame is a form for creating a new database.
———————–
PS: Cool tutorial. I agree about a need to explain (or at least mention) the postfix config as it threw me too.
Great tutorial. I had tried using XAMPP earlier but encountered some problems and I was convinced that XAMPP would be en easier choice. I was looking for the XAMPP instructions again and fell into this page (thank God). I thought what the heck and followed the instructions step by step. Everything worked fine exept installing phpmyadmin. I installed it using the same command used in this tutorial but after installing everything else. It works fine.
Thanks for this gr8 LAMP guide. Got my Ubuntu LAMP shining brightly, for some home work over the weekend.
Right back 2 work.
Thanks again for posting this.
There are many useful informations in this article. Thanks and greetings from Thuringia!
Two small nits to pick:
– Under MySQL Administrator, to start MySQL Administrator it is “Applications -> Programming -> MySQL Administrator”, not “Applications -> System Tools -> MySQL Administrator” – “System Tools” is wrong
– Under MySQL for Apache HTTP Server, you need ADD “extension=mysql.so” it is not included but commented out,a s your tutorial says.
Aside from the above nits, nice tutorial – off to install WOrdPress now (see you there)…
William: Thanks
fwiffo: No problem
Matt: Thanks for ur suggestion
rrutia: You can run phpmyadmin or using command line to create database.
Henry: You can edit /etc/apt/source.list and add universe repository
dearblues: make sure your mysal is running by type sudo /etc/init.d/mysql start
To uninstall mysql type this command
sudo apt-get remove libapache2-mod-auth-mysql php5-mysql phpmyadmin
George Nagy: Thanks for your suggestion
Oscar: great
Doug: Thanks
Kunst: Greeting from Indonesia
Ken: Thanks. Perhaps I will check for the version of Ubuntu
Thanks a bunch…
Very good article, thanks for sharing
Hi – I’m getting this but that disc is long gone. Any workarounds?
Media change: please insert the disc labeled
‘Ubuntu-Server 6.10 _Edgy Eft_ – Release i386 (20061025.1)’
in the drive ‘/cdrom/’ and press enter
Thanks!
Admin
please note inorder to get phpmyadmin working I had to open /etc/apache2/apache2.conf and add the line…
Include /etc/phpmyadmin/apache.conf
then restart apache
sudo /etc/init.d/apache2 restart
Hi,thaks for your tutorial
but i’m got some trouble,when i type :
sudo apt-get install libapache2-mod-auth-mysql php5-mysql phpmyadmin
and press enter,there an error issues
Reading package lists… Done
Building dependency tree
Reading state information… Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:
The following packages have unmet dependencies:
php5-mysql: Depends: php5-common (= 5.2.3-1ubuntu6) but 5.2.3-1ubuntu6.3 is to be installed
E: Broken packages
How to solve this?
Thanks before
Thanks for the tutorial.
@ray: it works with me, maybe just a temporary bug?
I’m having a similar problem as Ray. libapache2-mod-auth-mysql and php5-mysql both installled but getting error “E: Couldn’t find package phpmyadmin”.
I’ll keep trying since it worked for Urlaub, but is there some other way to get this package?
AHA! Need to set apt-get to look universal instead of just at E:
Found directions here: http://ubuntuforums.org/showthread.php?t=138789
don’t forget to update aptitude after editing
sudo aptitude update
Thanks a lot for this! Finally a tutorial that works!
this tutorial was very helpfull!
Very useful tutorial, thanks! Is there any way to change the folder that localhost refers to? For example, could I change it so my localhost was ~/Web?
Ok theres a whole lot wrong with this tutorial. Where you say “You’ll need to uncomment the “;extension=mysql.so”” That doesn’t exist.
I see extension=mcrypt.so, but there is no “;extension=mysql.so”.
Also I’m having this problem:
sudo /etc/init.d/mysql restart
* Stopping MySQL database server mysqld [ OK ]
* Starting MySQL database server mysqld [ OK ]
* Checking for corrupt, not cleanly closed and upgrade needing tables.
Also when typing “mysqladmin -u root password newpassword” I get: mysqladmin: connect to server at ‘localhost’ failed
error: ‘Access denied for user ‘root’@'localhost’ (using password: NO)’
And another problem: mysqladmin -h root@local-machine-name -u root -p password newpassword
Gives me errors.
This is ridiculous. Now I have a totally garbled install of all kinds of crap that doesn’t work.
I’m interested in using ubuntu 8.04 then I’ve got the cd.
But the problem is I still affraid to install ubuntu, I’ve got 3 partition(C,D,E) now on my hardisk with Wind**s OS.
If I would like to install ubuntu as you said that we just need to follow the instruction (automatic partition) how many partition will be created?
Can I get more Partition?
I do apologize for my english and thanks for your attention…
Warmes greeting from Bali
Putu
Hi all,
I followed the install-instructions above and everything works perfect.
But now I have a question. How to create a mysql database now ?
I am a real linux-newbie, sorry
br, Kalle
I just saw the post number 17 but:
http://localhost/phpmyadmin/
does not work. I get an 404, because in /var/www nothing related can be found.
Something wrong with the paths?
br, Kalle
I have trouble. I created file1 <? Klik ?> and file2
File2 is not working properly. Do you explain it for me?
Tx
when i followed this, i got hung up (ubuntu 8.10) at the steps
mysqladmin -u root password newpassword
mysqladmin -h root@local-machine-name -u root -p password newpassword
the error i was getting:
mysqladmin: connect to server at ‘localhost’ failed
error: ‘Access denied for user ‘root’@'localhost’ (using password: NO)’
But then I realized that I had already installed and configured mysql on my machine a while ago (for use with amarok). I remembered the password I had used originally, and it worked fine. duh.
just done..
great..
makasih banyak y ( ;
Excellent notes, which have saved me a great deal of time. Many thanks for this.
Very nice tutorial..I just hope there was a tutorial like this for ubuntu server.One of the reasons why newcomers do not find linux very friendly is becoz of lack of proper documentation on nitty gritty things..but this one is gr8.
thanks a bunch
Tried the following steps to install apache and PHP
********
Apache
Install Apache
sudo apt-get install apache2Testing HTTP Server by open a web browser and enter http://localhost
PHP
Install PHP5
sudo apt-get install php5 libapache2-mod-php5
**********
but it says no package found
please help.
where i can get apache mysql and php for my ubuntu
so how to create a http site after putting up dis lamp?? (plzz email me how)
im getting an error ;;;
connect to server at ‘localhost’ failed
error: ‘Access denied for user ‘root’@'localhost’ (using password: YES)’
when changing password!!
Brilliant Guide Ubuntu kk 9.10