Monday, August 08, 2011

How to setup a localhost with Lamp Server in Ubuntu

Although, I use Ubuntu, this should apply to a large number of linux distros. Every developer uses a local environment to develop locally before testing it live. I kinda avoid that root by mounting my FTP webspace in Ubuntu and directly working on live files (there is no need of download and upload as you might think), but I wanted to do some CPU intensive job for a client for which I needed to setup a localhost environment, so I thought I would share this with everyone on my blog.

Install LAMP Server

Fire up a terminal (Applications > Accessories > Terminal) and enter this command:

sudo apt-get install lamp-server^

Enter y for yes when it asks to continue after estimation of how much data will be downloaded and how much will be used on disk.
It will install quickly and can take a few minutes depending on your internet speed, and then it will ask you to setup the password for MySQL user root. It is usually left blank on localhost machines as they are used only for development purposes but last time I left it blank, I had to deal with the issues that it didn’t change the password to blank but has something else and I had to turn off the password prompt for root access. Avoid doing all that by just selecting “root” or anything you want as the password of the root user of MySQL.

Confirm it once (Type the password and press Tab key).

and you are done.


Test Apache Webserver

Just open http://localhost/ in your browser and it will show up this page,

which means Apache is working fine.


Test PHP

Create a file named phpinfo.php in /var/www/ to check if PHP is working fine.

sudo nano /var/www/phpinfo.php

Enter the content as <?php phpinfo() ;?> and save the file by hitting Ctrl + X and then Y (for yes) and return key (enter).

Restart Apache webserver by the following command. sudo /etc/init.d/apache2 restart

Now open http://localhost/phpinfo.php and it will show up a page with lots of php related information,

if you can see it, PHP is working fine.


Install phpMyAdmin

Enter this command in terminal. sudo apt-get install libapache2-mod-auth-mysql phpmyadmin

Select Apache2 as the web server by pressing Space and then Tab key and press enter key.

Press Yes to configure database for phpmyadmin.

Provide password which we set as “root” earlier.

Again, enter “root“.

Confirm it, and then you are done.


Test phpMyAdmin

Now open http://localhost/phpmyadmin/ in your brower to access phpmyadmin and you can login with username and password both as root.

Code for other installation:
sudo apt-get install apache2 apache2-doc mysql-server php5 libapache2-mod-php5 php5-mysql phpmyadmin

Pretty quick & easy!

Enter this command to edit permissions & access your web directory, sudo nautilus and go to File System your web root at /var/www/ where you will need super user permissions to write files.

Everything is done.

No comments:

Post a Comment