How to Install WordPress in a Subdirectory
Bulletproof Backups for Your WordPress Website
Fortify your business continuity with foolproof WordPress backups. No data loss, no downtime — just secure, seamless operation.
When you sign up with a web hosting provider, it’ll likely install WordPress in your root domain. While that is fine, there are certain reasons why you may want to install WordPress in a subdirectory:
- You want your blog, installed in a subdirectory of your domain (like https://example.com/blog), to be powered by WordPress while your main website is powered by something else.
- Security. In this day and age of automated hacking attempts via bots, installing WordPress in a subdirectory can reduce the chances of getting hacked since bots are much more likely to scan your root directory for a WordPress installation, and in turn, WordPress vulnerabilities. However, this is a very slender benefit to security, as most malicious bots will scan subdirectories as well. The only real way to keep out bots is to install a robust firewall like the one that comes with BlogVault.
- You wish your site to be multilingual. In that case, you can create separate subdirectories for each language and then install WordPress on them.
- Testing and experimenting. Installing WordPress in a subdirectory allows you to use it as a staging site for your live site on the same domain name.
TL;DR: Installing WordPress in a subdirectory can be useful in certain scenarios. For example, if you run a business, you could install WordPress in a subdirectory to power your blog while having the rest of your website run on something else. Remember that after installing WordPress, you still have to maintain it. This is where BlogVault comes in. It’s a WordPress plugin that provides everything you need to take care of your WordPress site from a single dashboard. From real-time backups to daily malware scanning, from a robust firewall to easy staging, BlogVault does it all.
How to install WordPress in a subdirectory via FTP
Step 1. Create a subdirectory under the root directory
Before you can install WordPress in a subdirectory, you need to have a subdirectory in the first place. So, in this step, we’re going to create a subdirectory that we’ll be installing WordPress into. You’re going to need an FTP client for this step. I’ll be using the popular FileZilla to illustrate the process.
- Connect to your website via FTP on FileZilla. You can either use Quickconnect or go to File > Site Manager to do so.
- Once connected, enter the root directory of your website. This is usually the public_html directory but doesn’t have to be. If you already have WordPress installed in your root directory, then you’ll see your WordPress files and folders there.
- Right-click on your root directory and pick ‘Create directory’ from the menu to create a subdirectory. Give your subdirectory a suitable name.
Step 2. Upload WordPress to your subdirectory
- First, we need the core WordPress files and folders. Go to https://wordpress.org/download/ and download the WordPress software as an archive. I always recommend using the latest version of WordPress for security reasons, but you should check the PHP version on your site first for compatibility.
- Extract the archive. The files will be extracted to a folder named ‘wordpress.’
- Navigate to this ‘wordpress’ directory in the left-hand pane of FileZilla and enter it.
- Select all files inside this directory and upload them to the newly created subdirectory on your live site.
Step 3. Create a new database for your subdirectory
Every WordPress site needs a database to store post content, user settings, and so on. In this step, we’ll be creating a new database for our subdirectory. You should be able to create a new database from the ‘Databases’ section of your web hosting dashboard. To illustrate this process, I’ll use Bluehost. The steps should largely be the same for any other web host out there.
- Go to Advanced > Databases from the left-hand navigation menu.
- Under the section ‘Create New Database,’ provide a name for your new database, then click on Create Database. In my example, I’ve named the database ‘mybhsite_home_for_new_database.’
- Now, we’re going to add a new database user for our account. Scroll down to ‘Add New User’ under ‘MySQL Users.’ Choose a username and a strong password for this user, then click on Create User to finish creating.
- Now, add the user you created in Step 3 to the database you created in Step 2 as shown in the image below.
- On the next page, assign all privileges to this new user and then click on Make Changes. Make a note of the database details and credentials you’ve just created. You will need them when installing WordPress to connect the site to the right database.
That’s it! You now have a new, blank database for your subdirectory’s WordPress installation.
Step 4. Install WordPress
Now that we have everything we need for WordPress to function properly, all that remains is to install WordPress itself.
- Visit your subdirectory. Its URL should look like this: http://yourwebsite.com/name-of-your-subdirectory
- Choose a language to continue with the installation and click Continue.
- Click “Let’s go!” on the next page to continue.
- Next, enter the details of the database you made in Step 3 and click on “Submit” to continue.
- On the next page, you should see the message that “WordPress can now communicate with your database.” Click Run the installation to continue.
- On the next page, enter the required information and click on Install WordPress to continue.
That’s it! WordPress is now active on your subdirectory.
How to install WordPress in a subdirectory via WP-CLI
Well, FTP isn’t the only way to install WordPress in a subdirectory. There’s another, more powerful way to do that: WP-CLI. WP-CLI is the command-line interface for WordPress. It allows you to do a lot of administrative stuff like installing and activating plugins, scripts, and themes; changing settings; automating repetitive tasks; and much more using specific commands in a terminal rather than continuous clicking. If you have the know-how, you can be more productive this way, without having to use the mouse.
Anyway, I only recommend using WP-CLI as a last resort if you’ve never worked with a command-line interface before. It is very easy to make inadvertent changes to critical files, which would then crash your site.
Note: In the following steps, any parameters inside brackets are optional.
- Install WP-CLI if you haven’t already. You can find the instructions for installing WP-CLI on the official site. Then, launch the terminal if you’re on Linux or macOS, or the command prompt if you’re on Windows to start using WP-CLI.
- Download WordPress using the following command:
wp core download [--path=path_to_your_folder]
The ‘path’ represents the folder you’ll download WordPress too. Here’s an example:wp core download --path=wordpress-in-a-subdirectory
This downloads WordPress in a folder called ‘wordpress-in-a-subdirectory’ inside my current working directory. - Enter the directory in which you installed WordPress via the following command:
cd --path=path_to_your_folder
- Create the wp-config.php file and set up your database credentials using the following command:
wp config create --dbname=your_database_name_here --dbuser=your_database_user_here [--dbpass=your_database_password_here]
If you created a new database for your subdirectory as I explained earlier in the article, then enter its credentials here. If you don’t wish to include the database password in the command, you can enter it when prompted. - Create the database based on the credentials we passed to the wp-config.php file in the step above using the following command:
wp db create
- All that remains now is to install WordPress. Enter the following command:
wp core install --url=url_of_your_subdirectory --title="name_of_your_subdirectory" --admin_user=username_of_website_admin --admin_password=password_to_access_WordPress_admin_panel --admin_email=email_address_of_website_admin
Congratulations! You’ve successfully installed WordPress in a subdirectory using WP-CLI.
How to make WordPress installed in a subdirectory to appear at the root
If you’ve installed WordPress in a subdirectory for your website, but want visitors to access your site via the root domain, there is a simple way to make that happen. Here are the steps:
- Go to Settings > General from your WordPress dashboard.
- In the WordPress Address (URL) field, enter the URL of your WordPress installation, i.e., your subdirectory’s URL.
- In the Site Address (URL) field, enter the URL of your root directory.
- Copy the index.php and .htaccess files of your WordPress installation to the root directory.
- Now, open your root directory’s index.php file in a text editor. Change the line that says require __DIR__ . ‘/wp-blog-header.php’; to require __DIR__ . ‘/wordpress/wp-blog-header.php’; replacing ‘wordpress’ with the actual name of your subdirectory.
- Now, log in to the admin panel of your subdirectory and change your permalink structure.
Pros and cons of installing WordPress in a subdirectory
Pros
- It allows you to run two or more different content management systems (CMSes) on your site if you want. For example, your blog can be powered by WordPress, leaving the rest of your website to be powered by something else.
- Having a few parts of your site, say, your blog and careers pages, be WordPress sites on their own can be easier to manage than having a multisite.
Cons
- Increased setup and maintenance time. Say you set up a blog in a subdirectory and have WordPress power it while the rest of the site is powered by something else. Now, you have to manage two different things, which increases your maintenance. Not only do you have to manage your WordPress installation in the subdirectory, but you also have to think about how to design the rest of your site, how to link it to the blog, etc.
Common installation issues
While installing WordPress in a subdirectory is fairly straightforward, you may have issues with permalinks. If your root directory already houses a WordPress installation, then installing WordPress in a subdirectory can cause issues with permalinks because of conflicts between the .htaccess files. That is why it’s important to update them after you’ve finished installing WordPress in your desired directory.
Differences between a root install and a subdirectory install
There isn’t much of a difference between root and subdirectory installations of WordPress. The important thing to note is that a subdirectory will be considered part of the root domain, and not a separate website. This is contrary to having subdomains, which are treated as separate websites by search engines.
Things to consider if you have multiple WordPress installations on a single domain
There are two scenarios to consider here:
- Multiple WordPress installations sharing a single database. Note that the wp-config.php file will be different for each installation. However, you can edit one line in this file that will be unique to each instance:
$table_prefix = ‘wp_’; // example: ‘wp_’ or ‘b2’ or ‘mylogin_’
WordPress assigns the wp_ table prefix to a database by default. But you can freely change this prefix if you want to. If you have multiple WordPress installations sharing a single database, then you should replace the table prefix for each appropriately. This table prefix will act like a unique identifier for each website in your database.
- Multiple WordPress installations with each installation using its own database. In this case, you would have to create a database for every different WordPress instance. For each instance, change the following lines in its respective wp-config.php file:
define(‘DB_NAME’, ‘wordpress’); // The name of the database
define(‘DB_USER’, ‘username’); // Your MySQL username
define(‘DB_PASSWORD’, ‘password’); // … and password
Replace ‘wordpress,’ ‘username,’ and ‘password’ with the actual database name, database username, and password, respectively.
Note that a multisite doesn’t count since it’s essentially a single WordPress installation (with multiple sites created within that same installation and arranged like a network).
Conclusion
Installing WordPress in a subdirectory is a fairly straightforward process. However, there are pros and cons to it, just like most things in life. Consider your needs and goals carefully when deciding whether to install WordPress in a subdirectory or not. Even though the process is simple, you want to minimize as much risk as you can. Use BlogVault to take a backup of your site before you begin the installation, and you’ll be happy to know that you can restore a fully functional version of your site if things go south.
FAQs
Q – How can I install WordPress in a subdirectory?
A – You can install WordPress in a subdirectory via FTP or WP-CLI.
Q – Should I install WordPress in a subdirectory?
A – There is no correct answer to this question. It’s something that you’ll have to decide based on your needs and goals.
Tags:
Share it:
You may also like
Repair WordPress Installation In 6 Simple Ways
Is your WordPress site currently facing errors, running slower than usual, or even completely offline? If you’re struggling with the white screen of death, database connection errors, or malware warnings,…
How to Take a cPanel Backup
Every website admin knows that backing up your website is important. The worst case scenario is not being able to restore a crashed or hacked site. Good backups are like…
How Often To Backup A Site
In today’s digital age, safeguarding your data is more crucial than ever. There is also an abundance of advice on when to take website backups and how often to take…
How do you update and backup your website?
Creating Backup and Updating website can be time consuming and error-prone. BlogVault will save you hours everyday while providing you complete peace of mind.
Updating Everything Manually?
But it’s too time consuming, complicated and stops you from achieving your full potential. You don’t want to put your business at risk with inefficient management.
Backup Your WordPress Site
Install the plugin on your website, let it sync and you’re done. Get automated, scheduled backups for your critical site data, and make sure your website never experiences downtime again.