To setup a web server and to run a website on a system(localhost) you have setup LAMP or WAMP first. If you are a Linux user, you have to setup LAMP for this purpose and if you use Windows then you setup WAMP. This is a simple guide for running a website on localhost by setting LAMP on Linux machine. I used Ubuntu 8.1 (desktop edition) for this purpose.
LAMP is the acronym for Linux Apache MySql Php,Python,Perl.
WAMP is the acronym for Windows Apache MySql Php,Python,Perl.
We will install all these components and will configure a web server on localhost.
First, we will install and configure Apache.
- Open the terminal Application -> Accessories -> Terminal and type the command-
sudo apt-get install apache2
Now apache is downloaded and installed automatically.
A www directory will be located in your /var directory. This is your server’s base address where you will place files for your website. /var/www basically stands for localhost. You can test your localhost by typing http://localhost/
Next, we will install PHP.
- Type the command in the terminal-
sudo apt-get install php5 libapache2-mod-php5
Here, we are downloading and installing PHP5. You can install other versions of php too.
After installation is finished , restart Apache with the command-
sudo /etc/init.d/apache2 restart
To test if everything is fine and working , create a test.php file and add any php code for examle-
<?php
echo 'Welcome to TechTickLe';
?>
Now you can open this file by the url http://localhost/test.php in the web browser . It should prompt Welcome to TechTickLe. If not working, then something is wrong with your local server.
So, your server is working , now you need to store databases for your server back end. Therefore we will install MySql now.
- Again in terminal execute the command-
sudo apt-get install mysql-server
This way, MySql will be installed for your localhost.
If you are running a server (not for localhost) then you have to bind your ip address to Mysql. You can do it by editing the bind address in the file /etc/mysql/my.cnf . And change bind address’s value (127.0.0.1) by your IP address.
Set your root password for MySql-
- First type mysql in terminal , it will drop mysql prompt.
- Then type command .
mysql> SET PASSWORD FOR ‘root’@'localhost’ = PASSWORD(‘xxxxxx’);
where xxxxxx is your desired password.
- Now we can install phpMyAdmin as graphical interface for MySql.
sudo apt-get install libapache2-mod-auth-mysql php5-mysql phpmyadmin
You can open phpMyAdmin by typing http://localhost/phpmyadmin
It will ask for username and password . You can access it as root and give its mysql’s root password.
Note- The password that you have set for mysql’s root not your system’s root password.
- Last step is to restart your apache.
sudo /etc/init.d/apache2 restart
This should give a better understanding how a Lamp server’s components are installed and configured.
Comments are welcome!
Thanks.


[...] This post was mentioned on Twitter by Sahil Malhan, Sahil Malhan and slimb mani, TechTickle. TechTickle said: TeckTickLe- How to: Setup #LAMP on Ubuntu http://bit.ly/bdy4lX (A tutorial for Linux Lovers) #linux #ubuntu [...]
Great tut just to say
mysql no need for the password command as the install asks you for this also slect apache 2 on mysql set up
There are so many folders – where do I save the test.php file?
there are so many folders, where do I save the test.php file?
In the localhost directory -> /var/www
When I try to create the test.php file at /var/www I receive the following error: Error moving file: Permission denied.
Looking at permissions, it looks like only root has access. Either I don’t remember ever setting the root password, or I forgot the password. Is there anything I can do so I can put this file in the /var/www folder?
I’m having the same problem…
Hi, when I get to the point where you say Set your root password for MySql-
* First type mysql in terminal , it will drop mysql prompt.
Then I get this output in the terminal: mysql
ERROR 1045 (28000): Access denied for user ‘sbn’@'localhost’ (using password: NO)
What to do?
Thanks
Just try to use command while opening mysql
mysql -u root -p
then enter your mysql’s root password.
I can’t seem to get the localhost/phpmyadmin to work… It’s basically saying it’s not found it… I’m not sure if there should be any sign of it in the directory when I look in the file manager, but there isn’t.
Any ideas?
Firstly make sure that phpmyadmin is installed. After that if it doesn’t work it means it would have not been linked in /var/www directory. To make this work just create a link from /usr/share/phpmyadmin to /var/www directory
Use command as root -
ln -s /usr/share/phpmyadmin /var/www
I got as far a the last stage and also got no connection for
http://localhost/phpmyadmin/
so I did
ln -s /usr/share/phpmyadmin /var/www
and I do get a connection now but it says
“phpMyAdmin -
Cannot load mysqli extension. Please check your PHP configuration. – Documentation”