Reading time: 4 minutes
Running PHP applications is made more solid by pairing Nginx with PHP-FPM, FastCGI Process Manager. It has a smaller environmental impact and is faster and more effective. In this post, you will learn how to enable Nginx with PHP-FPM to run on a Plesk server, allowing your websites to reap the benefits of this combination.
Here are the prerequisites:
A running Plesk server
Root or sudo access to the server
General familiarity with Plesk administration
Before doing any modifications, make sure to check whether your Plesk installation is up to date or not.
1. First, log in to your Plesk control panel
2. Navigate to tools & settings > updates>update components
3. If updates are available, apply them and restart Plesk
Plesk supports Nginx in two modes: As a reverse proxy for Apache ( Apache & Nginx) or as an individual web server (Nginx only). We will concentrate on using Nginx as a reverse proxy:
1. In Plesk, go to Tools & Settings>Server Settings>Web Server
2. Under “Web server mode, “select” Apache & Nginx reverse proxy mode.”
3. Now, click Apply to save the changes.
Now, set up PHP-FPM
1. Go to the Tools & Settings > PHP Settings
2. Click on the PHP versions tab
3. For each PHP version you want to use with FPM
Click on the version number
In the handler dropdown, select FPM application
To use Nginx with PHP-FPM for individual domains:
1. Visit the websites & domains and choose the desired domain
2. Click on “Hosting Settings.”
3. Set the web server to Nginx and Apache
4. For “PHP support, pick the PHP-FPM application server
5. Consider the desired PHP version
6. Now, click OK to apply the changes.
For optimal performance, do the following adjustments:
After making configuration changes:
1. Go to Tools & Settings > Server Management > Services Management.
2. Restart the following services:
- Nginx
- Apache
- PHP-FPM (for each version you've modified)
To ensure Nginx and PHP-FPM are working correctly:
1. Create a test PHP file (e.g., info.php) in your domain's document root with the following content:
<?php
// Show all information, defaults to INFO_ALL
phpinfo();
// Show just the module information.
// phpinfo(8) yields identical results.
phpinfo(INFO_MODULES);
?>
2. Access this file through your browser
3. Check that the "Server API" field shows "FPM/FastCGI."
In case you face any issues, try the following:
1. Check Plesk logs:
- Go to Tools & Settings > Server Management > Logs.
- Review Nginx, Apache, and PHP-FPM logs for errors.
2. Verify PHP-FPM processes:
- Connect to your server via SSH.
- Run: `ps aux | grep php-fpm` to ensure PHP-FPM processes are running.
3. Test Nginx configuration:
- In SSH, run: `nginx -t`
- This will check for syntax errors in the Nginx configuration.
4. Restart services:
- If you've made manual changes, restart Nginx, Apache, and PHP-FPM services as described in Step 6.
Thus, shifting to Nginx with PHP-FPM on Plesk can improve website performance along with sparing server resources. This guide will assist you in building a solid web-serving stack, created for effectively handling heavy traffic. Be mindful of your setup, adjust as required, and regularly update your system for maximum performance and safety.