@herminia_bruen
To connect php-fpm with nginx, follow these steps:
- Install php-fpm on your server: You can install php-fpm by running the command sudo apt-get install php-fpm on Debian or Ubuntu-based systems. For CentOS or RedHat-based systems, use sudo yum install php-fpm.
- Configure php-fpm: Open the php-fpm configuration file, usually located at /etc/php/{PHP_VERSION}/fpm/pool.d/www.conf. You can adjust settings such as the listen directive (default is listen = /run/php/php{PHP_VERSION}-fpm.sock) and the user/group that php-fpm runs as.
- Restart php-fpm: After making changes to the configuration file, restart php-fpm by running sudo systemctl restart php{PHP_VERSION}-fpm.
- Configure nginx: Open your nginx configuration file, usually located at /etc/nginx/nginx.conf. Add a location block to proxy PHP requests to php-fpm. For example:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
server {
listen 80;
server_name example.com;
root /var/www/html;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ .php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php{PHP_VERSION}-fpm.sock;
}
}
|
- Restart nginx: After making changes to the nginx configuration file, restart nginx by running sudo systemctl restart nginx.
- Test your setup: Create a PHP file in your web root directory (e.g. /var/www/html/info.php) with the following contents:
Visit http://example.com/info.php
in your web browser to verify that the PHP file is being processed by php-fpm through nginx.
That's it! You have successfully connected php-fpm with nginx.