In this blog we will see how to properly configure Nginx and php-fpm in a linux (ubuntu) machine or server (These links help you to know basics and to operate Nginx).
Here are some articles and blogs and links that will help you to learn and know more about these.
https://nginx.org/en/docs/beginners_guide.html
https://nginx.org/en/docs/switches.html
https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/
https://www.nginx.com/resources/wiki/start/topics/depth/ifisevil/
https://easyengine.io/wordpress-nginx/why-nginx/
https://serverguy.com/comparison/apache-vs-nginx/
http://nginx.org/en/docs/http/ngx_http_core_module.html
Pre-Requisites:
Linux (Ubuntu) Server.
Php.
Nginx.
Considering that the linux server is already setup and running with ubuntu, lets get started with the Nginx and php fpm setup.
Installing the necessary softwares.
You can follow THIS link and install Nginx and follow THIS link and install PHP.
Basic Nginx (V 1.24) Setup for PHP-FPM (8.1)
server {
...
# Add index.php nginx config
index ... index.php ...;
# Pass PHP scripts on Nginx to FastCGI (PHP-FPM) server
location ~ \.php$ {
include fastcgi_params;
# Nginx php-fpm sock config:
fastcgi_pass unix:/run/php/php8.1-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
# deny access to Apache .htaccess on Nginx with PHP,
# if Apache and Nginx document roots concur
location ~ /\.ht {
deny all;
}
...
} # End of PHP FPM Nginx config example
This is just a example config snippet and not the whole/actual configuration.
Depending on your system’s default configuration you may need to change fastcgi_pass
parameter.
It can be of the following variation
fastcgi_pass 127.0.0.1:9000; # For locally passing the php files
fastcgi_pass unix:/run/php/php8.1-fpm.sock; # For using unix socket to pass the file
unix socket location may vary per system (can be /run/php/php8.1-fpm.sock /var/run/php/php8.1-fpm.sock). This doesnt make a difference if the locations are symlinked or mounted. If incase it is not done then this needed to be noted carefully.
Another way is to change the phpfpm pool.d/www.conf file to use local host instead of unix socket.
Finally restart the php and nginx services.
Leave a Reply
You must be logged in to post a comment.