How to Install WordPress in a Subdirectory (Step by Step)

16 hours ago, WordPress Tutorials, 1 Views
Installing WordPress in a subdirectory or folder

Understanding WordPress Subdirectory Installations

Installing WordPress in a subdirectory, sometimes referred to as a subfolder, means placing the core WordPress files within a folder inside your website’s main directory. For example, instead of your WordPress site living directly at `example.com`, it would reside at `example.com/blog`, `example.com/wordpress`, or any other name you choose for your subdirectory.

This approach can be useful in several scenarios:

  • Adding a blog to an existing website: If you already have a website built with HTML, a different CMS, or even just static files, installing WordPress in a subdirectory allows you to easily add a blog without disrupting your existing site.
  • Testing new themes and plugins: Before implementing significant changes to your live website, you can create a subdirectory installation to experiment with new themes, plugins, or custom code without affecting your main site.
  • Developing a separate section of your website: You might want to use WordPress for a specific part of your website, such as a knowledge base, a forum, or an online store, while keeping the rest of the site managed differently.
  • Organizing multiple WordPress sites: If you plan to manage multiple WordPress websites under the same domain, using subdirectories can help you keep them organized and easily accessible.

Prerequisites

Before you begin the installation process, ensure you have the following:

  • A web hosting account: You’ll need a hosting account with a web server (like Apache or Nginx) that supports PHP and MySQL (or MariaDB).
  • A domain name: You’ll need a domain name pointed to your web hosting server.
  • Access to your web hosting control panel: This could be cPanel, Plesk, or a similar interface that allows you to manage your files, databases, and other hosting settings.
  • An FTP client (optional but recommended): An FTP client like FileZilla or Cyberduck can be helpful for uploading files to your server.
  • A text editor: You’ll need a text editor like Notepad++, Sublime Text, or Visual Studio Code to edit configuration files.

Step 1: Create a Subdirectory

The first step is to create the subdirectory where you’ll install WordPress. You can do this through your web hosting control panel’s file manager or using an FTP client.

Using cPanel File Manager:

  1. Log in to your cPanel account.
  2. Navigate to the “File Manager” section.
  3. Choose the directory where you want to create the subdirectory (usually `public_html` or `www`).
  4. Click on “+ Folder” or “New Folder” in the toolbar.
  5. Enter the name for your subdirectory (e.g., “blog,” “wordpress,” or “news”).
  6. Click “Create New Folder.”

Using FTP Client (e.g., FileZilla):

  1. Open your FTP client and connect to your web server using your FTP credentials (hostname, username, and password).
  2. Navigate to the root directory of your website (usually `public_html` or `www`).
  3. Right-click in the file listing area and select “Create directory.”
  4. Enter the name for your subdirectory (e.g., “blog,” “wordpress,” or “news”).
  5. Click “OK.”

Step 2: Download WordPress

