Selama menggunakan unmanaged VPS untuk menjalankan semua website, saya selalu menggunakan LEMP stack (Linux, Nginx, MariaDB/MySQL, PHP). Karena selain cukup ringan, saya paling nyaman menggunakannya, baik untuk setup maupun troubleshooting ketika sudah berjalan.
Nah, sekalian buat catatan pribadi, berikut adalah setup LEMP favorit saya untuk menjalankan WordPress.
Install semuanya software yang dibutuhkan. Saya asumsikan kamu sudah login sebagai root ya.
#apt update
#apt upgrade
#apt install software-properties-common php-common php-memcached php7.0 php7.0-cli php7.0-fpm php7.0-gd php7.0-json php7.0-mysql php7.0-xml php7.0-opcache memcached mariadb-server nginx
Setup MariaDB
#mysql_secure_installation
Buat user baru MariaDB
#mysql -u root -p
(masukkan password yang dibuat saat proses instalasi MariaDB tadi)
Dalam MariaDB (sesuaikan nama user dan password dengan yang akan kamu buat)
MariaDB [(none)]>CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password';
MariaDB [(none)]>GRANT ALL PRIVILEGES ON * . * TO 'newuser'@'localhost';
MariaDB [(none)]>FLUSH PRIVILEGES;
Setup NGINX
Buat konfigurasi NGINX untuk WordPress yang mendukung Memcached di /etc/nginx/ffpc.conf
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
location / {
# This is cool because no php is touched for static content.
# include the “?$args” part so non-default permalinks doesn’t break when using query string
try_files $uri $uri/ /index.php?$args;
}
location ~ \.(php)$ {
proxy_intercept_errors on;
fastcgi_keep_conn on;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
default_type text/html;
set $memcached_raw_key $scheme://$host$request_uri;
set $memcached_key data-$memcached_raw_key;
set $memcached_request 1;
if ($request_method = POST ) {
set $memcached_request 0;
}
if ( $uri ~ “/wp-” ) {
set $memcached_request 0;
}
if ( $args ) {
set $memcached_request 0;
}
if ($http_cookie ~* “comment_author_|wordpressuser_|wp-postpass_|wordpress_logged_in_” ) {
set $memcached_request 0;
}
if ( $memcached_request = 1) {
memcached_pass 127.0.0.1:11211;
error_page 404 = @nocache;
break;
}
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
location @nocache {
proxy_intercept_errors on;
fastcgi_keep_conn on;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
add_header X-Cache-Engine “not cached”;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
expires max;
log_not_found off;
}
atau eksekusi perintah berikut untuk mendownload
wget -P /etc/nginx/ https://gist.githubusercontent.com/andrea-sdl/338ad1cde3841ffd7ae6/raw/00e24040d2e89b37269a9978540688f89b83251a/ffpc.conf
Edit file /etc/nginx/nginx.conf, sesuaikan dengan konfigurasi berikut. Silakan ubah yang dirasa kurang sesuai dengan kebutuhan, yang saya edit adalah yang saya beri warna biru.
user www-data;
worker_processes auto;
pid /run/nginx.pid;
events {
worker_connections 768;
multi_accept on;
}
http {
##
# Basic Settings
##
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 300;
types_hash_max_size 2048;
client_max_body_size 100m;
# server_tokens off;
server_names_hash_bucket_size 256;
# server_name_in_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# SSL Settings
##
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
##
# Gzip Settings
##
gzip on;
gzip_disable “msie6”;
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_types text/plain text/css application/json application/javascript t ext/xml application/xml application/xml+rss text/javascript;
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
#mail {
# # See sample authentication script at:
# # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
#
# # auth_http localhost/auth.php;
# # pop3_capabilities “TOP” “USER”;
# # imap_capabilities “IMAP4rev1” “UIDPLUS”;
#
# server {
# listen localhost:110;
# protocol pop3;
# proxy on;
# }
#
# server {
# listen localhost:143;
# protocol imap;
# proxy on;
# }
#}
Buat konfigurasi untuk domain yang akan digunakan di /etc/nginx/sites-availabe/namadomainmu.com
server {
listen 80;
server_name namadomainmu.com;
root /var/www/namadomainmu.com/;
index index.php;
error_log /var/log/nginx/namadomainmu.com.COM.error.log;
include ffpc.conf;
}
Enable domain
#ln -s /etc/nginx/sites-availabe/namadomainmu.com /etc/nginx/sites-enabled/
Setup PHP
Edit file /etc/php/7.0/fpm/php.ini
Ubah bagian
;cgi.fix_pathinfo=1
Jadi
cgi.fix_pathinfo=0
Lalu bagian limit upload
upload_max_filesize = 2M
Ubah jadi
upload_max_filesize = 10M
Karena kalau mau upload gambar sering kena limit. 😀
Setup WordPress
#cd /var/www
#wget https://wordpress.org/latest.zip
#unzip latest.zip
#mv wordpress namadomainmu.com
#chown R www-data:www-data namadomainmu.com
#chmod -R 755 namadomainmu.com/wp-content/
Restart semua service
#/etc/init.d/nginx restart
#/etc/init.d/php7.0-fpm restart
#/etc/init.d/memcached restart
Sekarang silakan arahkan namadomainmu.com ke IP address server baru atau kalau lebih suka pakai edit NS ya silakan. Kalau sudah terarah ke server baru, kamu bisa akses melalui browser dan melancarkan konfigurasi WordPress.
Sekian dan terima PayPal..
[email protected] 😀
Referensi: