This tutorial will show you how to configure wordpress in nginx server in 10 steps
Step: 1
First of all we update our server, this command used to update the package lists on your instance server
sudo apt-get update
Step: 2
Putting a command on a single line is all it takes to install NGINX in Ubuntu
sudo apt-get install nginx -y
We check our nginx status
sudo systemctl status nginx
Here shows this in our server
Step: 3
You must set up PHP as well as the PHP-FPM service because WordPress is a PHP application. Because Nginx does not allow native PHP processing like some other web servers do, we must install php-fpm, also referred to as the fast CGI process manager. To process PHP requests, Nginx will be told to route them to this application.
sudo apt-get install php-fpm php-mysql -y
Step: 4
Install mysql to manage our database
sudo apt-get install mysql-server -y
you can test if installation has worked by checking the status
Step: 5
Create mysql user and database for our wordpress
Mysql login command:
sudo mysql -u root -p
Create a database for our wordpress:
CREATE DATABASE wordpress DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
create a user for our database:
CREATE USER ‘wordpressuser’@’localhost’ IDENTIFIED BY ‘password’;
This mysql command allows users to grant their privileges to other users.
GRANT ALL PRIVILEGES ON wordpress.* TO ‘wordpressuser’@’localhost’;
FLUSH PRIVILEGES instructs TiDB to reload the in-memory copy of privileges from the privilege tables
FLUSH PRIVILEGES;
Exit out of mysql
Exit
Step: 6
The next step is to set up Nginx to operate with PHP.
sudo nano /etc/nginx/sites-available/default
Find the index line in the server block, then add index.php to the list of files. Additionally, search for the server_name directive and change its value to the public IP address or domain name of your server.
Look for the try_files directive in the location / block and substitute the following line:
try_files $uri $uri/ /index.php$is_args$args;
inside the server block, add the location .php$ block :
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.4-fpm.sock; }
Save the document, then exit. If everything is in order, check the Nginx configuration and restart the Nginx service:
sudo systemctl restart nginx
sudo nginx -t
Step: 7
You should first download the compressed WordPress file from the /tmp directory:
cd /tmp
WordPress can now be downloaded and installed IN ZIP file format.
curl -LO https://wordpress.org/latest.tar.gz
Unzip the file:
tar xzvf latest.tar.gz
Move the file to your Nginx document root
sudo cp -a /tmp/wordpress/. /var/www/html
Step: 8
Access to the wp-config.php configuration file is required by WordPress. By copying from a model file, you can create this file even though it doesn’t by default exist:
cd /var/www/html
sudo cp wp-config-sample.php wp-config.php
Open the wordpress configure file
sudo nano wp-config.php
Locate the section containing the database connection settings, and then change the values for DB_NAME, DB_USER, and DB_PASSWORD to reflect the particulars of the database you made:
define(‘DB_NAME’, ‘wordpress’);
define(‘DB_USER’, ‘wordpressuser’);
define(‘DB_PASSWORD’, ‘password’);
Save and close the file.
And now we refresh the page
Step: 9 (Allow uploads of images and attachments)
Changing the permissions for the ‘wp-content’ folder and related files may be necessary if you’re having trouble uploading photos or attachments. Additionally, this will guarantee proper protection against unauthorized access. How to do it is as follows:
sudo chmod -R 755 wp-content
sudo chmod -R 644 wp-content/*
Step : 10 (Allow upload of plugins)
This step is not required. There might be a password requirement preventing you from uploading plugins through /wp-admin. You can take these steps to disable this requirement if you want to:
define(‘FS_METHOD’, ‘direct’);