Notice

Wednesday, September 4, 2013

Install and configure LAMP Server and PhpMyAdmin on Ubuntu

Hello all, As my first post in my Ubuntu blog I am going to describe how to install and configure Apache web server in ubuntu. Most tutorials found on internet either describes how to install Apache web server or how to install PHPmyadmin on ubuntu. In this tutorial I'll describe how to install Apache web server using LAMP (Linux version of WAMP as you may know), install PhpMyadmin and configure it to work in coperation with Apache and discuss some frequently asked questions on working with Apache on ubuntu. Well, lets start..

We are going to install LAMP(stands for Linux Apache MySQL PHP) on Ubuntu which is a 3 in 1 server. If you have ever used WAMP on windows, this is the similar version for ubuntu. After installing LAMP, you can run your PHP pages/websites on your local machine.

To install LAMP, go to ubuntu terminal and run following commands

sudo apt-get install lamp-server^

When you are asked for username and password for MySQL Database access, give a preferred username and a password.

After finishing your installation, you can whether your webserver works by just browsing to http://localhost in your browser. If LAMP is installed properly and running, you might see a simple web page like 'It Works'.
If you cannot access localhost, either your installation is unsuccessful or your web server is not running yet. If you have installed properly and the server has not been started yet, you can start your web server manually by running following command.

sudo ./etc/init.d/apache2 start

Now since you have completed installation of LAMP, lets install PhpMyAdmin. Run following commands to install it.

sudo apt-get install phpmyadmin

And then we have to configure phpmyadmin to work with apache. For that, run the following command.

sudo gedit /etc/apache2/apache2.conf

Now gedit will open apache2.conf file for you, and add the following line at the end of the file.

Include /etc/phpmyadmin/apache.conf

Save the file and restart apache web server with the following command.

sudo /etc/init.d/apache2 restart

Check your phpmyadmin installation by browsing to http://localhost/phpmyadmin in your browser. You will be directed to phpmyadmin and you can log into it using username and the password you provided for MySQL at the installation of LAMP.

Now you have successfully configured both LAMP and Phpmyadmin, you can run a website by copying the files of the website into /var/www/ folder. Note that writing into this folder requires root permissions and you need to copy files into it in terminal with sudo, or you need to launch nautilus as root (running sudo nautilus in terminal) to copy  files in ubuntu GUI. This is an annoying thing for a new user for ubuntu. So lets find a solution for this.

Since writing into the website directory requires root permissions, we can change the website directory into our own one into which we can write with existing permission. We can create a directory in our home directory and configure it as the www folder. To do that, follow these steps.

Open following files as follows and replace any string like '/var/www' into your prefered web folder name (say /home/<your-username>/www)

sudo gedit /etc/apache2/sites-available/default
sudo gedit /etc/apache2/sites-available/default-ssl

Then restart the Apache :

sudo /etc/init.d/apache2 restart

Now you can easiy copy files into your folder and access them via browser.

No comments:

Post a Comment