How to Install WordPress Within a Subdirectory

Posted on December 31, 2017 by in Tips & Tricks | 21 comments

How to Install WordPress Within a Subdirectory

In some cases, you may want to run multiple websites using a single domain. It may be that you need a test site, or you want to run a separate WordPress install from your main one. Either way, using a subdomain is your best bet. That is, as long as you know how to create one and install the platform on it.

Fortunately, this process is very straightforward. Most hosts enable you to create subdirectories in a matter of minutes, so your new WordPress install should be up and running quickly. In this article, we’ll talk a bit more about subdirectories and when to use them. Then we’ll teach you how to create one and set up WordPress on it. Let’s get started!

What Subdirectories Are (And When You Should Use Them)

A subdirectory is simply another name for a nested folder. For example, if you like to save photos of puppies to your Image folder, you could set up a subdirectory called Dogs inside. The same process applies to WordPress websites.

Technically, nothing is stopping you from using the same WordPress installation to run a website that includes a blog. However, it’s often simpler to use subdirectories to set up different installations when you’re running a massive operation. Here are some other examples of cases where using subdirectories makes sense:

  • You want to run an online store alongside your website. It’s often cleaner to set up a WooCommerce install (or whatever e-commerce plugin you use) in its own subdirectory, to avoid confusion.
  • For multilingual websites. If you want to display your site in multiple languages, it makes sense to create subdirectories for each of them.
  • When you need to use two different Content Management Systems (CMS). For example, if you want to run a website on WordPress, but use Magento for your online store, subdirectories are your friends.
  • As a testing environment. Subdirectories enable you to set up WordPress installations you can use as staging sites using the same domain.

It’s essential to understand the difference between two similar terms: subdirectories and subdomains. They’re not the same, even if they work similarly. You can use subdomains for every scenario we described earlier, but subdirectories are a better option.

The decisive factor here is that search engines recognize subdomains as individual websites. This means they don’t carry over the benefits from your Search Engine Optimization (SEO) work on your original domain. Subdirectories, on the other hand, do benefit from your SEO efforts.

Given this, we wouldn’t recommend using subdomains unless you don’t want those websites to rank in search engines. Testing or staging sites, for example, are situations where SEO doesn’t really matter, so you can use either subdomains or subdirectories. The same goes if you want to use subdomains to run individual websites, which isn’t advisable, considering how cheap it is to buy unique domains.

How to Install WordPress Within a Subdirectory via cPanel (In 2 Steps)

You’ll be pleased to know that installing WordPress to a subdirectory is a simple process. We’ll be showing you how to do this using cPanel, but the steps will be similar regardless of your host’s management panel.

Step #1: Create a Subdirectory

Creating a subdirectory is a fancy way of saying “set up a new folder”, which is something your cPanel enables you to do in a few minutes. First off, log into your cPanel, locate the File Manager button, then click on it:

The cPanel file manager.

Once you’re in, you should see at least one folder that contains your current WordPress installation. You’re going to look for the + Folder button now and click on it, then choose a name for your subdirectory:

Creating a new folder.

Whichever name you choose will become part of your subdirectory’s URL, so keep that in mind. Leave the new folder alone for now and return to your cPanel’s main screen.

Step #2: Install WordPress in Your New Subdirectory

Many hosts now include a one-click setup options for popular CMSs, such as WordPress. There are many different installers available, although in our example, we’re using the Softaculous App Installer. In any case, you’ll need to look for the WordPress icon, and click on it:

The WordPress icon.

On the next screen, click on the Install tab, and you’ll see a handful of fields you need to fill out before the installation begins. Pay particular attention to the top of the screen, which enables you to choose a name for your site and select where to install it:

How to install WordPress within a subdirectory.

You’ll need to select the primary domain for your new WordPress install (if you have more than one), then type the name of your new directory in the In Directory field. The rest of the settings are simple enough. You’ll have to choose an admin username and password, a language for your site, and more. When you’re done, click Install at the bottom of the screen.

Clicking the install button.

When the process is over, you’ll be able to access your new WordPress setup by going to yourwebsite.com/yoursubdirectory.

Your new WordPress website.

Now you can access your dashboard and customize your website as you would in any other case. Any changes you make here won’t affect your primary WordPress setup, so go crazy!

How to Install WordPress Within a Subdirectory Manually Via FTP

If your web host doesn’t provide you with access to a full-fledged control panel, you can always set up a subdirectory and install WordPress via File Transfer Protocol (FTP). You’ll need an FTP client, such as FileZilla, and a set of credentials that should’ve been provided via email when you signed up with your web host. You may also need to bone up on your FTP skills before tacking this method.

