Skip to content

emka.web.id

menulis pengetahuan – merekam peradaban

Menu
  • Home
  • Tutorial
  • Search
Menu

Installing Nginx with PHP and PHP-FPM

Posted on November 2, 2013

Nginx (pronounced “engine x”) is a free, open-source, high-performance HTTP server. Nginx is known for its stability, rich feature set, simple configuration, and low resource consumption. This tutorial shows how you can install Nginx on a CentOS 6.0 server with PHP5 support (through PHP-FPM) and MySQL support.

For this time, i’ll be use the server1.example.com as my hostname, and the IP Address is 192.168.0.100. Please use your own settings!

On this tutorial, i’ll use CentOS 6.0 linux distributions as the server operating system, please refer to your own OS’s documentations. This is how to installing Nginx with PHP and PHP-FPM on CentOS 6.0

Step 1. Adding Extras Repositories

Unfortunatelly, php-fpm is not available yet on CentOS repos, so we’ve to add the repo from Remi RPM (http://rpms.famillecollet.com/) that relies on EPEL repository. To enable the Remi RPM with EPEL support, you can do this:

rpm –import https://fedoraproject.org/static/0608B895.txt

rpm -ivh http://download.fedora.redhat.com/pub/epel/6/i386/epel-release-6-5.noarch.rpm

then:

rpm –import http://rpms.famillecollet.com/RPM-GPG-KEY-remi

rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm

then install yum-priorities first (if your CentOS is not yet installed with yum-priorities):

yum install yum-priorities

Change the priority level of EPEL repo priorities to 10, edit the /etc/yum.repos.d/epel.repo. Example:

[epel]
name=Extra Packages for Enterprise Linux 6 - $basearch
#baseurl=http://download.fedoraproject.org/pub/epel/6/$basearch
mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-6&arch=$basearch
failovermethod=priority
enabled=1
priority=10
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
[...]

Do the same to REMI repo and enable it, example:

[remi]
name=Les RPM de remi pour Enterprise Linux $releasever - $basearch
#baseurl=http://rpms.famillecollet.com/enterprise/$releasever/remi/$basearch/
mirrorlist=http://rpms.famillecollet.com/enterprise/$releasever/remi/mirror
enabled=1
priority=10
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi
failovermethod=priority

[remi-test]
name=Les RPM de remi en test pour Enterprise Linux $releasever - $basearch
#baseurl=http://rpms.famillecollet.com/enterprise/$releasever/test/$basearch/
mirrorlist=http://rpms.famillecollet.com/enterprise/$releasever/test/mirror
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi

 

Step 2. Install MySQL 5

To install MySQL 5, example:

yum install mysql mysql-server

Unfortunatelly, MySQL is not starts automatically on CentOS, so we’ve to create the system startup links to start MySQL Server automatically, by this example command:

chkconfig –levels 235 mysqld on

/etc/init.d/mysqld start

Beware! please disabled the skip-networking step on MySQL (edit your own /etc/my.cnf) and run the mysql_secure_installation as soon as possible after you do MySQL installation.

 

Step 3. Install Nginx

To install Nginx, you can use yum:

yum install nginx

and create the system startup for it then starts it:

chkconfig –levels 235 nginx on

/etc/init.d/nginx start

NB. Check with your Webbrowser to your server address (e.g http://192.168.0.100), you should see the nginx welcome page.

 

Step 4. Install PHP5

PHP5 will running well on Nginx server with PHP-FPM (PHP FastCGI Process Manager). It can be installed together with php-cli and some PHP5 module like php-mysql. Example install:

yum install php-fpm php-cli php-mysql php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc php-eaccelerator php-magickwand php-magpierss php-mbstring php-mcrypt php-mssql php-shout php-snmp php-soap php-tidy

Fix the CGI path info on CentOS, edit the /etc/php.ini. Set cgi.fix_pathinfo = 0; example:

[...]
; 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://www.php.net/manual/en/ini.core.php#ini.cgi.fix-pathinfo
cgi.fix_pathinfo=0
[...]

 

Step 5 (extra) Configuring Nginx

The configuration is in /etc/nginx/nginx.conf. For example, we can increase the number of worker processes and the keep alive timeout, like:

worker_processes 5;

keepalive_timeout 2;

Or you can defined new server vhost, it’s also in nginx.conf. Example:

[...]
    server {
        listen       80;
        server_name  _;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   /usr/share/nginx/html;
            index  index.php index.html index.htm;
        }

        error_page  404              /404.html;
        location = /404.html {
            root   /usr/share/nginx/html;
        }

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   /usr/share/nginx/html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~ \.php$ {
            root           /usr/share/nginx/html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        location ~ /\.ht {
            deny  all;
        }
    }
[...]

Restart Nginx with /etc/init.d/nginx restart

Happy Nginx-ing!

Terbaru

  • Apa Itu Putlocker? Ini Pengertian dan Deretan Alternatif Penggantinya
  • Apa Itu Extend Volume? Ini Cara Memperluas Drive C di Windows 11
  • Ini Trik AFK Fish It Roblox Pakai LDCloud, Auto Panen Ikan Tanpa Bikin HP Panas!
  • Apa itu Game Zenless Zone Zero (ZZZ) HoYoVerse? Ini Cara Mainnya
  • Cuma Kurang 1 Rupiah! Misteri Lucky Draw Akulaku Rp300 Ribu, Bisa Cair Nggak Sih?
  • Video Melolo Cuma Layar Hitam? Ini Trik Ampuh Mengatasinya, Pasti Berhasil!
  • Mau Simpan Video Twitter dan TikTok Tanpa Aplikasi? Begini Cara Praktis Pakai VidsSave!
  • Mau Gaji Dolar? Gini Caranya Tembus Kerja di Australia, Jangan Sampai Salah Visa!
  • Belum Tahu? Inilah Fakta MigoReels, Katanya Nonton Drama Bisa Dapat Rp700 Ribu!
  • Apa Itu Event Invite Friends CapCut? Ini Pengertian dan Cara Kerjanya Biar Cuan
  • Apa Itu MJ di FF? Ini Pengertian, Asal-Usul, dan Risiko di Balik Istilah Tersebut
  • Apa Itu Pengertian Penonaktifan SPayLater? Ini Durasi Blokir Akibat Telat Bayar
  • Apa Itu Rasio Gambar Ukuran 1:1 di Canva? Ini Pengertian dan Cara Buatnya
  • Pengiriman Shopee Express Hemat itu Berapa Lama? Ini Pengertian dan Estimasi Sampainya
  • Android 2025: Aplikasi Baru dan Smartphone Impian yang Akan Datang!
  • Apa Itu Google AI Pro Ultra? Ini Pengertian dan Penjelasan Lengkapnya
  • Apa Itu Error Gagal Kirim Nilai RDM 3.1? Ini Pengertian dan Solusi Mengatasinya
  • Facebook Mulai Batasi Link Eksternal Cuma 2 Sebulan! Ini Trik Mengatasinya
  • Cara Nonton Tensura Season 4! Bakal Tayang April 2026 dengan Format 5 Cour
  • Belum Tahu? Inilah Trik Supaya Live TikTok Kalian Aman dan Banjir Cuan
  • Pixel 8 Dapatkan Mode Panorama Baru! Hasil Foto Lebih Luas & Lebih Kreatif
  • Apa Itu AppLocker? Ini Pengertian dan Cara Mengamankan Windows 11 Kalian dari Skrip Jahat
  • Cara Membuat Riwayat Copilot Kamu Tetap Bersih dan Rapi!
  • Game & Aplikasi Android Terbaik Saat Diskon Liburan Natal! Jangan Ketinggalan!
  • Apa Itu Game Prison Escape Journey? Ini Pengertian dan Cara Mainnya untuk Pemula
  • “Listrik Gratis” dari Solar Panel Cuma Mitos?! Ini Sisi Gelap PLTS
  • Samsung Galaxy Z-Fold: Uji Jatuh Bebas yang Mengguncang Keandalan Lipatannya
  • Google One 2026: Apa yang Akan Jadi Fitur Utama dan Harga yang Diharapkan?
  • Apa Itu Error 0x800704f8? Ini Pengertian dan Cara Mengatasinya
  • Android Akhirnya Dapat GPS Darurat di India! Setelah Hampir 10 Tahun
  • Apa itu Cosmic Desktop: Pengertian dan Cara Pasangnya di Ubuntu 26.04?
  • Apa Itu Auvidea X242? Pengertian Carrier Board Jetson T5000 dengan Dual 10Gbe
  • Elementary OS 8.1 Resmi Rilis: Kini Pakai Wayland Secara Standar!
  • Apa Itu Raspberry Pi Imager? Pengertian dan Pembaruan Versi 2.0.3 yang Wajib Kalian Tahu
  • Performa Maksimal! Ini Cara Manual Update Ubuntu ke Linux Kernel 6.18 LTS
  • Inilah Cara Kerja AI Instagram Deteksi Konten Berbahaya dan Spam Secara Otomatis
  • Prompt AI Tahun Baruan di Bundaran HI
  • Prompt AI Pamer iPhone 17 Pro Max Orange
  • Apa itu GPT 5.2 di Microsoft Copilot? Ini Pengertian dan Keunggulannya
  • Apa Itu Iklan ChatGPT? Mengenal Sponsored Content yang Bakal Muncul di Hasil Pencarian AI
  • Apa itu CVE-2025-68664? Memahami Celah Keamanan LangGrinch pada LangChain
  • Kronologi Kasus Pencurian Data Karyawan Data Breach Korean Air 2025
  • Ini Kronologi Hack Memalukan Trustwallet di Natal 2025
  • Apa Itu Insiden Eksploitasi Sistem Rainbow Six Siege? Ini Penjelasannya
  • Apa Itu Docker Hardened Images (DHI)? Ini Definisi dan Penjelasannya
Beli Pemotong Rumput dengan Baterai IRONHOOF 588V Mesin Potong Rumput 88V disini https://s.shopee.co.id/70DBGTHtuJ
Beli Morning Star Kursi Gaming/Kantor disini: https://s.shopee.co.id/805iTUOPRV

©2026 emka.web.id | Design: Newspaperly WordPress Theme