PHP
PHP is a server-side scripting language designed for web development but also used as a general-purpose programming language. As of January 2013, PHP was installed on more than 240 million websites (39% of those sampled) and 2.1 million web servers. Originally created by Rasmus Lerdorf in 1994, the reference implementation of PHP (powered by the Zend Engine) is now produced by The PHP Group. While PHP originally stood for Personal Home Page, it now stands for PHP: Hypertext Preprocessor, which is a recursive backronym.
Instalasi PHP
Untuk melakukan instalasi PHP pada Web Server NGINX, pertama pastikan dulu anda telah menginstall NGINX pada Web Server anda, untuk melakukan instalasi NGINX dapat dilihat pada link berikut. Kemudian lakukan instalasi NGINX dengan menjalankan perintah berikut,
# yum install php php-mysql php-fpm
Setelah itu lakukan konfigurasi PHP Processor edit file /etc/php.ini dengan perintah berikut
# ee /etc/php.ini
Kemudian lakukan editing pada bagian cgi.fix_pathinfo, dengan menghilangkan tanda komentar; (titik koma) dan mengubah parameternya menjadi 0.
; 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://php.net/cgi.fix-pathinfo
cgi.fix_pathinfo=0
; FastCGI under IIS (on WINNT based OS) supports the ability to impersonate
; security tokens of the calling client. This allows IIS to define the
; security context that the request runs under. mod_fastcgi under Apache
; does not currently support this feature (03/17/2002)
; Set to 1 if running under IIS. Default is zero.
; http://php.net/fastcgi.impersonate
;fastcgi.impersonate = 1
# ee /etc/php-fpm.d/www.conf
Kemudian ubah parameter listen seperti pada konfigurasi dibawah.
; Note: This value is mandatory.
;listen = 127.0.0.1:9000
listen = /var/run/php-fpm/php-fpm.sock
; Set listen(2) backlog. A value of '-1' means unlimited.
; Default Value: -1
;listen.backlog = -1
Kemudian edit bagian listen.owner dan listen.group dengan menghilangkan tanda komentar; (titik koma)
; BSD-derived systems allow connections regardless of permissions.
; Default Values: user and group are set as the running user
; mode is set to 0666
listen.owner = nobody
listen.group = nobody
;listen.mode = 0666
; Unix user/group of processes
# systemctl start php-fpm
# systemctl enable php-fpm
Konfigurasi Virtual Hosts NGINX
Untuk melakukan konfigurasi Hosts pada NGINX lakukan konfigurasi pada directory /etc/nginx/conf.d/ dengan menambahkan file dengan extensi .conf. Misalnya kali ini digunakan konfigurasi default.conf. Buka file tersebut dengan menjalankan perintah berikut,
# ee /etc/nginx/conf.d/default.conf
Kemudian ketikkan konfigurasi berikut,
server {
listen 80;
server_name server_domain_name_or_IP;
# note that these lines are originally from the "location /" block
root /usr/share/nginx/html;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ =404;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
Setelah itu lakukan restart pada service NGINX dengan menggunakan perintah berikut
# systemctl restart nginx
Bila tidak ada masalah PHP telah berjalan dengan baik pada NGINX, kemudian lakukan testing dengan membuat satu buah file php misalnya info.php
# ee /usr/share/nginx/html/info.php
Lalu edit file tersebut sebagai berikut,
Kemudian arahkan web browser pada halaman tersebut, misalnya docs.harapan.me/info.php atau 167.205.3.1/info.php. Bila semua berjalan dengan baik, akan muncul tampilan sebagai berikut,
![]() |
Web Server menampilkan tampilan info.php |
0 comments:
Post a Comment