Get PHP-FPM support for your NGINX site in 3 easy steps!

0
Get PHP-FPM support for your NGINX site in 3 easy steps!

With NGINX, you can increase the speed of your website with just a few configuration lines. But if you also have PHP-FPM support enabled on your server, these configuration lines will enable it as well – automatically! In this guide, we’ll show you how to add PHP-FPM support for your NGINX site in 3 easy steps!

Step 1. Prepare our system

Before we can add PHP-FPM support to our NGINX web server, we need to make sure that our system is properly prepared. We’ll need to install a few dependencies, create a new user and group for PHP-FPM, and configure our firewall. Let’s get started! Step 2. Add the php-fpm package:

Next, let’s download and install the latest version of the php-fpm package from Debian or Ubuntu repositories with apt: sudo apt-get update && sudo apt-get -y install php5-fpm \ echo user = apache >> /etc/php5/mods-available/apache2.ini \ echo group = apache >> /etc/php5/mods-available/apache2.ini \ mkdir -p /var/run/php5-fpm && chown apache:apache /var/run/php5-fpm \ echo ‘;’ > /etc/nginx/sites-enabled/default && sed -i ‘s/#user nobody;/user apache;’ /etc/nginx/sites-enabled/default \ sed -i ‘s/#group nobody;/group apache;’ /etc/nginx/sites-enabled/default \ sed -i ‘s/#user nobody;/user apache;’ /etc/nginx/sites-enabled/default\ sed -i ‘s/#group nobody;/group apache;’

  • Make sure that any sites you want to use with PHP are configured as follows: location ~ \.php$ { root html ; fastcgi_pass unix:/var/run/php5-fpm.sock ; fastcgi_index index.php ; include fastcgi_params ; }
  •  Restart Nginx: service nginx restart
  •  Confirm installation by checking the status of PHP FastCGI Process Manager (FPM): ps aux grep php

Step 2. Install FPM

To install FPM on your server, you’ll first need to SSH into the server as the root user. Then, run the following command apt-get update && apt-get install php5 libapache2-mod-php5 php5-fpm . You should also consider installing Apache’s MPM module for PHP via: apt-get install libapache2-mod-php5 . Once this is done, restart Apache with service apache2 restart .

That’s it, now you have a site running with PHP-FPM installed and enabled. To confirm that everything was configured correctly, take a look at /var/log/php5-fpm.log to see if there are any errors or warnings reported by PHP-FPM which can help you diagnose the problem and fix it if necessary. If all went well, you will see something like this in the log file: the process manager can manage 2192 children. There are no children currently alive, so the number of requests that can be handled simultaneously is 8248 (assuming 10 seconds per request).

The current limit on requests per second is 8248; however, we have set it to 0 so this number doesn’t affect our benchmark. In addition, there is an error log with live updates available at http://localhost:9000/php-fpm.html, which lists stats about each active PHP-FPM instance. For example, this page might tell you how many total requests were processed by all instances since the last status update, the total memory usage of these instances, etc. It can provide valuable information about your server performance when troubleshooting issues with high CPU utilization or high memory usage.

Step 3. Configure NGINX

  1. Find the ‘server’ block in your NGINX configuration file that contains the directives for your website. If you don’t have a server block already, you’ll need to create one.
  2. Add the following lines to the server block:

proxy_set_header X-Real-IP $remote_addr;

proxy_set_header X-Forwarded-For $remote_addr;

  1. Save and close the file. That’s it! You’re done! You can now start using PHP-FPM on your site.
  2. To make sure everything is working correctly, restart the webserver by running sudo service nginx restart or sudo systemctl restart nginx .
  3. Verify by running curl -i localhost and looking at the response headers (the first line should say X-Powered-By: PHP/7.0).

Leave a Reply

Your email address will not be published. Required fields are marked *