Installing a LAMP Server on Debian

Linux, Apache, MySQL, and PHP; the components most used to configure a dynamic web server. For my test machine I am using an HP D530 desktop, Debian (Linux) and the aforementioned components.

From the Debian site, I downloaded the small image file that installs the operating system via the Internet. There are some interesting options listed for installation I would like to explore, but that will come later after I've mastered this first step.

Hardware

HP D530 Desktop PC: P4 2.6 Ghz, 2G RAM, 80 Gb SATA hard drive.

Installation

Burn the CD from Debian site. It is the minimal install requiring Internet access for additional install options.

Booting from the CD produces the graphical screen with the Debian logo and the boot prompt:

boot

The next three screens ask for Language, Country, and Keyboard. Pretty straightforward.

Enter Hostname, domain,

The installer then detects hard disks and other hardware.

On Linux, disk drives correspond to files in the /dev directory, and are referred to like this:

SCSI and SATA devices are listed differently. They are usually /dev/sda, /dev/sdb, etc. If you have installed Windows on this machine, /dev/hda will usually be what Windows refers to as the C:\ drive.

I chose separate /home /var /usr /tmp partitions, as it is more secure and stable. NEXT!

After commiting to the partition scheme, there's no turning back! On with

Installing the System

Time zone choice is next, then choosing the root password and setting up a primary user and password.

Now the installer 'installs,' asking if you want to use a network mirror. Yes, and I accepted the first entry of ftp.us.debian.org. No proxy needed, and the installation continues.

At the next screen presented, I chose only the Desktop environment and Standard System, since I want to install my components separately.

When the installation is finished, removed the CD and booted into the GUI.

Enabling Remote Access

Install and enable SSH by starting terminal as root and typing "apt-get install ssh" at the prompt #

The system asked for the CD, installed the server and now I have remote access via Putty! After finding the IP address, of course.

One more thing: Debian defaults to disallowing X and Agent forwarding for security reasons. To change this and allow SSH access, add the lines:

Host *
  ForwardAgent yes
  ForwardX11 yes

/etc/ssh/ssh_config

An easy way to do this is with pico, thusly:
pico /etc/ssh/ssh_config

Then restart the ssh server in this way:
/etc/init.d/ssh reload

Installing Apache

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

Installing MySQL

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

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

ERROR: In part the error was:

dpkg: error processing mysql-server-5.0 (--configure):
subprocess post-installation script returned error exit status 1

To fix this edit /etc/mysql/my.conf and change the bind-address to the static address of the machine. Then rerun apt-get to finish the configuration of the packages.

Creating users to use MySQL and Changing Root Password

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

To change Root Password: at the mysql prompt

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

Installing PHPMyAdmin

apt-get install phpmyadmin

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

To setup 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

Thats it!! MySQL and phpMyAdmin is Ready !!! Login with your mysql root password and create users to connect to database from your php script.

Installing Webmin

Webmin is a server control panel.

wget http://prdownloads.sourceforge.net/webadmin/webmin-1.410.tar.gz
tar xzf webmin-1.410.tar.gz
cd webmin-1.410
./setup.sh

The installation program will ask series of questions and most values will be automatically set by default.

Once done, point your browser to: http://ip.address:10000 or http://www.domainname:10000

Login into your webmin and you can do almost anything with your server. SWEET!

Installing FTP Server (VSFTP)

apt-get install vsftpd

Configuration file is located at: /etc/vsftpd.conf

Change the following settings in /etc/vsftpd.conf so that you allow local users and allow write using ftp.

pico /etc/vsftpd.conf

# Uncomment this to allow local users to log in.
local_enable=YES
# Uncomment this to enable any form of FTP write command.
write_enable=YES

Ctrl + X, yes, enter

Before you connect using ftp client, you will need to create local users and group. Do not upload files using root.

# CD to /home/<user> and create a symbolic link to /var/www as this is the public html folder.
ln -s /var/www www

#change ownership /var/www to user
chown -R <user> /var/www

#Change to 755 permissions
chmod -R 755 /var/www

Now you can connect to ftp and upload files. Once you upload all necesarry files in the public html folder, make sure all the files have 755 permission as otherwise you will get permission denied/forbidden error from apache.

Enabling VSFTP to Show Dotted Files

By default, vsftp does not show dotted files in the server, especially .htaccess, eventhough you have successfully uploaded the files. This could be frustrating especially if you are using .htaccess for authentication or rewriting friendly URLs. To fix this just add force_dot_files=YES in your vsftp configuration file /etc/vsftpd.conf

# Activate directory messages - messages given to remote users when they
# go into a certain directory.
dirmessage_enable=YES
force_dot_files=YES

Restart the vsftp server /etc/init.d/vsftpd restart.

Adding Index.htm as the Default Page and Removing that damn "apache2-default/" directory from the path!

Edit/create the file /sites-available/default with the entry:

DirectoryIndex index.htm index.php index.pl

Removing the directory redirection is simple too: just edit /sites-available/default and comment out

#RedirectMatch ^/$ /apache2-default/

Joomla! Installing a Content Management System (CMS).

Installation:

From the root directory of the website [/var/www] in my case, run the following commands to download and then extract the archive.

wget http://joomlacode.org/gf/download/frsrelease/6828/22536/Joomla_1.0.15-Stable-Full_Package.tar.bz2

THEN

tar xvjf Joomla_1.0.15-Stable-Full_Package.tar.bz2

Now proceed with the Web browser installation. Browse to http://[hostname IP or localhost]/index.php to proceed with the installation.

admin & standard medium security password.

Need to CHMOD as below, delete the installation folder, and off you go!

Securing the Server!

By default, Debian is installed with services appropriate for a LAN, such as the Network File System (NFS). The next step in setting up our Internet server is to remove NFS and some other services while adding some others such as OpenSSL.