Nginx with PHP

== PHP8.2 Installation ==
PHP packages is available in the Alpine Linux repositories. To install php8.2 with modules run:
Perhaps you do not need all these PHP modules. Install modules according to your needs.
=== Configuration of PHP8.2 ===
Defining ENV variables which will be used in configuration. You can do this e.g. in /etc/profile.d/php82.sh.
Modify variables according to your needs.
Modifying configuration file www.conf
Modifying configuration file php.ini
To add PHP support to Nginx we should modify Nginx configuration file:
user www;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx/nginx.pid;
events {
 worker_connections 1024;
}
http {
 include /etc/nginx/mime.types;
 default_type application/octet-stream;
 sendfile on;
 access_log /var/log/nginx/access.log;
 keepalive_timeout 3000;
 server {
 listen 80;
 root /www;
 index index.php index.html index.htm;
 server_name localhost;
 client_max_body_size 32m;
 error_page 500 502 503 504 /50x.html;
 location = /50x.html {
 root /var/lib/nginx/html;
 }
 location ~ \.php$ {
 fastcgi_pass 127.0.0.1:9000;
 fastcgi_index index.php;
 include fastcgi.conf;
 }
 }
}
In our configuration we have line: "fastcgi_pass 127.0.0.1:9000" 
It should be corresponing to the line "listen = 127.0.0.1:9000" in PHP configuration file /etc/php82/php-fpm.d/www.conf
=== Timezone ===
For configuring Timezone you may use tzdata package which can be installed by running:
Timezone configuration
=== Sample PHP page ===
<?php
	phpinfo();
?>
=== Starting Nginx with PHP82 ===
Nginx should be restarted because we have changed it's configuration. Restart it by running:
After the installation PHP is not running. Start it by running:
=== Runlevel ===
Normally you want to start the web server when the system is launching. This is done by adding Nginx and PHP to the needed runlevel.
Now they should start automatically when you boot your machine next time. To test that run:
To make sure that Nginx and PHP are started run command:
You should get something like this:
 263 root 0:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
 264 www 0:00 nginx: worker process
 291 root 0:00 php-fpm: master process (/etc/php82/php-fpm.conf)
 302 www 0:00 php-fpm: pool www
 303 www 0:00 php-fpm: pool www
 310 root 0:00 grep nginx\|php-fpm
=== Testing Nginx with PHP ===
This section is assuming that nginx is running and sample html page "/www/phpinfo.php" is created. Launch a web browser and point it to 
http://X.X.X.X/phpinfo.php
where X.X.X.X is IP address of your web server
If everything was set up correctly, you should see information about your web server.
=== Troubleshooting ===
If PHP is not started check php-fpm log file
Make sure that configuration files do not contain errors
== PHP7 Installation ==
PHP packages is available in the Alpine Linux repositories. To install php7 with modules run:
Perhaps you do not need all these PHP modules. Install modules according to your needs.
=== Configuration of PHP7 ===
Defining ENV variables which will be used in configuration. You can do this e.g. in /etc/profile.d/php7.sh.
Modify variables according to your needs.
Modifying configuration file www.conf
Modifying configuration file php.ini
To add PHP support to Nginx we should modify Nginx configuration file:
user www;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx/nginx.pid;
events {
 worker_connections 1024;
}
http {
 include /etc/nginx/mime.types;
 default_type application/octet-stream;
 sendfile on;
 access_log /var/log/nginx/access.log;
 keepalive_timeout 3000;
 server {
 listen 80;
 root /www;
 index index.html index.htm index.php;
 server_name localhost;
 client_max_body_size 32m;
 error_page 500 502 503 504 /50x.html;
 location = /50x.html {
 root /var/lib/nginx/html;
 }
 location ~ \.php$ {
 fastcgi_pass 127.0.0.1:9000;
 fastcgi_index index.php;
 include fastcgi.conf;
 }
 }
}
In our configuration we have line: "fastcgi_pass 127.0.0.1:9000" 
It should be corresponing to the line "listen = 127.0.0.1:9000" in PHP configuration file /etc/php7/php-fpm.d/www.conf
=== Timezone ===
For configuring Timezone you may use tzdata package which can be installed by running:
Timezone configuration
=== Sample PHP page ===
<?php
	phpinfo();
