Install NGINX 1.10, PHP-FPM 7.0, dan MariaDB 10.1 di CentOS 7

Kemarin, saat mengunjungi website NGINX ternyata telah release versi stable yang sudah support untuk HTTP/2. Dimana dengan HTTP/2, website akan di-deliver ke client dengan lebih cepat dibanding dengan HTTP/1.1, bisa dilihat dari link ini https://http2.akamai.com/demo. karena itu admin langsung mau coba deh migrasiin web ini ke HTTP/2. Di tutorial ini yang akan diinstall adalah NGINX versi 1.10, PHP-FPM versi 7.0, dan MariaDB versi 10.1. Let’s get started.

Install NGINX 1.10

pertama yang dilakukan adalah upgrade centos terlebih dahulu

yum -y upgrade

lalu di-restart jika telah selesai.

reboot

karena udah kebiasaan menggunakan nano untuk editor dan juga wget untuk mendownload package NGINX, install dulu yaaa

yum install nano wget

setelah itu kita siapkan beberapa tools pendukung untuk meng-compile NGINX dari source code.

yum install gcc openssl-devel pcre-devel

lalu download source code NGINX 1.10

wget http://nginx.org/download/nginx-1.10.0.tar.gz

setelah itu di-extract

tar xzvf nginx-1.10.0.tar.gz

masuk ke directory yang telah di-ectract

cd nginx-1.10.0

oh iyaaa buat dulu user untuk NGINX nya

useradd -d /etc/nginx/ -s /sbin/nologin nginx

di konfigure dahulu sebelum di compile

./configure \
--prefix=/etc/nginx \
--sbin-path=/usr/sbin/nginx \
--conf-path=/etc/nginx/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--pid-path=/var/run/nginx.pid \
--lock-path=/var/run/nginx.lock \
--http-client-body-temp-path=/var/cache/nginx/client_temp \
--http-proxy-temp-path=/var/cache/nginx/proxy_temp \
--http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \
--http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \
--http-scgi-temp-path=/var/cache/nginx/scgi_temp \
--user=nginx \
--group=nginx \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_sub_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_random_index_module \
--with-http_secure_link_module \
--with-http_stub_status_module \
--with-http_auth_request_module \
--with-threads \
--with-stream \
--with-stream_ssl_module \
--with-http_slice_module \
--with-mail \
--with-mail_ssl_module \
--with-file-aio \
--with-http_v2_module \
--with-ipv6

lalu di-compile

make

dan

make install

untuk verifikasi jalankan perintah

nginx -v

dan akan tampil seperti diwabah ini :

nginx-version

kita tambahkan file executable untuk memudahkan start/stop service NGINX

nano /etc/init.d/nginx
#!/bin/sh
#
# nginx - this script starts and stops the nginx daemon
#
# chkconfig:   - 85 15 
# description:  Nginx is an HTTP(S) server, HTTP(S) reverse \
#               proxy and IMAP/POP3 proxy server
# processname: nginx
# config:      /etc/nginx/nginx.conf
# config:      /etc/sysconfig/nginx
# pidfile:     /var/run/nginx.pid
 
# Source function library.
. /etc/rc.d/init.d/functions
 
# Source networking configuration.
. /etc/sysconfig/network
 
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
 
nginx="/usr/sbin/nginx"
prog=$(basename $nginx)
 
NGINX_CONF_FILE="/etc/nginx/nginx.conf"
 
[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
 
lockfile=/var/lock/subsys/nginx
 
make_dirs() {
   # make required directories
   user=`$nginx -V 2>&1 | grep "configure arguments:" | sed 's/[^*]*--user=\([^ ]*\).*/\1/g' -`
   if [ -z "`grep $user /etc/passwd`" ]; then
       useradd -M -s /bin/nologin $user
   fi
   options=`$nginx -V 2>&1 | grep 'configure arguments:'`
   for opt in $options; do
       if [ `echo $opt | grep '.*-temp-path'` ]; then
           value=`echo $opt | cut -d "=" -f 2`
           if [ ! -d "$value" ]; then
               # echo "creating" $value
               mkdir -p $value && chown -R $user $value
           fi
       fi
   done
}
 
start() {
    [ -x $nginx ] || exit 5
    [ -f $NGINX_CONF_FILE ] || exit 6
    make_dirs
    echo -n $"Starting $prog: "
    daemon $nginx -c $NGINX_CONF_FILE
    retval=$?
    echo
    [ $retval -eq 0 ] && touch $lockfile
    return $retval
}
 
stop() {
    echo -n $"Stopping $prog: "
    killproc $prog -QUIT
    retval=$?
    echo
    [ $retval -eq 0 ] && rm -f $lockfile
    return $retval
}
 
restart() {
    configtest || return $?
    stop
    sleep 1
    start
}
 
reload() {
    configtest || return $?
    echo -n $"Reloading $prog: "
    killproc $nginx -HUP
    RETVAL=$?
    echo
}
 
force_reload() {
    restart
}
 
configtest() {
  $nginx -t -c $NGINX_CONF_FILE
}
 
rh_status() {
    status $prog
}
 
rh_status_q() {
    rh_status >/dev/null 2>&1
}
 
case "$1" in
    start)
        rh_status_q && exit 0
        $1
        ;;
    stop)
        rh_status_q || exit 0
        $1
        ;;
    restart|configtest)
        $1
        ;;
    reload)
        rh_status_q || exit 7
        $1
        ;;
    force-reload)
        force_reload
        ;;
    status)
        rh_status
        ;;
    condrestart|try-restart)
        rh_status_q || exit 0
            ;;
    *)
        echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
        exit 2
