Quick run through getting NGINX, PHP and MySQL running on FreeBSD 11.1
colin@openproject:~ % sudo pkg install -y nginx mysql56-server php56 php56-mysql
…
colin@openproject:~ % sudo sysrc mysql_enable=YES; sudo sysrc nginx_enable=YES; sudo sysrc php_fpm_enable=YES
colin@openproject:~ % sudo mv /usr/local/etc/php-fpm.conf ./php-fpm.conf.bak
colin@openproject:~ % sed s/’listen = 127.0.0.1:9000’/’listen = \/var\/run\/php-fpm.sock’/g ./php-fpm.conf.bak | sed s/’;listen.owner = www’/’listen.owner = www’/g | sed s/’;listen.group = www’/’listen.group = www’/g | sed s/’;listen.mode = 0660’/’listen.mode = 0660’/g > php-fpm.conf.new
colin@openproject:~ % sudo cp php-fpm.conf.new /usr/local/etc/php-fpm.conf
colin@openproject:~ % sudo sed s/’;cgi.fix_pathinfo=1’/’cgi.fix_pathinfo=0’/g /usr/local/etc/php.ini-production > php.ini
colin@openproject:~ % sudo cp php.ini /usr/local/etc/
colin@openproject:~ % sudo service php-fpm start
Performing sanity check on php-fpm configuration:
[24-Oct-2017 17:01:56] NOTICE: configuration file /usr/local/etc/php-fpm.conf test is successful
Starting php_fpm.
colin@openproject:~ % sudo service mysql-server start
Starting mysql.
colin@openproject:~ % sudo mysql_secure_installation
…
colin@openproject:~ % sudo service mysql-server restart
colin@openproject:~ % sudo cp /usr/local/etc/nginx/nginx.conf nginx.conf.bak
colin@openproject:~ % sudo sed s/’#user nobody;’/’user www;’/g /usr/local/etc/nginx/nginx.conf | sed s/’worker_processes 1;’/’worker_processes 2;’/g > nginx.conf.new
colin@openproject:~ % sudo cp nginx.conf.new /usr/local/etc/nginx/nginx.conf
colin@openproject:~ % sudo service nginx start
Performing sanity check on nginx configuration:
nginx: the configuration file /usr/local/etc/nginx/nginx.conf syntax is ok
nginx: configuration file /usr/local/etc/nginx/nginx.conf test is successful
Starting nginx.
… Then to have nginx proxy over to php, add this to your server block:
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $request_filename;
include fastcgi_params;
}
and you can test by creating a file info.php in server root which contains: <?php phpinfo(); ?>
… Restart nginx and go to http://webserver/info.php and verify it works!