Jimi's Debian LAMP Setup Guide
Dec 7 2009 - Fixed some things - Thanks error10!
Dec 1 2009 - Originally wrote guide
1.0 - Introduction
---1.1 - What is LAMP?
---1.2 - Requirements
---1.3 - Starting Out
2.0 - Getting to Work
---2.1 - First Thing's First
---2.2 - Upgrading & Installing Common Software
---2.3 - 'Own' Server Software (Covers: SSH, Network, Hostname, Bind9)
---2.4 - Main Software (Covers: MySQL, Apache, ProFTPd)
3.0 - Ease-of-Use
4.0 - Configurations
5.0 - Conclusion
---5.1 - Credits
// 1.1 What is LAMP?
LAMP stands for Linux + Apache + MySQL + Php/Perl.
This is a common setup for webhosting on a Linux server/VPS (Virtual Private Server). This is
basically the "standard of the internet".
Still confused? Let me break it down piece by piece.
Linux - a generic term reffering to Unix-like computer operating systems based on the Linux kernel.
In this guide we will be using the Debian distribution.Apache - web server software notable for playing a key role in the initial growth of the World Wide Web.
This is the software that runs your website essentially.MySQL - a relational database management system that
has more than 6 million installations.
This is the "database" of your server. It stores information used for mostPHP - widely used, general-purpose scripting language
that was originally designed for web development, to produce dynamic web pages.
This is needed to support the use of PHP language on your server.Perl - a high-level, general-purpose, interpreted,
dynamic programming language.
This is needed to support the use of Perl on your server.// 1.2 Requirements
The approximate minimum requirement for your server/VPS is around 256MB of RAM. MySQL will use the most memory. It uses around 300MB of RAM on my personal VPS.
NOTE: If you're getting an "cannot connect to mysql.sock" error, that means that MySQL is not running.As I've stated this guide is for the Debian distribution of Linux. So that is another requirement. At current this guide isn't going to contain instructions for basic installation of Debian, but eventually I might add it.
// 1.3 Starting Out
I've broken this part into 2 sections: one for people who have decided to purchase a server from an online company for their hosting and one for people who decided to use one of their old PCs as a server.
If you're running a Windows OS, I'd suggest you download an application called PuTTY. This allows you to connect to your machine via SSH (Secured Shell). You can do this because most hosts (the company providing your server) will have your server already somewhat pre-setup. How much is has been set up, depends on the host. This guide assumes that the host hasn't pre-setup most things. What PuTTY is allowing you to do is connect to your server and manipulate it via the "command line" or terminal as it's known on Linux systems. This is how you're going to do EVERYTHING on your server. Your host will probably email you your SSH details or it will be available for you once you login their website.
Read through the 'Online' Server section above. You can also use an SSH but only once you've installed and setup an SSHD on your server. You have the advantage that you don't need to SSH to your server, since it's in your own home, but if you don't feel like running to the computer or don't want to use a monitor for your server, it is advised that you do install an SSHD so you can control your server from your other computers. When connecting to your server you will most likely SSH to the local IP address of the server and not it's physical IP address (since all your computers share the same physical IP address). You will also have to go about setting your router to forward incoming traffic on port 80 to your server. This can be done multiple ways, see http://www.portforward.com/ if you really need help, but this should all be common knowledge and you should understand port forwarding.
The following section will be written mostly in the context for those who have purchased their server from an online host. I will update this section and make it larger when I have some more time to make things clearer for those who want to use this method.
2.0 Getting to Work
// 2.1 First Thing's First
Log in by whatever method (probably SSH) to the root account. PuTTY is pretty straightforward to use. If you're running Linux, use the ssh command in the terminal (ssh ServerIPHere -p ServerPortHere -l ServerLoginNameHere). The IP address is the IP address of your server, the port is usually 22 (I set my to something different once I've set everything up to keep my server safer), and the login name will be root.
In my experience sometimes hosts (like 1and1) do some stupid things. So I recommend checking a couple of things before starting.
First find out what version of Debian you're using. Type:
Debian GNU/Linux 5.0 \ \\
Next we're going to check what repositories you're using (where your system will default to download software).
Type this in the terminal
deb http://ftp.de.debian.org/debian lenny main contrib non-free deb http://ftp.de.debian.org/debian-volatile lenny/volatile main contrib non-free deb http://ftp.de.debian.org/debian-security lenny/updates main contrib non-free
If your's looks completely different (some hosts *cough*1and1*cough* use their own repositories and it's extremely stupid) type:
"Enter". Vi is a little confusing at first, but once you learn it is as a very valuable text editor. Once we've got things updated, I'll run you through installing "nano" a much easier text editor.
// 2.2 Upgrading & Installing Common Software
Now we're going to upgrade the entire system. This may take a couple minutes.
NOTE: If you are receiving errors regarding resolving see the "BIND9" section below.About halfway throught upgrading, it should ask you if you want to sync clocks with the Debian servers. I'd suggest this.
Now to install a few common applications that are very helpful: (Some might already be there)
apt-get install aptitude nano ucf binutils cpp fetchmail flex gcc libarchive-zip-perl libc6-dev libcompress-zlib-perl libdb4.6-dev libpcre3 libpopt-dev lynx m4 make ncftp nmap openssl perl perl-modules unzip zip zlib1g-dev autoconf automake1.9 libtool bison autotools-dev g++ build-essential
NOTE: from now on, I'm going to use nano to edit files. Here's a guide how to use nano: http://www.nano-editor.org/dist/v2.2/nano.html// 2.3 'Own' Server Software
Those marked with a red asterisk (*) MAY need to be installed on pre-setup servers also.It as at this point in time that people running their own computer as a server should install a couple things.
SSH allows you to remotely connect to your server from another device.
This one's easy:
apt-get install openssh-server
Next we're going to configure the network so your server has a static local IP address.
# This file describes the network interfaces available on your system # and how to activate them. For more information, see interfaces(5). # The loopback network interface auto lo iface lo inet loopback # The primary network interface #allow-hotplug eth0 #iface eth0 inet dhcp auto eth0 iface eth0 inet static address 192.168.0.100 netmask 255.255.255.0 network 192.168.0.0 broadcast 192.168.0.255 gateway 192.168.0.1
Now restart your network:
We're going to edit your hostname so it includes your static IP address.
Now you're going to edit your hosts file and make it look like this:
127.0.0.1 localhost.localdomain localhost 192.168.0.100 server1.example.com server1 # The following lines are desirable for IPv6 capable hosts ::1 localhost ip6-localhost ip6-loopback fe00::0 ip6-localnet ff00::0 ip6-mcastprefix ff02::1 ip6-allnodes ff02::2 ip6-allrouters ff02::3 ip6-allhosts
echo server1.example.com > /etc/hostname
Now we should reboot so all processes are updated with the new hostname:
shutdown -r now
Bind9 is what resolves everything on your server. Some VPSs might not require Bind9, because the host server is already resolving things. If you couldn't update previously or have gotten any errors regarding resolving, this will most likely solve the problem.
apt-get install bind9
# run resolvconf? RESOLVCONF=yes # startup options for the server OPTIONS="-u bind -t /var/lib/named"
mkdir -p /var/lib/named/etc
mkdir -p /var/lib/named/var/cache/bind
mkdir -p /var/lib/named/var/run/bind/run
mv /etc/bind /var/lib/named/etc
mknod /var/lib/named/dev/null c 1 3
mknod /var/lib/named/dev/random c 1 8
chmod 666 /var/lib/named/dev/null /var/lib/named/dev/random
chown -R bind:bind /var/lib/named/var/*
chown -R bind:bind /var/lib/named/etc/bind
apt-get install mysql-server mysql-client libmysqlclient15-dev
Next you're going to want to make it so MySQL listens to all interfaces and not just localhost, so:
bind-address = 127.0.0.1
#bind-address = 127.0.0.1
Install Apache & the useful modules
apt-get install apache2 apache2-doc apache2-mpm-prefork apache2-utils apache2-suexec libexpat1 ssl-cert
apt-get install libapache2-mod-php5 libapache2-mod-ruby libapache2-mod-python php5 php5-common php5-curl php5-dev php5-gd php5-idn php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-mhash php5-ming php5-mysql php5-pspell php5-recode php5-snmp php5-sqlite php5-suhosin php5-tidy php5-xcache php5-xmlrpc php5-xsl
<IfModule mod_dir.c> #DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm DirectoryIndex index.html index.htm index.shtml index.cgi index.php index.php3 index.pl index.xhtml </IfModule>
apt-get install proftpd
Simple as that.
3.0 Ease of Use
In this section I will give details on some popular software that just helps manage things way easier. This will include things like phpmyadmin, webmin, and firewalls like apf & csf.
In this section I will cover some of the configurations that are popular and secure for a lot of the popular programs that people are running on their webservers.
When it comes down to it, majority of the internet is running on linux servers. The top choices for server distrubutions are CentOS and Debian. This guide was made to help kick start your learning experience running your new webserver off of one of the most preffered mediums (and for good reason). This server has the advantage of being lite and only having what is absolutely needed. This is how I've been running my webservers for years and I hope this helps someone out there learn just as I did.
// 5.1 Credits
-Myself for putting together the guide
-A couple guides that reminded me of a few things
Edited by Jimi - 5/15/10 at 8:42pm