esac

lalu tambahkan attribute executable ke file tersebut

chmod +x /etc/init.d/nginx

dan coba untuk jalankan service NGINX

service nginx start

sekarang coba buka browser dan coba akses

nginx

 

Install PHP-FPM 7.0

kalau sudah selesai install NGINX mari dilanjut install php-fpm agar bisa memproses PHP.

ada beberapa tools yang diperlukan, yaitu Repo Remi, karena di repo ini yang udah nge-release versi terbarunya dari PHP. berikut langkah-langkahnya :

menambahkan repo remi, sebelum menambahkan repo remi dibutuhkan terlebih dahulu repo dari EPEL, menambahkannya dengan cara

yum install epel-release

setelah itu lanjut untuk menambahkan repo REMI

rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm

lalu install package PHP-FPM versi 7.0

yum install php70-php-fpm php70-php-gd php70-php-mbstring php70-php-mcrypt php70-php-mysqlnd php70-php-xmlrpc

setelah itu ada tambahan config pada /etc/opt/remi/php70/php-fpm.d/www.conf

nano /etc/opt/remi/php70/php-fpm.d/www.conf

cari user dan group, lalu ganti isinya dengan ‘nginx’

user = nginx
group = nginx

lalu ubah juga nilai dari cgi.fix_pathinfo menjadi 0 pada file /etc/opt/remi/php70/php.ini

cgi.fix_pathinfo=0

setelah ini tambahkan config di NGINX agar dapat meneruskan proses PHP ke PHP-FPM

nano /etc/nginx/nginx.conf
location ~ \.php$ {
    root           html;
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    include        fastcgi_params;
}

setelah itu buat file testing php untuk melihat apakah php-fpm nya sudah berfungsi

nano /etc/nginx/html/tes.php

jika sudah start PHP-FPM dan juga restart NGINX

service php70-php-fpm start
service nginx restart

jika sudah coba buka browser dan coba akses

php

 

Install MariaDB 10.1

nah, ini yang terakhir nih MariaDB, sebenernya sih admin baru tau MariaDB ini saat mulai nyoba-nyobain CentOS 7 dimana kalau mau install MySQL eh malah disuruh install MariaDB, ternyata default-nya di CentOS 7 ini MariaDB telah menggantikan MySQL, walaupun sebenarnya saat menggunakan MariaDB, ngak beda jauh dengan MySQL, mungkin ada kelebihannya dibanding MySQL (pasti ada sih haha)

untuk menginstall MariaDB yang versi terbaru kita harus menggunakan repo dari MariaDB nya langsung, seperti dibawah ini

nano /etc/yum.repos.d/MariaDB.repo
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.1/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1

setelah itu tinggal diinstall

yum install MariaDB-server MariaDB-client

mudah kan??? hehe, lalu start MariaDB-nya

service mariadb start

nah kalau udah, di setup dahulu MariaDB nya

mysql_secure_installation
Enter current password for root (enter for none):
OK, successfully used password, moving on...

Set root password? [Y/n] y
New password:
Re-enter new password:
Password updated successfully!

Remove anonymous users? [Y/n] y
 ... Success!

Disallow root login remotely? [Y/n] y
 ... Success!

Remove test database and access to it? [Y/n] y
 - Dropping test database...
 ... Success!

Reload privilege tables now? [Y/n] y
 ... Success!

setelah itu coba login

mysql -uroot -p

mysql

oke, cukup sekian dulu yaa, nantikan tutorial berikutnya, selamat mencoba.

About the author
arisyi

Routecloud Networks

Information about Server, Linux and Computer Network.

Great! You’ve successfully signed up.

Welcome back! You've successfully signed in.

You've successfully subscribed to Routecloud Networks.

Success! Check your email for magic link to sign-in.

Success! Your billing info has been updated.

Your billing was not updated.