Download the latest version of WordPress from the official WordPress website: [https://wordpress.org/download/](https://wordpress.org/download/).

This will download a ZIP file containing the WordPress installation files.

Step 3: Upload WordPress Files

Next, you need to upload the downloaded WordPress files to the subdirectory you created in Step 1.

Using cPanel File Manager:

  1. Navigate to the subdirectory you created in Step 1 using the File Manager.
  2. Click on “Upload” in the toolbar.
  3. Click “Select File” and choose the WordPress ZIP file you downloaded in Step 2.
  4. Wait for the file to upload completely. The progress bar will indicate the upload status.
  5. Once the upload is complete, go back to the File Manager and locate the ZIP file.
  6. Right-click on the ZIP file and select “Extract.”
  7. Choose the subdirectory as the extraction destination and click “Extract Files.”
  8. After extraction, you should see a folder named “wordpress” (or similar) inside your subdirectory. Move all the files and folders within this “wordpress” folder one level up, directly into your subdirectory (e.g., /public_html/blog/). This is important for your website to function correctly from the subdirectory.

Using FTP Client (e.g., FileZilla):

  1. Open your FTP client and connect to your web server.
  2. Navigate to the subdirectory you created in Step 1 in the remote site panel (right side).
  3. In the local site panel (left side), locate the WordPress ZIP file you downloaded.
  4. Right-click on the ZIP file and select “Extract Here” (or a similar option depending on your operating system). This will extract the files to a folder on your computer.
  5. Navigate into the extracted “wordpress” folder on your computer.
  6. Select all the files and folders within the “wordpress” folder.
  7. Drag and drop the selected files and folders from the local site panel to the subdirectory in the remote site panel.
  8. Wait for all the files to upload completely. The upload speed will depend on your internet connection and the server’s performance.

Step 4: Create a MySQL Database

WordPress requires a MySQL database to store its data. You’ll need to create a new database and a user with appropriate privileges.

Using cPanel:

  1. Log in to your cPanel account.
  2. Navigate to the “Databases” section and click on “MySQL Databases.”
  3. Under “Create New Database,” enter a name for your database (e.g., “wordpress_blog”).
  4. Click “Create Database.”
  5. Scroll down to “MySQL Users” and create a new user. Enter a username (e.g., “wp_user”) and a strong password.
  6. Click “Create User.”
  7. Scroll down to “Add User To Database” and select the user you just created and the database you created earlier.
  8. Click “Add.”
  9. On the next page, grant all privileges to the user by checking the “ALL PRIVILEGES” box.
  10. Click “Make Changes.”

Important: Remember the database name, username, and password. You’ll need them in the next step.

Step 5: Configure WordPress

Now that you’ve uploaded the WordPress files and created a database, you can start the WordPress installation process.

  1. Open your web browser and go to your website’s subdirectory (e.g., `example.com/blog`).
  2. You should see the WordPress welcome screen. Choose your language and click “Continue.”
  3. The next screen will ask you for your database information. Enter the following:
    • Database Name: The name of the database you created in Step 4.
    • Username: The username you created for the database in Step 4.
    • Password: The password for the database user.
    • Database Host: This is usually “localhost.” If not, your hosting provider will provide the correct value.
    • Table Prefix: This is optional but recommended for security. Change the default “wp_” to something else (e.g., “wp_blog_”).
  4. Click “Submit.”
  5. If the database connection is successful, you’ll see a message saying, “Alright, sparky! You’ve made it through this part of the installation. WordPress can now communicate with your database.” Click “Run the installation.”
  6. On the next screen, you’ll need to provide information about your website:
    • Site Title: The name of your website (e.g., “My Blog”).
    • Username: The username you’ll use to log in to the WordPress admin panel. Choose a strong and unique username.
    • Password: A strong password for your WordPress admin user.
    • Your Email: Your email address. This will be used for notifications and password recovery.
    • Search Engine Visibility: Check or uncheck the box to discourage search engines from indexing your site while it’s under development. You can change this later in the WordPress settings.
  7. Click “Install WordPress.”
  8. Once the installation is complete, you’ll see a success message. Click “Log In” to access your WordPress admin panel.
  9. Enter the username and password you created during the installation process.

Step 6: Update the .htaccess File (if needed)

In some cases, you might need to update the `.htaccess` file in your website’s root directory to ensure that WordPress works correctly in the subdirectory. This is usually necessary if you’re experiencing issues with permalinks or if your website’s main page redirects to the WordPress subdirectory.

  1. Access your website’s root directory using the File Manager or an FTP client.
  2. Locate the `.htaccess` file. If you don’t see it, make sure your file manager or FTP client is configured to show hidden files (usually an option in the settings).
  3. Edit the `.htaccess` file.
  4. Add the following code to the `.htaccess` file:

    “`

    RewriteEngine On
    RewriteBase /
    RewriteRule ^index.php$ – [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]

    “`

  5. Save the `.htaccess` file.

If you installed WordPress in a subdirectory (e.g., /blog/), you might need to modify the `RewriteBase` directive to match your subdirectory:

“`

RewriteEngine On
RewriteBase /blog/
RewriteRule ^index.php$ – [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]

“`

Important: Be very careful when editing the `.htaccess` file. An incorrect configuration can break your website. If you’re not comfortable editing the file manually, consult with your hosting provider.

Step 7: Configure WordPress URL Settings

To ensure that your WordPress site works correctly within the subdirectory, you need to update the WordPress URL settings in the admin panel.

  1. Log in to your WordPress admin panel (e.g., `example.com/blog/wp-admin`).
  2. Navigate to “Settings” > “General.”
  3. In the “WordPress Address (URL)” field, enter the URL of your WordPress installation (e.g., `http://example.com/blog`).
  4. In the “Site Address (URL)” field, enter the URL where you want your website to be accessible (e.g., `http://example.com/blog`).
  5. Click “Save Changes.”

Step 8: Permalinks Settings

Finally, configure your permalinks to ensure that your post and page URLs are SEO-friendly.

  1. In the WordPress admin panel, navigate to “Settings” > “Permalinks.”
  2. Choose a permalink structure that you prefer. The “Post name” option is generally recommended.
  3. Click “Save Changes.”

After completing these steps, your WordPress site should be successfully installed in a subdirectory and accessible through the specified URL (e.g., `example.com/blog`).