How to Install WordPress In a Different Directory?
When it comes about custom WordPress installation then we don’t realize is that installing WordPress in same directory (The Root) is not the best approach. You won’t face any problem and the things will work perfectly normal on doing so. The benefit of having WordPress installation in a different directory comes in the form of enhanced security and easy file management.
Normally, hackers attempt to exploit the core WordPress files such as wp-login.php or wp-admin.php whose location is quite obvious if the WordPress installation exists in same directory. On the other hand if you have a separate folder with WordPress installation then the chances of getting hacked become exponentially low. In addition, you will also be able to manage non-WordPress files in a better way.
Install WordPress In a Different Directory?
The initial approach is to only have index.php and .htacess file in root and rest of the files in a different folder. In the following section I have explained the step-by-step procedure for installing WordPress in its own directory. Have a look …
- Create a new folder inside the directory where you desire to host the blog on your web-server.
- Next, download the latest WordPress installation zip on your PC. Uncompress it and make necessary changes in wp-config.php. If you are unable to find a file named ‘wp-config.php’ then most probably you will find another with name wp-config-sample.php”. Just rename it, configure it, and continue.
- Now recreate the archive and upload it inside the newly created folder on your server. Then you will require extracting the archive file. This must not be a problem as most of the hosting service providers have tools to uncompressed archives in the control panel. If not, then you will require uploading files manually via FTP.
- Now, visit the online address “http://[your domain/sub-domain name]/[name of folder ]“. Soon you will be prompted about specifying the name of website and set a username and password for administrator.
- After login, you will be taken to dashboard of your freshly installed WordPress account.
- To proceed, click on ‘Settings’ and select ‘Permalinks’. It is very necessary to set the right kind of URL structure in very beginning. As per my view the best approach will be to select the radio-button in-front of “Post name” followed by a click on “Save Changes” button.
- Under ‘General’ settings you will require modifying the entries in text-boxes for specifying ‘WordPress Address’ and ‘Site Address’. Leave the WordPress Address (URL) unchanged and set the Site Address (URL) as name of your website ( http://[your domain name]).
- Now, copy the Index.php file and .htacess files from WordPress folder on your PC. Copy it, do not cut.
- Now, open the index.php in any binary text editor to change the last line as follows “require(‘./[folder-name]/wp-blog-header.php’);”.
- Now, save the file and upload it with along with .htacesss file to root of your WordPress blog.
Now you can try accessing the blog on a browser and hopefully everything will work fine.
You need to know:
- You can also create a sub-directory or more and run WordPress from there. The trick is all about including the correct path to header.php inside the Index.php file at root of your blog.
- If you modified the permalink structure at some stage then make sure to copy the .htacess file inside the folder and replace the existing one in the root directory.
- This tutorial to install WordPress in a different directory is for Linux based web servers only.
Same approach is to be utilized for an existing WordPress installation in root. You will require copying all WordPress files & folders in a separate directory. Then visit dashboard and specify the new WordPress Path and save changes. Now, edit index.php file inside root directory as discussed above. The final task is to swipe other WordPress content expect index.php and .htacess.
Caution: To prevent any loss of data, you must backup WordPress beforehand.