Cloud Service >> Knowledgebase >> Plesk >> How To Enable Nginx With PHP-FPM On Plesk?
submit query

Cut Hosting Costs! Submit Query Today!

How To Enable Nginx With PHP-FPM On Plesk?

Pairing Nginx with PHP-FPM (FastCGI Process Manage­r) gives a power boost when it come­s to running PHP applications. It's faster, more efficie­nt, and leaves a smaller footprint. This guide­? It's your map to getting Nginx and PHP-FPM up and running on a Plesk serve­r, helping your websites re­ap the rewards of this powerful combo.

Prerequisites:

- A server running Plesk

- Root or sudo access to the server

- Basic familiarity with Plesk administration

Step 1: Update Plesk

Before making any changes, ensure your Plesk installation is up to date:

1. 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.

Step 2: Enable Nginx Support

Plesk supports Nginx in two modes: as a reverse proxy for Apache (Apache & Nginx) or as a standalone web server (Nginx only). We'll focus on enabling 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. Click "Apply" to save the changes.

Step 3: Configure PHP-FPM


Now, let's set up PHP-FPM:

1. Go to Tools & Settings > PHP Settings.

2. Click on the "PHP Versions" tab.

3. For each PHP version you want to use with FPM:

   a. Click on the version number.

   b. In the "Handler" dropdown, select "FPM application".

  c. Click "OK" to save.

Step 4: Enable Nginx and PHP-FPM for Specific Domains

To use Nginx with PHP-FPM for individual domains:

1. Go to Websites & Domains and select the desired domain.

2. Click on "Hosting Settings."

3. Set "Web server" to "Nginx and Apache (reverse proxy)."

4. For "PHP support," choose "PHP-FPM application server."

5. Select the desired PHP version.

6. Click "OK" to apply the changes.

Step 5: Optimize Nginx and PHP-FPM Configuration

For optimal performance, consider the following adjustments:

1. Nginx Configuration:

   - Go to Tools & Settings > Server Settings > Web Server Settings.

   - Click on the "Additional nginx directives" tab.

   - Add performance-enhancing directives, such as:

     ```

     client_max_body_size 50M;

     client_body_buffer_size 128k;

    ```

2. PHP-FPM Configuration:

   - Go to Tools & Settings > PHP Settings.

   - Click on the "Additional directives" tab for the desired PHP version.

   - Add optimizations like:

     ```

     pm = dynamic

     pm.max_children = 50

     pm.start_servers = 5

     pm.min_spare_servers = 5

     pm.max_spare_servers = 35

    ```

   Adjust these values based on your server's resources and traffic patterns.

Step 6: Restart Services

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)

Step 7: Verify the Configuration

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

   

   ```

2. Access this file through your browser (e.g., http://yourdomain.com/info.php).

3. Check that the "Server API" field shows "FPM/FastCGI."

Troubleshooting:

If you encounter 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.

Best Practices:

1. Monitor resource usage:

   - Regularly check CPU, memory, and disk usage to ensure your configuration is efficient.

  - Adjust PHP-FPM pool settings if needed.

2. Keep software updated:

  - Regularly update Plesk, Nginx, Apache, and PHP to benefit from security patches and performance improvements.

3. Use caching:

   - Implement Nginx caching for static content to reduce server load.

  - Consider using PHP opcode caching (e.g., OPcache) for improved PHP performance.

4. Secure your setup:

   - Implement SSL/TLS for all domains.

  - Use Plesk's security features like fail2ban and ModSecurity.

5. Regular backups:

  - Always back up your Plesk configuration and website data before making significant changes.

Conclusion:

Switching on Nginx with PHP-FPM on Plesk can e­scalate website pe­rformance along with sparing server re­sources. This guide has lent a hand in building a robust we­b-serving stack, designed for e­ffectively managing heavy traffic. Be­ mindful of your setup, adjust as neede­d, and regularly update your system for max pe­rformance and safety.

 

Cut Hosting Costs! Submit Query Today!

Grow With Us

Let’s talk about the future, and make it happen!