LEMP merupakan singkatan dari Linux, Nginx, MySQL, PHP dan dalam postingan ini kita akan menggunakan MySQL versi 5.5.29 dan PHP versi 5.4.11 dengan modul PHP-FPM dengan Nginx.
Untuk Install LEMP di CentOS mari ikuti beberapa langkah dibawah ini.
1. Install Remi Repository
- RHEL/CentOS 6.3-6.0
- RHEL/CentOS 5.4-5.0
# rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
# rpm -Uvh http://dl.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm
# rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-5.rpm
2. Install Nginx Repository
Buatlah sebuah file baru dengan nama “nginx.repo” pada direktori : /etc/yum.repos.d/ dan tambahkan baris di bawah ini sebagai isi dari file tersebut.
- RHEL
- CentOS
RHEL 6.3/6.2/6.1/6/5.8
[nginx] name=nginx repobaseurl=http://nginx.org/packages/rhel/$releasever/$basearch/
gpgcheck=0
enabled=1
CentOS 6.3/6.2/6.1/6/5.8
[nginx] name=nginx repobaseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1
3. Install Ngnix, MySQL 5.5.29, PHP 5.4.11 & PHP-FPM
# yum --enablerepo=remi,remi-test install nginx mysql mysql-server php php-common php-fpm
4. Install PHP 5.4.11 Modules
# yum --enablerepo=remi,remi-test install php-mysql php-pgsql php-pecl-mongo php-sqlite php-pecl-memcache php-pecl-memcached php-gd php-mbstring php-mcrypt php-xml php-pecl-apc php-cli php-pear php-pdo
5. Stop Service Apache
# chkconfig --levels 235 httpd off # /etc/init.d/httpd stop
6. Start/Stop Nginx MySQL dan PHP-FPM
- 1. Enable on Boot
- 2. Enable on Run Levels
Enable Nginx, MySQL and PHP-FPM
# chkconfig –add nginx
# chkconfig –add mysqld
# chkconfig –add php-fpm
Enable Nginx, MySQL and PHP-FPM
# chkconfig –levels 235 nginx on
# chkconfig –levels 235 mysqld on
# chkconfig –levels 235 php-fpm on
Startup Command
- 3. Nginx
- 4. MySQL
- 5. PHP-FPM
Nginx Startup Command
# /etc/init.d/nginx start
# /etc/init.d/nginx stop
# /etc/init.d/nginx status
MySQL Startup Commands
# /etc/init.d/mysqld start
# /etc/init.d/mysqld stop
# /etc/init.d/mysqld status
PHP-FPM Startup Commands
# /etc/init.d/php-fpm start
# /etc/init.d/php-fpm stop
# /etc/init.d/php-fpm status
7. Konfigurasi Nginx dan PHP-FPM
Buatlah direktori untuk menempatkan file website anda /srv/www/. contoh untuk dhansz.com. untuk direktori public_html dan logs.
# mkdir -p /srv/www/dhansz/public_html # mkdir /srv/www/dhansz/logs # chown -R nginx:nginx /srv/www/dhansz
Membuat Website Logs
buat direktori log /var/log.
# mkdir -p /srv/www/dhansz/public_html # mkdir -p /var/log/nginx/dhansz # chown -R nginx:nginx /srv/www/dhansz # chown -R nginx:nginx /var/log/nginx
Konfigurasi Direktori Virtual Host Buat direktori virtual host didalam direktori : /etc/nginx. # mkdir /etc/nginx/sites-available # mkdir /etc/nginx/sites-enabled
Tambahkan baris kode dibawah ini di dalam file /etc/nginx/nginx.conf dengan bantuan editor “nano” di akhir file, sebelum blok penutup tag http.
include /etc/nginx/sites-enabled/*;
Lihat contoh dibawah ini sebagai contoh file /etc/nginx/nginx.conf. ( Bagian berwarna biru)
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
Membuat Virtual Host file
Tambahkan kode baris dibawah ini ke dalam file /etc/nginx/sites-available/dhansz.
server { server_name dhansz; access_log /srv/www/dhansz/logs/access.log; error_log /srv/www/dhansz/logs/error.log; root /srv/www/dhansz/public_html; location / { index index.html index.htm index.php; } location ~ .php$ { include /etc/nginx/fastcgi_params; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /srv/www/dhansz/public_html$fastcgi_script_name; } }
Mengkoneksikan dhansz Virtual Host
Mengkoneksikan dhansz virtual host dengan /etc/nginx/sites-enabled.
# cd /etc/nginx/sites-enabled/ # ln -s /etc/nginx/sites-available/dhansz
Restart Nginx Service
# /etc/init.d/nginx restart
Tambahkan Virtual Domain kedalam Host File
tambahkan baris kode berikut kedalam file /etc/hosts.
127.0.0.1 localhost.localdomain localhost dhansz
8. Test Nginx, MySQL, PHP dan PHP-FPM
Buatlah sebuah file dengan nama : “phpinfo.php” didalam direktori /srv/www/dhansz/public_html/ dan tambahkan baris kode dibawah ini. contoh penempatan file nantinya :(/srv/www/dhansz/public_html/phpinfo.php).
< ?php phpinfo (); ?>
Sekarang coba untuk mengakses file phpinfo.php tadi di browser anda http://www.domain_ANDA.com/phpinfo.php
Selamat Mencoba….