Setting up PHP 7 with Nginx

Published on December 29, 2020

Installation

Install PHP 7:

apk add php7-fpm php7-mcrypt php7-soap php7-openssl php7-gmp php7-pdo_odbc php7-json php7-dom php7-pdo php7-zip php7-mysqli php7-sqlite3 php7-apcu php7-pdo_pgsql php7-bcmath php7-gd php7-odbc php7-pdo_mysql php7-pdo_sqlite php7-gettext php7-xmlreader php7-xmlrpc php7-bz2 php7-iconv php7-pdo_dblib php7-curl php7-ctype

Configuration

Edit /etc/php7/php.ini:

[Date]
date.timezone = Europe/Amsterdam

Start the service:

/etc/init.d/php-fpm7 start
rc-update add php-fpm7

Edit /etc/nginx/sites-available/02_localhost to add in the following within server:

server {
	location ~\.php$ {
		fastcgi_split_path_info ^(.+\.php)(.*)$;
		include fastcgi.conf;
		fastcgi_pass 127.0.0.1:9000;
	}
}

Edit /var/www/localhost/htdocs/version.php:

<?php
	phpinfo();
?>

Reload the Nginx configuration:

/etc/init.d/nginx reload

If you like my work or if my work has been useful to you in any way, then feel free to donate me a cup of coffee. Any donation is much appreciated!