Set Up the Web Server


Set Up the Web Server

Now that we have verified that our web server can access the WordPress database, we need to actually make this a web server by configuring Nginx, PHP and the necessary components.

Since you updated your package index to run the test above, we don’t need to do that again. Let’s install all of the packages we need:


When everything is installed, you can begin configuring the software.

Configure PHP

Let’s begin with PHP since that is quite easy.

Open the PHP configuration file for php-fpm, which will handle our dynamic content. We just need to modify one value in this:


Search for the cgi.fix_pathinfo parameter. It will likely be commented out with the “;” character and set to “1”. We need to reverse both of these conditions by uncommenting the line and setting it to “0”:


Set Up the Web Server


This is a security measure. By setting this option, we tell PHP not to try to guess the file that the user was trying to access if an exact match is not found. If we didn’t set this, a malicious user could take advantage of this opportunity and get our server to execute code that we don’t want it to.

Save and close the file when you are finished.

Next, we’ll need to open another file to modify how our PHP processor and web server communicate:


Look for the listen directive, which should be set to Rather than using a port, we’re going to set this to a unix domain socket:


Save and close the file when you are finished.

Now that we have our values, restart our PHP processor:


Configure Nginx

Now we’re ready to configure Nginx. We can start by copying the default virtual host file to a new file that we can work with. We’ll name this after the domain of our site. I’m going to use the placeholder “”:


Now, open the file we just copied over:


Inside, we’ll modify our server block (the sections contained within the server brackets). Begin by uncommenting the directive to listen to port 80. We’re also going to change the root directory and make Nginx serve a PHP index file by default:


Next, we’ll modify the server_name directive to use our domain name, ensure that our try_files is set up correctly (passing requests to PHP if no files are found) and that our error pages are configured:


Finally, we need to set up the actual PHP processing by using a location block that will match all of our PHP requests. We will immediately return a 404 if an exact match is not found. We’ll also use the socket we configured for PHP:


This is the end of our server block configuration. Save and close the file.

Now, we link this to our “enabled” directory and remove the link for the default server block file:


Restart Nginx to make these changes happen:




About Author

Là một developer rất ham chơi nhưng không ham hố, không ham chơi nhưng rất thích cầm đầu...

Comments are closed.

%d bloggers like this: