Trying to install Wordpress on Subdirectory

Hello, I’ve been trying to install the wordpress on Subdirectory of my website.

Any can guide which steps should i follow to make it work?

I am using ubuntu 22.04 Lts. LEMP is installed.

At the moment i am following these steps: 1- created /blog directory on root domain. 2- created a .conf file in /etc/nginx/sites-avaiable with below code

server {
        root /var/www/html/websiterootfolder/blog;
        index index.php index.html index.htm index.nginx-debian.html;

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

        #location /blog {
        #       index index.php index.html index.htm;
        #       try_files $uri $uri/ /index.php?$args;

        location ~ \.php$ {
                include snippets/fastcgi-php.conf;
                fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;

        location ~ /\.ht {
                deny all;

        location = /favicon.ico { log_not_found off; access_log off; }
        location = /robots.txt { log_not_found off; access_log off; allow all; }
        location ~* \.(css|gif|ico|jpeg|jpg|js|png)$ {
                expires max;
                log_not_found off;


3- created database and user 4- Installed PHP extensions 5- restarted apache with this:

sudo systemctl restart apache2;

6- Enabled the /etc/nginx/sites-enabled

Also i followed few tutorials but after that i am getting 404 or 403 errors.

Tutorial i already tried:

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Bobby Iliev
Site Moderator
Site Moderator badge
January 20, 2023

Hi there,

Your website seems to be loading as expected already. Do you have a separate website that is installed in /var/www/yourdomain and should WordPress be only loading for the /blog URL?

If you already have a website setup on that server for this domain name, you would usually not want to add a totally separate Nginx server block but just add the necessary rules for the WordPress installation, for example:

server {
    listen 80;

    location / {
        root /var/www/yoursite;
        index index.php;
        try_files $uri $uri/ /index.php?$args;

    location /blog {
        root /var/www/yoursite/blog;
        index index.php;
        try_files $uri $uri/ /site1/index.php?$args;

    location ~ \.php$ {
        fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;

In this example, requests to will be served from the /var/www/yoursite/blog directory, and requests to will be served from the /var/www/yoursite directory.

An alternative approach is to use a separate Nginx server block with a subdomain like



Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

card icon
Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Sign up
card icon
Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We’d like to help.

Learn more
card icon
Become a contributor

You get paid; we donate to tech nonprofits.

Learn more
Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow – whether you’re running one virtual machine or ten thousand.

Learn more ->
DigitalOcean Cloud Control Panel
Get started for free

Enter your email to get $200 in credit for your first 60 days with DigitalOcean.

New accounts only. By submitting your email you agree to our Privacy Policy.

© 2023 DigitalOcean, LLC.