How To Set Up A Ubuntu/Debian LAMP Server

Want to support HowtoForge? Become a subscriber!
 
Submitted by olddocks (Contact Author) (Forums) on Wed, 2007-01-03 14:13. :: Debian | Ubuntu | Apache | MySQL | PHP

Build Your Own Debian/Ubuntu LAMP Server - Quick & Easy Do it Yourself Installation

  • Apache 2 - Linux Web server
  • MySQL 5 - MySQL Database Server
  • PHP4/5 - PHP Scripting Language
  • phpMyAdmin - Web-based database admin software.

Note: Linux + Apache + MySQL + PHP/Perl together commonly known as LAMP Server.

First, let us prepare a system that has a minimum requirement of Debian/Ubuntu version of linux with atleast 256MB of RAM available. Anything less than this minimum ram will cause lot of problems since we are running a server along especially mysql and webmin requires lot of RAM to run properly. Mysql will give you this nasty error "cannot connect to mysql.sock" if you dont have enough memory in your server.

I love debian/ubuntu based linux because of my enormous affinity towards this command apt-get. As a starter knowing this one command, It is so easy to install packages and you dont need to worry about package dependency and configuration. You need to buy a dedicated server or a VPS package if you want to setup your own server. If you want to experiment with the server and installation it is recommended to buy a vps package from various hosts. I prefer vpslink because of their pricing. Believe it or not it is so easy to install and configure your server yourself eventhough you are new are to linux and dedicated/vps hosting.

First download PuTTy if you are accessing your server through SSH. Just enter the IP of your server with root login to access your host. As you probably know, Webmin is a freely available server control panel and we will setup this once we have completed the LAMP server and Mail Server. Webmin makes more easier for us to fine tune our linux box.

Before proceeding to install, update the necessary packages with debian with this command.

apt-get install update

 

1. Installing Apache + PHP

Apache is one of the most famous web server which runs on most linux based servers. With just few commands you can configure apache to run with PHP 4 or PHP 5.

If you want to install PHP 4, just apt-get

apt-get install apache2 php4 libapache2-mod-php4

To install PHP5, just run the following on linux shell. Note that if you dont specify packages with '4', PHP5 will be automatically installed.

apt-get install apache2 php5 libapache2-mod-php5

Apache configuration file is located at: /etc/apache2/apache2.conf and your web folder is /var/www.

To check whether php is installed and running properly, just create a test.php in your /var/www folder with phpinfo() function exactly as shown below.

nano /var/www/test.php

# test.php
<?php phpinfo(); ?>

Point your browser to http://ip.address/test.php or http://domain/test.php and this should show all your php configuration and default settings.

You can edit necessary values or setup virtual domains using apache configuration file.

 

2. Installing MySQL Database Server

Installing mysql database server is always necessary if you are running a database driven ecommerce site. Remember running mysql server to a fair extend requires atleast 256mb of RAM in your server. So unless you are running database driven sites you dont absolutely need mysql. The following commands will install mysql 5 server and mysql 5 client.

apt-get install mysql-server mysql-client php5-mysql

Note: If you have already installed php4, you should make a slight change like this.

apt-get install mysql-server mysql-client php4-mysql

The configuration file of mysql is located at: /etc/mysql/my.cnf

 

Creating users to use MySQL and Changing Root Password

By default mysql creates user as root and runs with no passport. You might need to change the root password.

To change Root Password

mysql -u root
mysql> USE mysql;
mysql> UPDATE user SET Password=PASSWORD('new-password') WHERE user='root';
mysql> FLUSH PRIVILEGES;

You must never use root password, so you might need to create a user to connect to mysql database for a PHP script. Alternatively you can add users to mysql database by using a control panel like webmin or phpMyAdmin to easily create or assign database permission to users. We will install Webmin and phpmyadmin during later once we complete basic installation.

 

3. PhpMyAdmin Installation

PhpMyAdmin is a nice web based database management and administration software and easy to install and configure under apache. Managing databases with tables couldnt be much simpler by using phpmyadmin.

All you need to do is:

apt-get install phpmyadmin

The phpmyadmin configuration file is located at: /etc/phpmyadmin folder.

To set up under Apache all you need to do is include the following line in /etc/apache2/apache2.conf:

Include /etc/phpmyadmin/apache.conf 

Now restart Apache:

/etc/init.d/apache2 restart

Point your browser to: http://domain/phpmyadmin

That's it! MySQL and phpMyAdmin are ready. Log in with your mysql root password and create users to connect to database from your php script.

