Mungkin kalian sudah sering mendengar installasi dan kombinasi Apache, Mysql dan PHP. Nah kali ini ayies akan mengganti Apache/HTTPD dengan Nginx (En-Gin-X). Begini caranya:
Install PHP
$ sudo apt update $ sudo apt install php php-fpm
Cek versi PHP yang terinstall
$ php -v PHP 7.0.4-7ubuntu2 (cli) ( NTS ) Copyright (c) 1997-2016 The PHP Group Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies
Install NGINX
$ sudo apt install nginx
Install MySQL
$ sudo apt install mysql-server php-mysql
Setup PHP FPM
$ sudo nano /etc/php/7.0/fpm/php.ini
Uncomment baris ini dan ubah 1 menjadi 0
cgi.fix_pathinfo=0
Ubah file www.conf
$ sudo nano /etc/php/7.0/fpm/pool.d/www.conf
Dan ubah menjadi
; listen = /run/php/php7.0-fpm.sock listen = 127.0.0.1:9000
Setup NGINX Virtualhost
Edit file berikut ini
$ sudo nano /etc/nginx/sites-enabled/default.conf
Dan ubah menjadi :
server {
listen 80;
root /var/www;
index index.php index.html index.htm;
server_name example.com www.example.com;
location / {
try_files $uri $uri/ /index.html;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/www;
}
location ~ .php$ {
try_files $uri =404;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
Restart service Nginx dan PHP FPM
$ sudo systemctl restart nginx.service $ sudo systemctl restart php7.0-fpm.service
Allow port 80 (HTTP) di sisi Firewall
Jika menggunakan Firewall Iptables :
$ sudo iptables -A INPUT -m state --state NEW -p tcp --dport 80 -j ACCEPT
Jika menggunakan Firewall UFW :
$ sudo ufw allow 80/tcp
Selesai ! Silahkan akses di browser menggunakan alamat http://localhost atau IP server/PC kamu.