How to: Setup LAMP on Ubuntu




lamp linux apache mysql phpWeb Server-

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.

Installing 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.

Installing 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.

Installing Mysql

  • 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.

You can Subscribe to TechTickle Feed or join us on our Facebook Page or follow us on twitter for any queries and to keep yourself updated with the latest updates!

  • Share/Bookmark

You might like:

Enter your email address:

Delivered by FeedBurner


About - Mani

Mani is a coder passionate about working in open-source projects. You can follow him on Twitter . If You have any questions feel free to write and add him to Gtalk - it will be nice to get comments and direct contact from you!

One Comment | Add your own!

  1. [...] 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 [...]

Leave a Comment