Thursday, May 07, 2020

Nginx PHP-FPM setup under Kali Linux

Another Nginx PHP-FPM setup post similar to previous post [ here ]

To start with, install Nginx...

root@kali:~# apt-get -y install nginx

Start Nginx

root@kali:~# service nginx start

Install PHP-FPM, note the version

root@kali:~# apt-get -y install php-fpm

Edit default configuration

root@kali:~# vi /etc/nginx/sites-available/default

Add index.php into server block

index index.html index.htm index.nginx-debian.html index.php;

Add location block

location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.3-fpm.sock;
}

Restart Nginx

root@kali:~# service nginx restart

Edit php.ini, note the PHP-FPM version, add cgi.fix_pathinfo=0

root@kali:~# vi /etc/php/7.3/fpm/php.ini

; 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://php.net/cgi.fix-pathinfo
cgi.fix_pathinfo=0

Restart PHP-FPM

root@kali:~# service php7.3-fpm restart

Create a PHP test page "test.php" as content below and save it to /var/www/html/

<?php
phpinfo();
?>

run the PHP file = http://<your host>/test.php






No comments:

Post a Comment