For students and new users, the steps below will show them how to set up WordPress with Nginx and FastCGI to perform faster even with a single server. If you want to improve your WordPress site performance, you should install the Nginx HTTP server and enable FastCGI caching. Doing this will greatly improve WordPress performance. This brief tutorial is going to show students and new users how to install the Nginx HTTP server and enable FastCGI on Ubuntu 16.04 LTS with PHP 7.2-FPM. When you combine the Nginx web server and FastCGI module, you will greatly improve your PHP-based applications, including WordPress websites. FastCGI module caches dynamic PHP content that is served through the Nginx backend. When dynamic PHP content is cached, repeated requests for the same content are quickly returned from the cache store, instead of compiling all the dynamic data that make up the page each time a request is made. So, when you’re running a website or blog powered by Nginx, make sure to include FastCGI caching.

Install Nginx Latest Version

First, install Nginx from the Ubuntu default repository. This will install a stable version of the Nginx HTTP server. However, if you want to install or upgrade to the latest version of Nginx, then run the commands below. After adding the key, run the commands below to install Nginx’s Mainline repository or branch on Ubuntu. When you’re done, all you need to do is run the commands below to install the latest version of Nginx. The commands above will upgrade to the latest version of the Nginx HTTP server. After installing Nginx, the commands below can be used to stop, start and enable the Nginx service to always start up with the server boots.

PHP 7.2 may not be available on Ubuntu default repositories… to install it, you will have to get it from third-party repositories. Run the commands below to add the below third party repository to upgrade to PHP 7.2-FPM Then update Ubuntu by running the commands below. Then run the commands below to install PHP 7.2-FPM and related modules. After installing PHP 7.2-FPM, run the commands below to open PHP 7.2-FPM default file. Then make the changes on the following lines below in the file and save. The value below is a great setting to apply in your environment. After installing and updating, the commands below can be used to stop, start and enable PHP 7.2-FPM to always startup when the server boots.

Setup FastCGI Directive in Nginx.conf file.

On Ubuntu systems, Nginx configuration files are stored in the /etc/Nginx directory. In that directory, Nginx’s main configuration file called Nginx.conf is also stored in there. In that file is where you set up Nginx global configurations. In Nginx main configuration file at /etc/nginx/nginx.conf, place the block of code before the last line in the file and save. Run the commands below to open the file. Then copy and paste the block of lines below into the file and save. then close out Save the file when done.

Setup FastCGI Directive in Nginx Web config file.

On Ubuntu systems, Nginx individual website configuration files or virtual host files are stored in /etc/nginx/sites-available/ That is where you store your website configurations. There should already be a default configuration file there. When implementing FastCGI for a website, open the site configuration file and edit the PHP block as shown below. Run the commands below to open the default site configuration file. Then make the PHP block look like the one below and save. Save the file when you’re done. If everything is set up correctly, PHP should be going through FastCGI module and caching enabled. For the WordPress website, you should also include the block of code below in the site configuration file, just above the location ~.php$ block. Save the file and you’re done. Reload Nginx and you’re done. This is how to enable FastCGI support for Nginx it’s the best setting that we have and that works on all our sites. It’s great. you should try it. You may also like the post below: