What is WordPress?

WordPress is a content Management software (CMS) based on PHP and MySQL.

It allows you to easily create and manage Blogs and Websites.

In this article, We will focus on how to install wordpress with nginx on Ubuntu Operating systems.


We will need an Ubuntu OS in order to continue with this article.

If you don’t have one, Create a EC2 instance using the below articles,

Create AWS EC2 instance from Console

How to create EC2 Instance using Terraform

  • you must have a sudo access to the instance.
  • Install LEMP stack which fulfills the requirements of creating WordPress website.

Installing Nginx Webserver:

WordPress requires a web server to funtion and Nginx is the most popular open source software for web serving, caching , load balancing and reverse proxying.

Lets go ahead and install nginx on the ubuntu instance using the below command:

apt-get install nginx

next , Run the below commands to start and active the nginx to run on system reboot.

systemctl start nginx
systemctl enable nginx

To check the status of nginx,

systemctl status nginx

Installing MySQL Database:

WordPress requires a database as well in order to function , So lets install mysql packages in the ubuntu server using the below command,

sudo apt-get install mysql-server

To setup password the root user in Mysql,


When prompted, Answer the below questions ,

  • Enter the current password for root : Just press Enter
  • Set root password ? : Yes
  • New Password : set password
  • Re-enter new Password : repeat the password
  • Remove anonymous users ? : Y
  • Disallow root login remotely ? : Y
  • Remove test database and access to it ? : Y
  • Reload privilege table now ? : Y

All done!

Now start the MySQL service and enable it to run on reboot:

systemctl start mysql
systemctl enable mysql

Check the status of the MySQL service,


Installing PHP and Related Modules:

When setting up wordpress site , We need a modules to be installed in order to make wordpress function properly and communicate with the Database server.

Lets install the php packages and its extensions,

apt install php-fpm php-curl php-gd php-intl php-mbstring php-soap php-xml php-xmlrpc php-zip

once the installation of PHP modules and its extensions, Lets start the php-fpm process so that PHP processes can utilize the newly installed extensions.

systemctl restart php7.4-fpm

php7.4-fpm – based on the PHP version change the version.

Now that we have all the necessary packages and modules installed in the server for the WordPress site to work properly.

Creating database for WordPress:

We have to create a database for the wordpress site.

Login to the MySQL database using the below command,

sudo mysql -uroot -p

type then password when prompted.

Create a database called wordpress,

create database wordpress;

Create a database user named worduser with password,

create user 'worduser'@'localhost' identified by 'newpasswordhere';

Then grant full access for USER: worduser to DB: wordpress,

grant all on wordpress.* to 'worduser'@'localhost' identified by 'userpasswordhere';

Saving changes and exit the database,

flush privileges;

Downloading WordPress Latest Release:

Visit the wordpress official website to download the latest package of wordpress.


After downloading run the below commands to extract the package and setup a root directory for wordpress files.

cd /opt && wget https://wordpress.org/latest.tar.gz
tar -xvzf wordpress-5.3.2.tar.gz
mv wordpress /var/www/html

We have to set the correct permissions and ownership for the wordpress folder for the wordpress to function;

sudo chown -R www-data:www-data /var/www/html/wordpress/ 
sudo chmod -R 755 /var/www/html/wordpress/ 

Configuring Nginx for WordPress:

We need to create a new configuration file for wordpress.

Go to this directory and create a new config file,

cd /etc/nginx/sites-available/
nano wordpress.conf

Add the below configuration into the file , Save and close it.

server {
root /var/www/html/wordpress;
index index.php index.html index.htm;
server_name example.com www.example.com;

client_max_body_size 100M;

location / {
try_files $uri $uri/ /index.php?$args;

location ~ .php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;


To check whether the nginx configuration is correct using the below command,

nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Enabling the WordPress Site:

After setting up the Virtual host , We need to enable the site by running the below command,

cd /etc/nginx/sites-enabled/
ln -sf /etc/nginx/sites-available/wordpress.conf

Once the nginx setup is completed, restart the nginx service and activate it on start start-up.

systemctl start nginx
systemctl enable nginx

To Check the status of Nginx,

systemctl status nginx

Configuring WordPress:

Now we have to create a wordpress config file,

Go the wordpress root directory and run the below command,

cd /vaw/www/html/wordpress/
mv wp-config-sample.php wp-config.php
nano wp-config.php

Change the highlighted texts with the username and password which you have created.

// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define( 'DB_NAME', 'database_name_here' );

/** MySQL database username */
define( 'DB_USER', 'username_here' );

/** MySQL database password */
define( 'DB_PASSWORD', 'password_here' );

/** MySQL hostname */
define( 'DB_HOST', 'localhost' );

/** Database Charset to use in creating database tables. */
define( 'DB_CHARSET', 'utf8mb4' );

/** The Database Collate type. Don't change this if in doubt. */
define( 'DB_COLLATE', '' );

Save and close the file.

After that Go to the browser, type the domain name which you have configured in the nginx.

You should see the WordPress setup page to complete the installation.

It will ask for few details such as email id, Db username password , pass them correctly.

Please follow the wizard carefully, You should see the wordpress admin panel.


From here, You manage themes, plugin and much more..

Congratulations , Now, You know how to setup a wordpress website on you own.

Thanks for reading this article. Please do Check out my other articles,