Install Multi Versi PHP 5.6 dan 7.2 Pada Server Centos dengan Apache Webserver

Step1#: Install packages yang dibutuhkan

Apache
yum install httpd

Extra Packages for Enterprise Linux (EPEL)
yum install epel-release

Yum utilities
yum install yum-utils

Update yum
yum update


Step2#: Install Multi PHP 5.6 dan 7.2

Install  remi-repository 
yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm

Install PHP5.6 dan PHP-FPM5.6
yum install php56
yum install php56-php-fpm

Install PHP7.2 and PHP-FPM7.2
yum install php72
yum install php72-php-fpm

Install Modul PHP7.2
yum-config-manager --enable remi-php72
yum install php php-common php-opcache php-mcrypt php-cli php-gd php-curl php-mysqlnd

Step3#: Stop both PHP-FPM

Hentikan terlebih dahulu kedua service php-fpm sebelum lanjut ke Step4
systemctl stop php56-php-fpm
systemctl stop php72-php-fpm

Step4#: Konfigurasi PHP-FPM

Secara default apache akan listen port 9000 untuk php, ketika kita install multi versi php kita harus menambahkan port unik untuk kedua php tersebut. dalam tutorial ini kami menggunakan port 9056 untuk php 5.6 dan 9072 untuk php 7.2

php 5.6
Untuk cara manual file konfigurasi php5.6 terletak di /etc/opt/remi/php56/php-fpm.d/www.conf, gunakan vim ,nano atau editor lainnya untuk edit file tersebut, atau langsung dengan copy paste script berikut.
sed -i 's/:9000/:9056/' /etc/opt/remi/php56/php-fpm.d/www.conf
php 7.2
letak file konfigurasi di /etc/opt/remi/php72/php-fpm.d/www.conf
sed -i 's/:9000/:9072/' /etc/opt/remi/php72/php-fpm.d/www.conf

Jalankan kedua php-fpms
systemctl start php72-php-fpm
systemctl start php56-php-fpm

Step5#: Configure SELinux

Ketika menambahkan port baru (9056 dan 9072) maka kita harus menambahkannya di SELINUX 
semanage port -a -t http_port_t -p tcp 9072
semanage port -a -t http_port_t -p tcp 9056

Step6#: Membuat Script Wrapper

Untuk memanggil kedua versi php berdasarkan permintaan user maka harus menambahkan file php56.fcgi dan php72.fcgi, file tersebut diletakkan di /var/ww/cgi-bin, buat folder dan file nya sekaligus dengan script berikut :

php5.6
cat > /var/www/cgi-bin/php56.fcgi << EOF 
#!/bin/bash 
exec /bin/php56-cgi 
EOF 

php7.2 
cat> /var/www/cgi-bin/php72.fcgi << EOF 
#!/bin/bash 
exec /bin/php72-cgi 
EOF

Buat script wrapper menjadi executable
sudo chmod 755 /var/www/cgi-bin/php56.fcgi
sudo chmod 755 /var/www/cgi-bin/php72.fcgi

untuk memastikan folder dan script wrapper sudah dibuat masuk ke /var/www/cgi-bin, lihat gambar dibawah ini : 

atau melalui command prompt

Step7#: Konfigurasi Apache

dari beberapa artikel lain serupa yang kami coba terdapat kegagalan muncul error 500 ketika load php7.2, tambahkan konfigurasi di bawah ini pada  httpd.conf untuk mengatasi tersebut. Letak file httpd.conf berada di /etc/httpd/conf. Harap disesuaikan konfigurasi dengan domain yang akan digunakan pada konfigurasi anda.

#php56 tes
<VirtualHost *:80>
    ServerAdmin admin@ilmujaringan.web.id
    ServerName localhost56.test
    DocumentRoot /var/www/html/php56
    DirectoryIndex index.php index.html
    <FilesMatch "\.php$">
        <If "-f %{REQUEST_FILENAME}">
            SetHandler "proxy:fcgi://127.0.0.1:9056"
        </If>
    </FilesMatch>
    ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
    AddHandler php56-fcgi .php
    Action php56-fcgi /cgi-bin/php56.fcgi

    <Directory "/var/www/html/php56">
        AllowOverride All
    </Directory>
</VirtualHost>

#php72 tes
<VirtualHost *:80>
    ServerAdmin admin@ilmujaringan.web.id
    ServerName localhost72.test
    DocumentRoot "/var/www/html/php72"
    DirectoryIndex index.html index.php
    <Directory "/var/www/html/php72">
        AllowOverride All
    </Directory>
    <FilesMatch "\.php$">
        <If "-f %{REQUEST_FILENAME}">
            SetHandler "proxy:fcgi://127.0.0.1:9072"
        </If>
    </FilesMatch>
    ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
    AddHandler php72-fcgi .php
    Action php72-fcgi /cgi-bin/php72.fcgi
</VirtualHost>

Step8#:  Membuat File Index.php

mkdir -p /var/www/html/php56
mkdir -p /var/www/html/php72
echo "<?php phpinfo(); ?>" > /var/www/html/php56/index.php
echo "<?php phpinfo(); ?>" > /var/www/html/php72/index.php

Step9#:  Start/Enable Services

systemctl enable httpd 
systemctl enable php56-php-fpm 
systemctl enable php72-php-fpm 
systemctl start httpd 
systemctl start php56-php-fpm 
systemctl start php72-php-fpm


Step10#: Testing

Tutorial ini sudah 100% work, tested by me...pastikan semua langkah diatas sudah diikuti dengan benar

php5.6
multi version php5.6 dan php7.2

php7.2
multi version php5.6 dan php7.2


Step#11: Trik

Melihat modul php56 yang terpasang
yum list installed | grep -i php56

Configuration wizard Remi's RPM Repository
visit http://rpms.remirepo.net/wizard/

Mencari module php yang belum tersedia ex: PHP module zip
yum --enablerepo=remi-php73 search php73 | grep zip

Result:
php73-php-pecl-zip.x86_64 : Une extension de gestion des ZIP
rh-php73-php-zip.x86_64 : ZIP archive management extension for PHP

Kemudian
yum install rh-php73-php-zip.x86_64

Melihat module php yang terinstall
php -m

Testing melakukan instalasi Slims 9 Bullian, beberapa error yang terjadi :
Database driver, PHP GD, PHP mbstring, YAZ not installed

Problem solving
  • instalasi php-fpm 73 karena slims9 Bullian tidak support php72, langkah-langkah nya seperti diatas ketika instalasi php72-fpm
  • Instalasi module php dan yaz
    # sudo yum install php73-php-fpm php73-php-gd php73-php-json php73-php-mbstring php73-php-mysqlnd php73-php-xml php73-php-xmlrpc php73-php-opcache

    # yum Install php73-php-pecl-yaz rpm

    # yum --enablerepo=remi install php73-php-pecl-yaz
  • tidak dapat akses index.html, index.php
    edit /etc/httpd/conf/httpd.conf, sesuaikan seperti konfigurasi di bawah, kemudian buat file index.html, akses ip server


  • # line 86: change to admin's email address
    ServerAdmin root@srv.world
    # line 95: change to your server's name
    ServerName www.srv.world:80
    # line 151: change
    AllowOverride All
    # line 164: add file name that it can access only with directory's name
    DirectoryIndex index.html index.cgi index.php
    # add follows to the end
    # server's response header
    ServerTokens Prod
    [root@www ~]# systemctl start httpd
    [root@www ~]# systemctl enable httpd





Belum ada Komentar untuk "Install Multi Versi PHP 5.6 dan 7.2 Pada Server Centos dengan Apache Webserver"

Posting Komentar

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel