How to install a Debian LAMP Server

The combination of Linux + Apache + MySQL + PHP setup is known as LAMP

We will be using:

Debian Linux - Operating System

Debian is an opensource operating system, which uses the popular Linux kernel. It is a good choice for servers as it is stable and has an easy to use package manager

Apache - Web server

Apache is one of the most famous web servers and with just few simple commands, you can configure apache to play nicely with PHP.

Note: You put your content /var/www.

MySQL 5 - Database Server

The MySQL database is renownd for its excellent performance, high reliability and ease of use.

PHP5 - Scripting Language

PHP is a common scripting language that is especially suited for Web development and can be easialy embedded into HTML pages and works well with other technogies such as the MySQL database and Apache webserver.

phpMyAdmin - Web-based database administration software.

PhpMyAdmin is an excellent web based database administration tool. Managing databases and tables couldnt any simpler.


First, lets ensure that the system meets the minimum requirements for Debian and that it has at least 256MB of RAM available. If your machine has less than 256MB ram then it can cause lot of problems and MySQL will give you the error "cannot connect to mysql.sock".

Getting Started:

Debian linux is my favourite for servers as it has the command "apt-get".

This command makes it easy for a beginner to install packages as you dont need to worry about package dependencies or manually creating configuration files.

I will assume that you have already installed debian and have it up and running (very easy). I personally love to use the netinstall cd and install just a base system then use apt-get.

If you wish to access the server remotely through SSH from a windows PC then please download a tool called PuTTY


Ok, now type (in this order, hit enter at the end of the line) and wait for it to complete. Reboot once all the software is installed

apt-get update

apt-get install apache2 php5 libapache2-mod-php5 mysql-server mysql-client php5-mysql phpmyadmin ssh


By default the mysql root (superuser) account does not have a password. Set one like this:

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

You are now ready to roll!

DanceInstructor commented: This is good stuff, but shouldn't it be under Web Hosting Tutorials? +3

Recommended Answers

All 26 Replies

Danceinstructor, you said that

This is good stuff, but shouldn't it be under Web Hosting Tutorials?

i dont know, i submitted it to davey for the PHP tutorials section but he said it wasnt in-depth enough. Fair enough, i dont have a problem with that, i may try to submit it again soon (with additional sections for a: doing a debian netinstall b: checking php/mysql are working and c: securing ssh and maybe adding FTP/samba

I think its great. It's to the point and succinct. It makes it look easy (which it is for the most part). If somebody has a problem, then its a good reason for them to post and everyone can benefit from that discussion (and possibly use that info to improve/udate the tutorial).

Although in my opinion this is a "server administratration" tutorial and doesn't really apply to scripters/programmers.

Oh ok, i just put it there as that was what i used it for (instead of using sopmething like XAMPP i did that that and ran it u nder virtual pc so that i could develop from my windows pc)

i have nearly finished a new version which adds parts on:

installing debian
securing ssh
file transfer to server
bssic sql commands
phpinfo to test if it works

It appears that there is little more to a Debian install than this. I just installed it as a Web server from the downloads on the Debian site.

It appears to work fine as a stand-alone PC, but is not functioning as a server on my network. I cannot even ping it. I've read that all the ports are closed by default with a Debian install, but have not found info regarding what I need to do to complete the Web server setup.

What do I need to know to do this? I'm looking forward to your other tutorials.

Thus far I think Red Hat was much easier to work with.

when you installed did you choose the Standdard System option. If not then you dont get the DHCP client.

Also make sure to guve it a proper hostname . NOT LOCALHOST!

go into a command prompt and type


. Thats I-F. Post the details here. Also at the command prompt it should say sometuing like

[EMAIL="root@(name"]root@(name[/EMAIL]): $

tell us what the name is

if you want a GUI just do

apt-get install xorg gnome gdm

reboot then type startx if it doesnt come up automatically.

just drop your content in /var/www by the way.



go to http://(hostname)/phpmyadmin to configure the database

When I try to set the password everything seemed to go OK so I restarted my pc and then tried myphp admin without a pass and it would still let you login :-/

Any Ideas?

Also where is the dir where I can drop all my file's etc in to be hosted on apache?


did you set the mysql password with

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

drop your files into the webroot (ususally somewhere under /var/www)

see post 8

I used that but it doesnt work I cant set a bleeding password :(


Instead of typing it all in one could you do this,

type this,
then, this then you should get this
then that

if you understand my sooo n00by language

yah you are supposed to hit enter at the end of each line

only type mysql the first time - where it says "mysql>", thats a prompt for further commands

dotn forget the ;s

Yep :)

Its worked!!!

Btw when I remove the files apart from phpmyadmin It still says ''it works'' put if i move my forum to a folder and go to the folder it shows what I want it to, how can I remove this text.

Also now I have set a pass when I create a new database will the pass be the pass I use to login that I se in the tutorial?


yeah, that password is the mysql root password.

for a site which will be public, do not use root. Create another account for the site which only has rights on the tables required for its operation. that way, a hacker cant destroy your server.

umm, in debian, i think the web root is wierd, try /var/www/sites-enabled/default

or somthing like that

the apache ''it works'' page is called index.htm so look for that.

btw, you need to reboot once changing it, or it wont switch to the new files.

I deleated the apache folder with the it works thing and upon restart it says this when I type http://localhost/ http://localhost/apache2-default/

Not Found

The requested URL /apache2-default/ was not found on this server.
Apache/2.2.3 (Debian) PHP/5.2.0-8+etch10 Server at localhost Port 80

But I have put phpbb files in but it doesn't come up :(

Any Ideas?

I got it fixed :twisted:

It worked out that the apache server was that folder and I had to put my files into that folder not the www itself ;) so just deleted the files inside the apache and added the phpbb files

Thanks Jbennet

btw how do you add a new user? in phpmyadmin?
it says under permissions add user and it asks loads of question and the what permissions do I give to the user?

if you havea libary, try and get SAMS Learn SQL in 24 hours - its awesome

I dont have a libary lol, how do I add a user?

basically, to make a database for your forum, and make a user with rights on it

mysql -u root -p

GRANT ALL PRIVILEGES ON my_database.* TO 'my_user'@'localhost';

replace my_user with whatever username you want. It will grant all priviliges on that database to the user.

How do you create a user tho :S

You should have some user table in your database, where you first check if the username does not already exist. If not you then add it to DB and grant privileges

How do you create a user tho :S

What i said in 21 creates a table, AND a user for it

when I create a database and add a user does it only assign it to that database or can I use it for all future databases I make? and what permissions do I have to set the user?

it makes that user and gives it full rights on that database

the poijt is that you make a db for your site, and then use that user for all the site stuff. that way if that site is compormoised it cant break your whole server

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.