Fast And Secure Server Setup

In this article we will describe how to set up a fast and secure linux server with Mysql, Lighttpd and PHP. We will use:

Linux Debian Stable OS (as of this moment it is version 5.07). It is small, low-resource demanding and has everything we can think of. Also, it is supported for a very long time.
Lighttpd - small and fast web server. It is better than Apache in terms of performance and may be security.
Php 5.2 / MySQL 5.0 - These are the versions bundled with the current Debian stable release. They are tested for years and proven to be the extremely stable if not outdated.

1. Core installation

First we begin with downloading the net installation of Debian Stable. The Small CD install is only 150 MB and can be found here:

http://www.debian.org/distrib/netinst#smallcd

Note: You will need Internet connection to complete the installation. This package will have only the basic files to get started.

Note: Many data centers will perform the install for you so may skip the manual installation.

As a whole the installation is very straight-forward and we will not go into most details. You just click next and 'Yes' if you are not sure. Of course, make sure to understand what the installaer asks for because you may wipe your hard-drive if you have something else on it.

2. Software Selection

During the installation you will be prompted for Software Selection. There remove any checks and make sure nothing is installed by default. That's because we want the simplest install possible.

Once the installation completes you end up with an amazingly resources undemanding system. If you perform a check you will see that after a clean boot only 21 MB of RAM are taken.

A. Install Lighttpd + Php5cgi

The first thing we will need is the webserver with PHP support. For this purpose we will use Lighttpd + Php5cli. We install it by typing in the terminal:

# apt-get install lighttpd php5-cgi

When the insstallation is completed you can check it with netstat -ntap. Besides portmap and famd there will be also lighttpd listening on port 80.

The get PHP working insider Lighttpd you will just have to change 2 files:

- In the file /etc/php5/cgi/php.ini specify 'cgi.fix_pathinfo = 1'

- Open /etc/lighttpd/lighttpd.conf and make 2 changes:

1. Make sure that mod_fastcgi is listed in the server modules:
server.modules = (
"mod_access",
"mod_alias",
"mod_compress",
"mod_rewrite",
"mod_fastcgi",
#       "mod_redirect",
#       "mod_usertrack",
#       "mod_flv_streaming",
#       "mod_evasive"
)
2. Add the end of the configuration file add:

fastcgi.server = ( ".php" => ((
"bin-path" => "/usr/bin/php5-cgi",
"socket" => "/tmp/php.socket"
)))

Restart the webserver with '/etc/init.d/lighttpd restart' and you can begin executing your PHP sccripts from /var/www/.

B. Next install MySQL and Php5-mysql.

# apt-get install mysql-server php5-mysql

We need php5-mysql in order to have MySQL support inside PHP.

That's all for the basic installation. At this moment you will have the server installation of MySQL 5.0 and Php 5.2. Without any optimizations your RAM usage by now should be ONLY 100 MB and there will be no unnecessary service running.

blog comments powered by Disqus