First, log into your website via FTP and navigate to the directory including your WordPress root folder (usually named public_html). Now, right-click below that directory and choose the option reading Create directory:

Creating a subdirectory via FTP.

The FTP client will ask you to set a name for your new directory before creating it. Keep in mind – not all web hosts enable you to create subdirectories. If you run into an error at this stage, you probably don’t have the necessary permissions to do so. In this case, you’ll either need to use the cPanel method exclusively, or contact your host for advice.

On the other hand, if you didn’t run into any errors, you can go ahead and install WordPress. First, you’ll need to download the latest version of the CMS from its home page:

Downloading WordPress.

Once complete, unpack the contents of the zipped file within a new directory. That way, they won’t get mixed up with any other files:

A local folder including WordPress' setup files.

Now return to your FTP client and navigate to within the folder where you just placed all those files on the left hand side.  Next, access your new subdirectory on the right side of the client. Select all of the WordPress files within your local folder and drag them to the subdirectory:

Uploading files via FTP.

This will prompt your FTP client to upload copies of all those files to your server, within the subdirectory. Depending on your internet speed, this process might take a while, so sit back.

When the transfers are done, you’ll need to set up a new database for your website before running the WordPress installer script. When complete, go to yourwebsite.com/yoursubdirectory/, which will execute the WordPress installer. During the process, you’ll need to enter your database’s details, including its name, admin username, and password. Without that information, the installation won’t be able to continue.

Conclusion

In most cases, you’ll want to use subdirectories over subdomains. They’re better from an SEO perspective, since they’re recognized as part of your website, and in our opinion they just look better. Plus, creating subdirectories is simple, and you can have as many as you want. For example, if you need to set up a multilingual website, you can quickly create a handful of subdirectories and use one for each language.

There are two ways you can go about setting up WordPress on a subdirectory, and they’re both very straightforward:

  1. Use your cPanel to install WordPress.
  2. Set up the platform manually via FTP.

Do you have any questions about how to install WordPress within a subdirectory? Let’s talk about them in the comments section below!

Article thumbnail image by Rvector / shutterstock.com.

