How to install WordPress in a subdomain on Cloud Servers with Nginx

2022-05-03 By Nathan 2581 Views wordpress nginx subdomain
7 reviews

WordPress, one of the most popular content management and blog platforms, is a free open-source CMS software, that allows to create and manage a vast variety of website content efficiently.


This tutorial explains how to install WordPress in a subdomain for eg: support.layerstacksupport.com with Nginx. The tutorial assumes the server is already equipped with the following:

  • Server installed with Nginx, PHP and MySQL

  • Root access to the server

  • Subdomain created and pointed to the server


Now, as part of installing WordPress to a subdomain, we start with creating and setting up Database for the subdomain.

  1. Log in to MySQL and create a new database for the subdomain.

    # mysql
    
    MariaDB > CREATE DATABASE supportdb;
    

    wordpresssubdomain1

  2. Grant the privileges to the newly created database and assign them with a strong password.

    Mariadb > grant all privileges on supportdb.* TO ‘wpuser’@’localhost’ identified by ‘mypassword’
    

    wordpresssubdomain2

  3. Refresh the privileges and rules set to the database using the command.

    Mariadb > FLUSH PRIVILEGES;
    

    wordpresssubdomain3

Once done, it is okay to leave the MySQL command line by exit command.


The next stage is to install WordPress to the subdomain pointed, and follow the steps for installation.


  1. Create a directory for the subdomain and download the WordPress and then extract the archive files.

    # mkdir /var/www/support.layerstacksupport.com  
    # cd /var/www/support.layerstacksupport.com  
    # wget http://wordpress.org/latest.tar.gz
    

    wordpresssubdomain4

  2. After extracting the files, copy the files inside the created directory.

    # tar –xzf latest.tar.gz  
    # mv wordpress/* .
    # chown –R www-data:www-data .
    

    wordpresssubdomain5


After setting up the WordPress files, it is required to set the Nginx configuration. Now, the permission has to be set correctly, and now setting the Nginx configuration for the website.


  1. Create a new file in location /etc/nginx/sites-available.

    # cd /etc/nginx/sites-available
    
    # touch support.layerstacksupport.com.conf  
    

    wordpresssubdomain6

  2. Copy below the Nginx configuration and save it in the file support.layerstacksupport.com.conf.

    server {
    server_name support.layerstacksupport.com www.support.layerstacksupport.com;
    access_log /var/log/nginx/support.layerstacksupport.com.access.log rt_cache;
    error_log /var/log/nginx/support.layerstacksupport.com.error.log;
    root /var/www/support.layerstacksupport.com;
    index index.php index.html index.htm;
    include common/php74.conf;
    include common/wpcommon-php74.conf;
    include common/locations-wo.conf;
    include /var/www/support.layerstacksupport.com/conf/nginx/*.conf;
    }
    
  3. After saving the configuration file, please check the Nginx syntax if it is correct.

    # nginx -t
    

    wordpresssubdomain7


    Now, create a symlink by activating the Nginx server block by linking it to the /etc/nginx/sites-enabled using the below command:

    # ln –s /etc/nginx/sites-available/support.layerstacksupport.com.conf /etc/nginx/sites-enabled/support.layerstacksupport.com.conf
    

    wordpresssubdomain8

  4. After the above changes, the configuration is to be refreshed, therefore we restart both the Nginx and PHP processes:

    # systemctl restart nginx.service
    
    # systemctl restart php7.4-fpm.service
    

    wordpresssubdomain9


Finally, the WordPress installation phase. Now, log in to the subdomain, and proceed with the installation:

wordpresssubdomain10

  1. Click on Run the installation and proceed further and select the Language and proceed further.

    wordpresssubdomain11

  2. Go ahead and click on Continue.

    wordpresssubdomain12

  3. Click on Let’s go and this will continue with the installation wizard of WordPress, enter the database details and make sure the Database host is localhost.

    Note: The database details are the same ones that are used when creating the database:

    wordpresssubdomain13

  4. Once filling in the details, click on Submit and the Site Title and WordPress login details are to be entered.

    wordpresssubdomain14

  5. Click the Install WordPress and the final step for the installation is done, you can log in using the above username and password.

    wordpresssubdomain15


The installation of WordPress has concluded. Once the above steps are correct, you would be able to view the WordPress dashboard.


Related Tutorials

What do you think about this article?

Rate this article
LayerStack Promotion
Need assistance?

Try this guide to receive free bundled services at signup on a new free account.

Sign Up

Your Feedback Is Important

We hope you’ll give the new products and updates a try. If you have an idea for improving our products or want to vote on other user ideas so they get prioritized, please submit your feedback on our Community platform. And if you have any questions, please feel free to ask in the Community or contact our Technical Support team.