Konfigurasi LEMP (Linux Ubuntu 16.04 + Nginx + MySQL 5.7 + PHP 7)

LEMP singkatan dari Linux, Nginx (dibaca: Engine X), MySQL, PHP

Install MySQL 5.7

apt-get -y install mysql-server mysql-client

To secure the database server and remove the anonymous user and test database, run the mysql_secure_installation command.

mysql_secure_installation

Enter password for user root: <-- masukin password
Would you like to setup VALIDATE PASSWORD plugin? <-- y jika ingin aktifin fitur ini, atau enter jika tidak
Change the password for root ? <-- ENTER
Remove anonymous users? <-- y
Disallow root login remotely? <-- y
Remove test database and access to it? <-- y
Reload privilege tables now? <-- y

Install Nginx

apt-get -y install nginx

Jalankan nginx

service nginx start

Install PHP 7.0

apt-get -y install php7.0-fpm

Setting Nginx

nano /etc/nginx/sites-available/namadomain.com

default vhost untuk web yang menggunakan www

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

server {
 server_name www.namadomain.com;
 listen 80;
 listen [::]:80;
 root /var/www/namadomain.com;
 index index.html index.htm index.nginx-debian.html index.php;
 location / {
 try_files $uri $uri/ /index.php?q=$uri&$args;
 }
 location ~ \.php$ {
 include snippets/fastcgi-php.conf;
 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:/run/php/php7.0-fpm.sock;
 }
 location ~ /\.ht {
  deny all;
 }
}

buat symlink:

ln -s /etc/nginx/sites-available/namadomain.com /etc/nginx/sites-enabled/

reload nginx

service nginx reload

edit /etc/php/7.0/fpm/php.ini

nano /etc/php/7.0/fpm/php.ini

ubah cgi.fix_pathinfo menjadi 0 dan uncomment,

[...]
; cgi.fix_pathinfo provides *real* PATH_INFO/PATH_TRANSLATED support for CGI.  PHP's
; previous behaviour was to set PATH_TRANSLATED to SCRIPT_FILENAME, and to not grok
; what PATH_INFO is.  For more information on PATH_INFO, see the cgi specs.  Setting
; this to 1 will cause PHP CGI to fix its paths to conform to the spec.  A setting
; of zero causes PHP to behave as before.  Default is 1.  You should fix your scripts
; to use SCRIPT_FILENAME rather than PATH_TRANSLATED.
; http://php.net/cgi.fix-pathinfo
cgi.fix_pathinfo=0
[...]

reload php-fpm

service php7.0-fpm reload

Mendapatkan support MySQL di PHP 7

Mendapatkan support MySQL di PHP 7 dan beberapa modul lain

apt-get -y install php7.0-fpm php7.0-common php7.0-mysql php-apcu php7.0-gd php7.0-curl php7.0-zip php7.0-json php7.0-xml php7.0-xmlrpc

modul lain bisa dilihat dengan command:

apt-cache search php7.0

Install PHPMyAdmin

Command untuk menginstall phpMyAdmin di ubuntu:

apt-get update
apt-get install phpmyadmin

Pindah ke directory web, misal:

cd /var/www/namadomain.com/

lalu buat shortcut:

ln -s /usr/share/phpmyadmin

phpMyAdmin bisa diakses di namadomain.com/phpmyadmin/

Leave a Reply

Your email address will not be published. Required fields are marked *