HOWTO: Setup a Debian/Ubuntu LAMP Server
Build Your Own Debian/Ubuntu LAMP Server – Quick & Easy Do it Yourself Installation
This howto tutorial was written by Scott from MySQL-Apache-PHP.com.
- 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 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
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 MySQL Root Password
By default mysql creates user as root and runs with no passport. You might need to change the mysql root password.
To change MySQL Root Password
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.
Popularity: 25% [?]
Tagged with: apache • debian • guides • HowTo • Linux • mysql • php • servers • ubuntu
Like this post? Subscribe to my RSS feed and get loads more!













when i deleted /var/lib/mysql
how can i reinstall mysql-server again
I can’t reinstall by command
sudo apt-get install mysql-server
thank U
It’s “apt-get update”, not “apt-get install update”. The latter installs the software named “update”.
You’ve left something out here. By default the php modules aren’t enabled.
nice quicky howto! I followed it step by step. the MySQL User SET Update (…) code was unable for me to get it to work, but instead I just logged into Phpmyadmin and did it that way. Except from that, once again a nice one!
thanks dude – works perfectly – up and running in 1/2 an hour
Would you explain where excatly should I put “Include /etc/phpmyadmin/apache.conf” in the apache2.conf?
Almost got it done. One thing I’m stuck on is that when i go to the page in a browser, it tries to download the file Rather than displaying in the browser. Not sure what I’ve done wrong. Any suggestions? Nice guide btw!
weird thing:
apt-get install phpmyadmin
returns:
Reading package lists… Done
Building dependency tree… Done
E: Couldn’t find package phpmyadmin
any ideas?
U must change Your repository – check: universe, multiuniverse, … (all)
For ubuntu 64 bit it is necessary to add the php5-mcrypt package in order to login/stay logged in/use myphpadmin. A small package that will save hours of grief.
This is a good guide. Nice work. There is a good step-by-step guide on configuring new Apache sites and a cgi-bin directory here.
I have a problem, it wont let me use IPB installer for some odd reason… if you can help me please email me
Excellent guide, got my server set up thanks to you.
Nice article. LAMP setup isn’t so heavy to do, but I would like to point to few post installation steps. After Linux installation, many needless services are started by default. They are potentially security hole – minimize them. If firewall isn’t started, start it. You can easily find firewall configuration for your need. Forbid ssh root access – use “normal” user instead and then “su”. Hide your Apache/PHP version … this tips can be useful, and if you want to read more http://www.redips.net/linux/lamp-setup/
Thank you!
Thanks, works fine for me:)
Thank you very much indeed. It took just 30 mins to setup everything … in a Pentium II ubuntu box … just 10 ys old
Edgard
This is the only working guide for LAMP installation for me so far. Many thanks.
PHPMyAdmin.
How do you access that?
That works perfectly, thanks.
One small thing: I would update all the code to include “sudo.”
Also, under section one, there should be a command to restart apache before checking if php works.
Thanks again for a great guide.
For anyone having issues with the php test bringing up a popup to save the php file:
Just continue the installations in the complete order and you’ll be able to test the php file once you’ve restarted the apache server towards the end by running:
/etc/init.d/apache2 restart
For those who cannot access the php module out of box, you need to restart you apache server to have it load the php module:
sudo /etc/init.d/apache2 restart
and then point your browser to http://domain.name/test.php
Hello, it seems this article is quite outdated, is there a link to a newer one? Also more specifically one for CentOS 5.5?
Thank you
Hey, no matter what other says, this worked for me very good. Thank You so much for sparing me few hours