21 Comments

  1. Great information! I am sort of a novice in this area, so I have a question about using the sub-directory as a staging site. How simple is it to switch this over to be the in the main directory once you want your newly redesigned to go live? Or would you just use a re-direct?

    • Note: This is not an advertisement, just a suggestion of a product that I use and know very well.

      WP All-In-One Migration can be used for free for sites up to 512MB and has tons of options for pulling any part of the database and content. You can even do a search and replace on the entire site. It works as a simple import/export system and downloads your site to your computer as a zip file. After that, you just install the same plugin on the site you wish to add your newly made backup to and then import the file that you downloaded to your computer.

      They have multiple different addons for their plugin that will allow you to back up to DropBox, FTP, and many other things. If you need to gain access to larger file sizes you will need to spend between $79 and $180 for the addon of choice that works best for you. I have done this manually for years and love this plugin because it allows me and my clients to make backups and changes with a solid piece of mind that never fails.

      • So does All-in-One Migration take care of the database file too? So could i feasibly export the current active site (that I am going to redesign) and import it into my new ‘staging’ subdirectory. Once all is redesigned, I could then export the files in my subdirectory and then import them back into the main directory? Would I delete all the files in my main directory first? Or will it overright the files properly?

    • I mostly use duplicator plugin and put the files in public html, the database is the one u used before for your sec dir.

      • So right now I have a site that I will redesign. I want to use Extra Theme, (right now it uses “X” theme). So I want to start with a clean install of WordPress, but I want to be able to use all the existing posts, categories and events. What would be the best way to achieve this? Duplicate the entire site, and import it into the new subdirectory? Then change the theme and get rid of any plugins I won’t be using? I didn’t understand what you meant about the database.

  2. SAMEE QUESTTION
    HoW to switch the Testing Site to be the in the main directory or primary domain once you want your newly redesigned to go live?

    • You will need to backup your current site DB from phpmyadmin (or use a plugin to do that), move all files and folders to a new folder (using ftp), in case you would like to switch back to the old site quickly.

      Download your new site and upload to main site via ftp.

      There are four sql statements you will need to run that will go over your new DB and change the url’s of your oldsite to newsite.

      Change DB settings in your new wp-config to reflect your new site’s DB.

      Sounds like a lot of work, but I’ve done it so many times, it’s quite straightforward and flawless 🙂

      Maybe an ET tutorial is in need 🙂

      • Would love it in an ET Tutorial! They have all been so helpful to me! Thanks!

  3. Should be as simple as repointing the domain to the new sub-directory…

  4. Hi there,

    I have transferred a few Divi sites from sub-directories to the root directory following these 2 steps, links below:

    First, you’ll need to move the site (follow the link and video in point 1).

    Secondly, you’ll need to ensure that all image/file links are linking properly to the root domain and not the sub-folder (point 2).

    1. How to Move WordPress from a Sub-folder to the Root Directory: https://www.inmotionhosting.com/support/edu/wordpress/329-move-folders

    (Video Link: https://www.youtube.com/watch?v=ZQL31otQroQ)

    2. Correcting Image Links after Migration (this is done through your CPanel Using phpMyAdmin):
    https://www.inmotionhosting.com/support/edu/wordpress/migrating-wordpress-inmotion-hosting/correct-image-links

    Additionally with Divi, you’ll need to go back to your Theme Options to fix the logo URL manually and maybe some links in your custom CSS if any.

    So if your sub-directory folder name is “newsite”, simply go to the Divi Theme and remove /newsite from the link.
    Old Logo link:
    http://yoursite.com/newsite/wp-content/uploads/2017/12/logo.png

    New Logo link:
    http://yoursite.com/wp-content/uploads/2017/12/logo.png

    As a last note, when updating image links using the method above, the SQL they use says “UPDATE wp_posts”, make sure that wp_posts reflects the _posts that exists in your phpMyAdmin (click on the site database name on the right panel and the scroll down the files on the right panel until you find …_posts), and insert that name into “UPDATE yourdb_posts”

    Generally, the whole process shouldn’t take more than 5 minutes. Make sure you have a backup of course before doing it.

    I hope this helps!

    • John Hughes

      No problem 🙂 Glad you found it helpful.

  5. Could somebody tell me other benefits of isolating them to parts? for example I isolate pages (root), blog (/blog) & woocommerce (/shop).

    1. will it benefit in faster loading? since there’s not gonna be load of plugins in one wp installation now?

    2. I’m using MAILSTER to handle my email campaign. it’s really benefiting those components together. as I install it in ROOT, how can I broadcast to customer who shop with me via woocommerce (/shop) since I separate the system?

    3. Database. Now people can register (if I enable) on root, /blog & /shop now? How to manage them all? Is there a way, all these different subdirectories wp installation can share the same databases (I mean the users registration information)?

  6. To develop locally, what would be better, do it in subdirectories or use WP Multisite?

    Thank you

    • John Hughes

      Hello Enrique. Without knowing the exact setup of your site, we are unable to give you specific advice on this matter. However, our general advice would be to match the format of your own (or your client’s) sites.

  7. Hi

    Thank you for this useful post.

    Is there one way using .httacess to delete the subdirectory from the URL ?

    Sablier

    • John Hughes

      Hello Sablier. Glad you found it useful. In regards to your question, would you be able to provide any further clarification as to what you are trying to do?

  8. Interesting post- something I’ve been wondering about for a long time. When we were in the process of rebuilding our site using WordPress, we placed WordPress in a subdirectory (WP) while the site was being developed. When it was ready, my host “did something” (to .httaccess?) to make it re-direct to the WP folder. When you type in our URL, the “/WP” automatically appears in the address bar.

    Question: The General Setting Tab in WordPress has entries for “WordPress Address (URL)” and “Site Address (URL)”. What do these do? Currently I have set both URLs to include the “/WP” folder. What would happen if I removed the /WP subdirectory from the “Site Address” entry?

    • John Hughes

      Hello Larry. You would add your URL to the Site Address URL section if you want your homepage to be different from your WordPress Installation directory. You can find more information via the following link:

      https://codex.wordpress.org/Giving_WordPress_Its_Own_Directory

      Useful information about changing the site URL can be found here:

      https://codex.wordpress.org/Changing_The_Site_URL

      As far as telling what would happen if you remove the /WP subdirectory, that would depend on your site’s subfolder configuration. Hope this helps 🙂

      • John-
        Thanks for the info; I’ll check out the links.

        I realized after I entered my initial comment that the last sentence was confusing. I didn’t mean to say that I would consider “removing (deleting) the /WP folder”… I just wonder what would happen if I removed the characters “/WP” from the Site Address URL entry. In other words, just enter the base URL (without the /WP).

Leave a Reply

Comments are reviewed and must adhere to our comments policy.

437,821 Customers Are Already Building Amazing Websites With Divi. Join The Most Empowered WordPress Community On The Web

We offer a 30 Day Money Back Guarantee, so joining is Risk-Free!

Sign Up Today

Pin It on Pinterest