Home > Articles > Debian LAMP + nginx installation for high-loaded webservers

Debian LAMP + nginx installation for high-loaded webservers

Debian LAMP + nginx installation for high-loaded webservers

Debian LAMP + nginx installation for high-loaded webservers

All below steps have been done on the server which have the latest version of Debian pre-installed. I will setup a standard LAMP installation for a web-server and will install and configure nginx to serve static content for better performance.

Remove services you will not use. Execute the following command:

apt-get remove lpr nfs-common portmap pidentd pcmcia-cs \
pppoe pppoeconf ppp pppconfig

Set the host name:

echo "www" > /etc/hostname

Alter /etc/hosts with new hostname:

ip.address www.sysadmin.md sysadmin.md www

Before proceeding to install, update Debian packages with this command:

apt-get update
apt-get upgrade

Install utilities:

apt-get install tcpdump links htop nmap mc screen sysv-rc-conf sudo

Tune the server by enabling spoofing protect and syncookies. The options are located in file /etc/network/options:

spoofprotect=yes
syncookies=yes

Disable unneeded services by running:

sysv-rc-conf

For server will be enough 3 consoles. Edit /etc/inittab and make the following changes:

1:2345:respawn:/sbin/getty 38400 tty1
2:23:respawn:/sbin/getty 38400 tty2
3:23:respawn:/sbin/getty 38400 tty3
#4:23:respawn:/sbin/getty 38400 tty4
#5:23:respawn:/sbin/getty 38400 tty5
#6:23:respawn:/sbin/getty 38400 tty6

The above changes will insure that will be created only three terminals on startup.

Install Apache + PHP:

apt-get install apache2 php5 libapache2-mod-php5 

Secure Apache. Edit /etc/apache2/apache2.conf and alter the following variables to match like this:

ServerSignature Off
ServerTokens Prod

Prepare webserver root:

mkdir -p /home/sysadmin.md/{public_html,logs}
chown -R www-data:www-data /home/sysadmin.md

Create a file /etc/apache2/sites-available/sysadmin.md to match like this:

<VirtualHost *>
        ServerAdmin webmaster@sysadmin.md
        ServerName www.sysadmin.md
        ServerAlias sysadmin.md
        DocumentRoot /home/sysadmin.md/public_html

                Options -Indexes FollowSymLinks
                AllowOverride None
                Order allow,deny
                allow from all

        ErrorLog /home/sysadmin.md/logs/sysadmin.md-error_log
        CustomLog /home/sysadmin.md/logs/sysadmin.md-access_log common
</VirtualHost>

Test the config and enable the site:

apache2ctl configtest
a2ensite sysadmin.md

Alter /etc/apache2/ports.conf to make Apache listen on localhost:

Listen 127.0.0.1:80

Restart the Apache and test if it is running on 127.0.0.1:80

/etc/init.d/apache2 restart
netstat -nalp

Install nginx:

apt-get install nginx

Move default config to another location:

mv /etc/nginx/nginx.conf /etc/nginx/nginx.conf.default

Create a new one to match like this:

user www-data;
worker_processes  2;
error_log  /var/log/nginx/error.log;
pid        /var/run/nginx.pid;
events {
    worker_connections  8192;
}
http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;
    access_log  /var/log/nginx/access.log;
    sendfile        on;
    tcp_nopush     on;

    keepalive_timeout  65;
    tcp_nodelay        on;

    gzip  on;

    server {
        listen       ip.address:80;
        server_name  sysadmin.md www.sysadmin.md;

        access_log  /home/sysadmin.md/logs/nginx.sysadmin.md.access.log;

        location / {
            proxy_pass         http://127.0.0.1:80/;
            proxy_redirect     off;

            proxy_set_header   Host             $host;
            proxy_set_header   X-Real-IP        $remote_addr;
            proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;

            client_max_body_size       10m;
            client_body_buffer_size    128k;

            proxy_connect_timeout      90;
            proxy_send_timeout         90;
            proxy_read_timeout         90;

            proxy_buffer_size          16k;
            proxy_buffers              32 32k;
            proxy_busy_buffers_size    64k;
            proxy_temp_file_write_size 256M;
        }

	# for static files
       location /s/  {
                root /home/sysadmin.md/;
                access_log  /home/sysadmin.md/logs/nginx.static.sysadmin.md.access.log;
        }

        # redirect server error pages to the static page /50x.html
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   /var/www/nginx-default;
        }
    }
}

Install MySQL Database Server + phpMyadmin:

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

Configure it:

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

Set up phpMyAdmin – include the following line to /etc/apache2/apache2.conf:

Include /etc/phpmyadmin/apache.conf

Now restart Apache:

/etc/init.d/apache2 restart

And reboot:

reboot

Articles

  1. No comments yet.
  1. No trackbacks yet.