Cara Install PHP dengan Nginx di CentOS 8

PHP adalah salah satu bahasa pemrograman paling populer di dunia yang digunakan untuk membangun website. PHP menjadi bagian dari LAMP (Linux Apache MariaDB PHP) / LEMP (Linux Nginx MariaDB PHP) stack.

*0.Install Nginx*

Install Nginx terlebih dahulu.

[INPUT]

1 2 3 4 dnf install nginx systemctl enable –now nginx systemctl start nginx systemctl status nginx

{{

Baca tutorial lengkap Cara Install Nginx di CentOS 8

}}

*1.FirewallD Service*

Masukkan service http ke dalam FirewallD agar web server dapat diakses.

[INPUT]

1 2 3 firewall-cmd –add-service=http –permanent firewall-cmd –reload firewall-cmd –list-services

{{

Baca tutorial lengkap Cara Setting Firewall dengan FirewallD di CentOS 8

}}

*2.Install PHP*

Versi PHP yang tersedia secara default di CentOS 8 adalah PHP versi 7.2.11.

[INPUT]

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 dnf info php   Name         : php Version      : 7.2.11 Release      : 1.module_el8.0.0+56+d1ca79aa Arch         : x86_64 Size         : 4.9 M Source       : php-7.2.11-1.module_el8.0.0+56+d1ca79aa.src.rpm Repo         : @System From repo    : AppStream Summary      : PHP scripting language for creating dynamic web sites URL          : http://www.php.net/ License      : PHP and Zend and BSD and MIT and ASL 1.0 Description  : PHP is an HTML-embedded scripting language. PHP attempts to make it              : easy for developers to write dynamically generated web pages. PHP              : also offers built-in database integration for several commercial and              : non-commercial database management systems, so writing a              : database-enabled webpage with PHP is fairly simple. The most common              : use of PHP coding is probably as a replacement for CGI scripts.              :              : The php package contains the module (often referred to as mod_php)              : which adds support for the PHP language to Apache HTTP Server.

Install paket PHP beserta extension yang sering digunakan.

[INPUT]

1 dnf install php php-mysqlnd php-pdo php-gd php-mbstring

Aktifkan dan jalankan service php-fpm.

[INPUT]

1 2 3 systemctl enable php-fpm systemctl start php-fpm systemctl status php-fpm

*3.Pengujian*

Mengecek hasil install PHP.

[INPUT]

1 2 3 4 5 php -v   PHP 7.2.11 (cli) (built: Oct  9 2018 15:09:36) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies

Mengecek hasil install PHP dengan membuat file PHPInfo.

[INPUT]

1 2 cd /usr/share/nginx/html echo “” > info.php

Lalu browsing http://ip-server/info.php.

Pengujian PHP dengan PHP Information

*4.Nginx + Server Block Nginx*

Selanjutnya mencoba melakukan konfigurasi server block untuk domain superuser.web.id.

Buat Document Root terlebih dahulu dan file testing PHP.

[INPUT]

1 2 mkdir /var/www/superuser.web.id echo “” > /var/www/superuser.web.id

Lalu file konfigurasi server block dengan nama file superuser.web.id.conf.

[INPUT]

1 vi /etc/nginx/conf.d/superuser.web.id.conf

Isi dari file konfigurasi.

[INPUT]

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 server {     listen 80;       server_name superuser.web.id;     root /var/www/superuser.web.id;       index index.php index.html;       location / { try_files $uri $uri/ /index.php?$query_string;     }           location ~ \.php$ { try_files $fastcgi_script_name =404; include fastcgi_params; fastcgi_pass unix:/run/php-fpm/www.sock; fastcgi_index index.php; fastcgi_param DOCUMENT_ROOT $realpath_root; fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;     }       access_log /var/log/nginx/superuser.web.id.access.log;     error_log /var/log/nginx/superuser.web.id.error.log warn; }

Restart service Nginx.

[INPUT]

1 2 systemctl restart nginx systemctl status nginx

Cek hasilnya dengan browsing http://superuser.web.id/info.php.

Pengujian PHP dengan Server Block Nginx

*5.Mencari Extension PHP*

Jika membutuhkan extension atau module PHP yang lain, cari nama paketnya dengan perintah dnf search.

[INPUT]

1 2 3 4 5 6 7 dnf search php-   php-gd.x86_64 : A module for PHP applications for using the gd graphics library php-cli.x86_64 : Command-line interface for PHP php-fpm.x86_64 : PHP FastCGI Process Manager php-cli.x86_64 : Command-line interface for PHP …

Selamat mencoba 🙂

Leave a Reply

Your email address will not be published.