?>
=== Starting Nginx with PHP7 ===
Nginx should be restarted because we have changed it's configuration. Restart it by running:
After the installation PHP is not running. Start it by running:
=== Runlevel ===
Normally you want to start the web server when the system is launching. This is done by adding Nginx and PHP to the needed runlevel.
Now they should start automatically when you boot your machine next time. To test that run:
To make sure that Nginx and PHP are started run command:
You should get something like this:
 263 root 0:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
 264 www 0:00 nginx: worker process
 291 root 0:00 php-fpm: master process (/etc/php7/php-fpm.conf)
 302 www 0:00 php-fpm: pool www
 303 www 0:00 php-fpm: pool www
 310 root 0:00 grep nginx\|php-fpm
=== Testing Nginx with PHP ===
This section is assuming that nginx is running and sample html page "/www/phpinfo.php" is created. Launch a web browser and point it to 
http://X.X.X.X/phpinfo.php
where X.X.X.X is IP address of your web server
If everything was set up correctly, you should see information about your web server.
=== Troubleshooting ===
If PHP is not started check php-fpm log file
Make sure that configuration files do not contain errors
== PHP5 Installation ==
PHP packages is available in the Alpine Linux repositories. To install php5 with modules run:
Perhaps you do not need all these PHP modules. Install modules according to your needs.
=== Configuration of PHP5 ===
Defining ENV variables which will be used in configuration. You can do this e.g. in /etc/profile.d/php5.sh.
Modify variables according to your needs.
Modifying configuration file php-fpm.conf
Modifying configuration file php.ini
To add PHP support to Nginx we should modify Nginx configuration file:
user www;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx/nginx.pid;
events {
 worker_connections 1024;
}
http {
 include /etc/nginx/mime.types;
 default_type application/octet-stream;
 sendfile on;
 access_log /var/log/nginx/access.log;
 keepalive_timeout 3000;
 server {
 listen 80;
 root /www;
 index index.html index.htm index.php;
 server_name localhost;
 client_max_body_size 32m;
 error_page 500 502 503 504 /50x.html;
 location = /50x.html {
 root /var/lib/nginx/html;
 }
 location ~ \.php$ {
 fastcgi_pass 127.0.0.1:9000;
 fastcgi_index index.php;
 include fastcgi.conf;
 }
 }
}
In our configuration we have line: "fastcgi_pass 127.0.0.1:9000" 
It should be corresponing to the line "listen = 127.0.0.1:9000" in PHP configuration file /etc/php5/php-fpm.conf
=== Timezone ===
For configuring Timezone you may use tzdata package which can be installed by running:
Timezone configuration
=== Sample PHP page ===
<?php
	phpinfo();
?>
=== Starting Nginx with PHP5 ===
Nginx should be restarted because we have changed it's configuration. Restart it by running:
After the installation PHP is not running. Start it by running:
=== Runlevel ===
Normally you want to start the web server when the system is launching. This is done by adding Nginx and PHP to the needed runlevel.
Now they should start automatically when you boot your machine next time. To test that run:
To make sure that Nginx and PHP are started run command:
You should get something like this:
 263 root 0:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
 264 www 0:00 nginx: worker process
 291 root 0:00 php-fpm: master process (/etc/php5/php-fpm.conf)
 302 www 0:00 php-fpm: pool www
 303 www 0:00 php-fpm: pool www
 310 root 0:00 grep nginx\|php-fpm
=== Testing Nginx with PHP ===
This section is assuming that nginx is running and sample html page "/www/phpinfo.php" is created. Launch a web browser and point it to 
http://X.X.X.X/phpinfo.php
where X.X.X.X is IP address of your web server
If everything was set up correctly, you should see information about your web server.
=== Troubleshooting ===
If PHP is not started check php-fpm log file
Make sure that configuration files do not contain errors
Category:Web Server
Category:PHP