Cara Install + Setting Nginx, MySQL, dan PHP 5 di Ubuntu

Setting firewall terlebih dahulu:

ufw allow ssh
ufw allow http
ufw logging off
ufw enable

Install MySQL:

apt-get update
apt-get install mysql-server

Install PHP 5:

apt-get install php5-fpm php-pear php5-common php5-mysql php-apc php5-gd php5-curl

Edit /etc/php5/fpm/php.ini lalu di bagian bawah tambahkan:

[apc]
apc.write_lock = 1
apc.slam_defense = 0

Edit /etc/php5/fpm/pool.d/www.conf
lalu cari code ini:

listen = /var/run/php5-fpm.sock

Di bawahnya tambahkan:

listen.owner = nginx
listen.group = nginx
listen.mode = 0660

Lalu cari code ini:

user = www-data
group = www-data

dan ganti dengan:

user = nginx
group = nginx

Install Nginx:
Download signing key:

cd /tmp/
wget http://nginx.org/keys/nginx_signing.key
apt-key add /tmp/nginx_signing.key

Lalu jalankan command ini:

echo "deb http://nginx.org/packages/ubuntu/ lucid nginx" >> /etc/apt/sources.list
echo "deb-src http://nginx.org/packages/ubuntu/ lucid nginx" >> /etc/apt/sources.list
apt-get update

Download dan install nginx:

apt-get install nginx

Edit /etc/nginx/nginx.conf, lalu di bagian http tambahkan kode ini:

port_in_redirect off;
gzip  on;
gzip_types text/css text/xml text/javascript application/x-javascript;
gzip_vary on;

Pindah ke folder /etc/nginx/conf.d dan buat file baru: /etc/nginx/conf.d/drop dengan menjalankan command ini:

cd /etc/nginx/conf.d
nano /etc/nginx/conf.d/drop

Isi file drop itu dengan:

# Most sites won't have configured favicon or robots.txt
# and since its always grabbed, turn it off in access log
# and turn off it's not-found error in the error log
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
location = /apple-touch-icon.png { access_log off; log_not_found off; }
location = /apple-touch-icon-precomposed.png { access_log off; log_not_found off; }

# Rather than just denying .ht* in the config, why not deny
# access to all .invisible files
location ~ /\. { deny  all; access_log off; log_not_found off; }

Ganti file /etc/nginx/conf.d/default.conf dengan:
*konfigurasi di bawah untuk web yang menggunakan www (redirect non www ke www)
**ganti namadomain dengan nama domain kamu

server {
    server_name  namadomain.com;
    rewrite ^(.*) http://www.namadomain.com$1 permanent;
}

server {
    ## Your website name goes here.
    server_name www.namadomain.com;
    ## Your only path reference.
    root /var/www/namadomain.com/;
    listen 80;
    ## This should be in your http block and if it is, it's not needed here.
    index index.html index.htm index.php;

    include conf.d/drop;

        location / {
                # This is cool because no php is touched for static content
			try_files $uri $uri/ /index.php?q=$uri&$args;
        }

        location ~ \.php$ {
            fastcgi_buffers 8 256k;
            fastcgi_buffer_size 128k;
            fastcgi_intercept_errors on;
            include fastcgi_params;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_pass unix:/var/run/php5-fpm.sock;
        }

        location ~* \.(css|js|png|jpg|jpeg|gif|ico)$ {
                expires 1w;
        }

}

Install PHPMyAdmin:

apt-get install phpmyadmin

Pindah ke directory web, misal:

cd /var/www/namadomain.com/

lalu buat shortcut:

ln -s /usr/share/phpmyadmin