This tutorial was written and contributed to HowToForge by Scott  who currently runs MySQL-Apache-PHP.com. Permission is fully granted to copy/republish this tutorial in any form, provided a source is mentioned with a live link back to the authors site.


Please do not use the comment function to ask for help! If you need help, please use our forum.
Comments will be published after administrator approval.
Submitted by Jake Berg (not registered) on Thu, 2013-07-18 16:35.
I always look for this article when it comes to installing a new Debian web server. By far the most straight-forward and easy to understand tutorial. Thank you!
Submitted by Anonymous (not registered) on Sun, 2013-12-29 21:27.
Yes, it's too easy, I have configured many system with Guide "Install LAMP with phpmyadmin"
Submitted by Anonymous (not registered) on Tue, 2013-05-21 18:21.

When I install this, I get a prompt to set the root password.

 The command mysql_secure_installation also adds some security.

Submitted by Anonymous (not registered) on Fri, 2013-05-03 02:58.
Hi, followed your guide but I found these other guides as well that had alot of screen shots.
 
Maybe I am just a picture person but these seemed to help as I didn't have to double check what I was doing as much.
 
I dunno If I can post there here but here they are! 

http://draalin.com/installing-phpmyadmin-in-ubuntu/

Overall they were just really detailed, even though I don't think you need that many details for something like this.

Submitted by Learath2 (not registered) on Mon, 2012-04-09 17:03.
After using apt-get to install php5 and apache you need a

/etc/init.d/apache2 restart

else it wont work with php and going to the php file would cause it to be downloaded
Submitted by Learath2 (not registered) on Mon, 2012-04-09 16:50.
The first command in the tutorial is wrong not

apt-get install update

it should be

apt-get update

Submitted by Anonymous (not registered) on Fri, 2012-03-30 09:23.
This got me going! Two thumbs up!!!
Submitted by Kumkum (not registered) on Fri, 2012-03-09 06:43.

Another solution for LAMP is using EHCP (easy hosting control panel).
Just need one line install syntax: ./install.sh and LAMP will be installed flawlessly.
Check this article on EHCP Setup.

Submitted by Joaquim Afonso (not registered) on Fri, 2011-10-14 17:15.
It was simply perfect and absolutely correct all the guidelines, I am deeply grateful, because I had much trouble before, even having to reinstall ubuntu because of inadequate procedures. Brazilian greetings. I am deeply grateful.
Submitted by online games (not registered) on Fri, 2010-12-24 21:42.

I was trying to install phpmyadmin on my debian server with no luck but thanks to this article I found out what i was missing - to edit - /etc/apache2/apache2.conf:

So it helped my alot, thanks guys! 

Submitted by rg (not registered) on Mon, 2010-10-25 22:25.

Before I can test the point 1 (test if php was running) I must restart the apache2 server with followed command:

/etc/init.d/apache2 restart

 After than will the php-file was executed.

Submitted by Anonymous (not registered) on Sun, 2010-09-12 18:02.

Hello:

 It is apt-get update -- not "apt-get install update" 

 

Before proceeding to install, update the necessary packages with debian with this command.

apt-get install update

Submitted by Anonymous (not registered) on Sun, 2010-09-05 07:41.
After much fighting and fussing, I have finally accomplished what I came here for. A working LAMP server...
This article was all I needed! Very helpful!
Submitted by reply (not registered) on Wed, 2010-09-08 14:55.

Thanks for this great help by registrating a lampp server.

 Helped me a verry lot!

 Thanks!

Submitted by syabac (not registered) on Tue, 2010-07-06 11:26.

really helped.

i just install the AMP on my Debian and it works.

 

Submitted by Jose (not registered) on Sun, 2010-06-20 15:46.

Hello olddocks,

Thanks for the article.  It helped me set up a development environment on my laptop.

Best regards,

Jose

Submitted by Jefferson Camargo (not registered) on Tue, 2010-05-25 21:57.

This article saved my life!

Everything works well!!!

Thank you very very much!

 :)

Submitted by Anonymous (not registered) on Tue, 2010-03-02 17:27.

Just to say thank you buddy. and you are a member in my geek list.

 

Submitted by husskii (registered user) on Sat, 2009-12-26 01:25.

thank you mate, I have attempted other tutorials on the net that are supposedly made by professionals linked to certain webhost companies and they always FAIL, were as your tutorial works perfectly first time round...

I have a few servers which are local but I use putty to connect to them as they dnt have monitors, and I follow you tutorial word for word command for command and it works like a charm :D

 

Ive also  followed other tutorials you have made on the site with success..

 

great job!!!!!

Keep up the good work!!!!!!

Submitted by stéphane V (not registered) on Thu, 2009-11-05 21:31.

