FreeBSD install PHP 7.2 with FPM for Nginx

Here are the steps to install PHP 7.2 with FPM (FastCGI Process Manager) for Nginx on FreeBSD:

  1. Install the PHP package using pkg:
pkg install php72
  1. Install the PHP-FPM package:
pkg install php72-fpm
  1. Enable PHP-FPM in the system:
sysrc php_fpm_enable=yes
  1. Start the PHP-FPM service:
service php-fpm start
  1. Configure Nginx to use PHP-FPM. Edit the Nginx configuration file, usually located at /usr/local/etc/nginx/nginx.conf and add the following lines in the server block:
location ~ \.php$ {
fastcgi_pass unix:/var/run/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
  1. Check the configuration and reload the nginx service
nginx -t
service nginx reload
  1. Verify that PHP is working by creating a file info.php in the document root of your server, and adding the following line:
<?php phpinfo(); ?>
  1. Access the file in your browser http://your-server-ip-address/info.php

You should now have PHP 7.2 with FPM for Nginx installed and configured on your FreeBSD system. You can now start building your PHP web application on this server.

Leave a Comment