FreeBSD: Nginx FastCGI PHP Configuration

‮‬https://www.lautturi.com
FreeBSD: Nginx FastCGI PHP Configuration

To configure Nginx to use FastCGI to process PHP files on a FreeBSD system, you will need to do the following:

  1. Install Nginx and PHP on your FreeBSD system. You can install Nginx and PHP using the pkg package manager:
# pkg install nginx
# pkg install php72
  1. Enable the PHP FastCGI process manager (FPM) daemon. You can do this by adding the following line to the /etc/rc.conf file:
php_fpm_enable="YES"
  1. Start the PHP FPM daemon:
# service php-fpm start
  1. Edit the Nginx configuration file /usr/local/etc/nginx/nginx.conf and add the following lines to the http block to configure Nginx to use PHP FPM to process PHP files:
location ~ \.php$ {
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    include        fastcgi_params;
}

This configuration tells Nginx to pass any requests for PHP files to the PHP FPM daemon listening on 127.0.0.1:9000.

  1. Restart Nginx to apply the changes:
# service nginx restart
  1. Test the configuration by creating a PHP file in the document root of your Nginx server, and accessing it through a web browser. For example, if the document root is /usr/local/www/nginx, you can create a PHP file at /usr/local/www/nginx/test.php with the following contents:
<?php
echo "Hello, World!";

Then, access the file through a web browser by visiting http://your-server/test.php. If the PHP file is processed correctly, you should see the message "Hello, World!" in the web browser.

For more information about configuring Nginx and PHP FPM to process PHP files, you can refer to the Nginx documentation and the PHP documentation.

Created Time:2017-10-28 20:40:38  Author:lautturi