This tutorial was brilliant !

thanks a lot for writing it. It helps me perfectly !

 Stéphane

Submitted by inckie (not registered) on Sun, 2009-07-26 11:55.

i wrote a small simple web panel for my LAMP server

 Take a look: SimpleHostingPanel

Submitted by Brazilian (not registered) on Mon, 2008-12-29 20:07.

after instalation of the php5 (or 4):

sudo apt-get install mysql-server mysql-client php5-mysql

add this line in /etc/apache2/apache2.conf:

LoadModule php5_module /usr/lib/apache2/modules/libphp5.so

and restart the apache:

/etc/init.d/apache2 restart.

Submitted by nhat truong (not registered) on Tue, 2009-08-18 07:41.

  I agree!!!

Submitted by Hnnashik (not registered) on Wed, 2009-05-27 20:38.

After i tried this Apache said that the module already was loaded.
Therefore I only restarted Apache and it worked.

I followed this tutorial pretty accuratly on Debian Lenny, and it worked like a charm!

Submitted by Anonymous (not registered) on Fri, 2009-02-06 17:56.

Hm. After i had installed mysql packages by this howto, the LoadModule directive was in

/etc/apache2/mods-enabled/php5.load 

and was successfully included to /etc/apache2/apache.conf in line looked like

Include /etc/apache2/mods-enabled/*.load

Did not php work under apache after you had installed mysql on your system, that you had to edit apache2.conf? 

Submitted by charles (registered user) on Mon, 2008-04-14 02:12.

Shouldn't the first command be apt-get update and not apt-get install update?

Submitted by Anonymous (not registered) on Sun, 2009-04-19 14:47.

I agree

Submitted by bettdani1234 (registered user) on Fri, 2008-01-25 19:24.
Hello all, Tiny comment for newbies (such as myself) where your browser tries to open the test.php file rather than simply running the script.... You have to logout of your system and log back in for it to work. Am running Debian Lenny and KDE D
Submitted by dade (not registered) on Sun, 2010-04-04 21:31.

Actually all you need to do is to restart apache:

 /etc/init.d/apache2 restart

 a reboot or logout is overkill! Apache has to restart to know it must work with php, which has been installed after it. 

 

Submitted by supermonkeyman2004 (registered user) on Wed, 2007-09-12 19:28.

You'll get problems with reliable login performance to PhpMyAdmin, UNLESS YOU DO THE FOLLOWING:

sudo apt-get install php5-mcrypt

The install line for phpmyadmin should be modified to reflect this fact. 

Submitted by zaphu (registered user) on Tue, 2007-08-21 23:56.
Add the desktop user interface afterwards by following this guide..
and configure apache and mySQL via this guide.
Submitted by Everweb (registered user) on Fri, 2007-06-01 19:57.
Ubuntu does not allow root login by default so all commands requiring root access (that's most in this article) should be prefixed with "sudo".
eg.   
        $ sudo apt-get update
        $ sudo apt-get install apache2 php5 libapache2-mod-php5
        $ sudo nano /var/www/test.php

Submitted by Anonymous (not registered) on Tue, 2008-11-18 16:47.
Can't get to root in linux?  Noob! (;

$ sudo su -

Submitted by m0ntassar (not registered) on Sun, 2009-05-03 17:01.

I'd just use:

$sudo -s

Submitted by Everweb (registered user) on Fri, 2007-06-01 19:49.
If you're logged into the server you're configuring via PuTTY and don't (yet) have a way to access the apache server, you can use the following to obtain a text-only browser:
     # apt-get install lynx

Then you can see the results of step 1 thus:
    # lynx http://localhost/test.php


Submitted by Anonymous (not registered) on Tue, 2009-02-03 16:04.

Instead of Lynx, you can also use:

wget localhost

This wil just download the html with http.  If you just use vi to edit the source you can see if it worked correctly or not.

Submitted by Anonymous (not registered) on Sat, 2009-05-02 03:09.

Or

telnet localhost 80 <enter>

GET /test.php HTTP/1.0 <enter>

Submitted by AbdulFattah (not registered) on Fri, 2010-03-05 00:50.

Your article was very clear and straight to the point.

 Thank you very much, my LAMP is running now.

 Have a great day.

Submitted by forealz12 (not registered) on Wed, 2010-05-05 01:05.

Awesome post. thank you for this.

I to use webmin too. I used this guide at

http://t3.woodel.com/my-linux-how-to/debian_howto_start_to_finish_using_webmin.pdf

 

 

Submitted by Donni (not registered) on Mon, 2011-05-09 09:03.
Thanks, tell me please what is better pureftpd or proftpd for fpt?