Simple Web Server Setup for Ubuntu/Debian

In server

It’s not easy to setup and secure a high web traffic server. But for the low traffic small sites, it can almost work on default settings. If prefer using VPS machines like Linode, Digital Ocean or Vultr. These instructions should work for Ubuntu 14.04 and Debian 8.

It’s better we change the hostname to what make sense:

echo "web1" > /etc/hostname
hostname -F /etc/hostname
127.0.0.1 localhost
127.0.1.1 web1.example.com web1

Update our repository and upgrade necessary packages

apt-get update
apt-get upgrade

Configure time-zone

dpkg-reconfigure tzdata

Common utilities:

apt-get install ufw git ntp vim sendmail htop rsync mailutils

If you want Nginx web server:

apt-get install nginx php5-fpm php5-gd php5-curl php5-mysql php5-mcrypt

If you want Apache web server:

apt-get install apache2 libapache2-mod-php5 php5-gd php5-curl php5-mysql php5-mcrypt ufw git ntp vim sendmail htop rsync

I don’t recommend installing Mysql/MariaDb server to a web machine, but if your VPS’s ram is more than 1GB, you can do it.

apt-get install mysql-server

Firewall ayarlarımızı yapalım

ufw allow ssh
ufw allow http
ufw allow https
ufw logging off
ufw enable

Our server is ready for testing, configure/edit virtual hosts as you like.

vim /etc/nginx/sites-available/default
   server {
        listen 80;
                server_name www.example.com example.com;
                root / var / www / example.com / http;

                index index.php;

                fastcgi_buffers 16 16k;
                fastcgi_buffer_size 32k;
                client_body_buffer_size 10K;
                client_header_buffer_size 1k;
                client_max_body_size 64m;
                large_client_header_buffers 4 32k;
                client_body_timeout 12;
                client_header_timeout 12;
                keepalive_timeout 15;
                send_timeout 10;

                gzip on;
                gzip_comp_level 2;
                gzip_min_length 1000;
                gzip_proxied expired no - cache no - store private auth;
                gzip_types text / plain application / x - javascript text / xml text / css application / xml;

                rewrite ^ /robots.txt$ /robots.php last;

                location ~ \.php$ {
                        try_files $uri = 404;
                        fastcgi_split_path_info ^ (. + \.php)(/.+)$;
                        fastcgi_pass unix:/var/run / php5 - fpm.sock;
                        fastcgi_index index.php;
                        include fastcgi_params;
                        fastcgi_param SERVER_NAME $host;
                        fastcgi_read_timeout 600;
                }

                # prevent nginx from serving dotfiles (.htaccess, .svn, .git, etc.)
                location ~ /\. {
                        deny all;
                        access_log off;
                        log_not_found off;
                }

                location / {
                        if ( - f $request_filename) {
                                expires max;
                                break;
                        }
                        rewrite ^ (. * ) / index.php last;
                }
}

At last, restart services.

service php5-fpm restart
service nginx restart

Notes:

Address resolving issues

If your dns nameservers are not properly configured, you will get errors when trying to install/update apt packages. You should get proper nameservers from your hosting firm or you can use google dns for quick/temporary fix. You can add this line to your iface eth0 config:

dns-nameservers 8.8.8.8 8.8.4.4

Perl Locales Errors
If you are getting these errors and you are using non-us remote console, you need an easy fix:

perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
LANGUAGE = (unset),
LC_ALL = (unset),
LC_CTYPE = "UTF-8",
LANG = "C"
are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
LANGUAGE = (unset),
LC_ALL = (unset),
LC_CTYPE = "UTF-8",
LANG = "C"
are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").

If you are using Ubuntu this line will fix the problem for your non-us console:

locale-gen tr_TR.UTF-8

If you are using Debian you should open up dpkg locales and choose your console’s languages additional to en_US.UTF-8

dpkg-reconfigure locales
Recommended Posts

Leave a Comment

Contact Me

I'm not around right now. But you can send me an email and we'll get back to you, asap.

Not readable? Change text. captcha txt