Joomla!: Moving sensitive files outside the web root (Joomla 1.5)

joomla_hackedAs a web developer, one of the worst things that can ever happen to you are woken up in the middle of the night by an aggravated client whose site you manage, and have him tell you that his site has been hacked and there is a black Mario smiling back instead of the crisp and clean home page your worked tirelessly to perfect. To make matters worse, you try login to the admin side of the Joomla! installation and your password does not work anymore! If your are really unlucky and the hacker wanted to finish you off, you find your database gone! (This has actually happened to me! Damn you silly Iranians! Thank God for backups!).


Avoiding such scenarios, I believe, is in every developers best interests. Therefore, upon restoring my clients site in record time, I had to venture into clamping down on the system, within the limits of making changes to Joomla! because I had very limited access to the server. So below, find something interesting you can do to secure your Joomla! installation, over and above the obvious security measures of making sure  the super-admin account is not called ‘admin’ and is not id ‘62’, changing the database table prefix to something other than ‘jos_’ and making sire that your index.php for the site (and template) are not writable by the system.

This is a core hack. Files you change as described on this page will be overwritten during updates of Joomla!.

One challenge in Joomla! is ensuring that certain PHP files in public_html (or otherwise known as httpdocs or www depending on your server setup) containing executable code or confidential data are protected from direct Internet access.

There are various ways to protect such files, but most are not optimal. Many users and developer groups, such as Gallery2 and strongly recommend against keeping vulnerable files and confidential data inside public_html.

The following method is one way to protect the Joomla configuration.php, perhaps the most confidential file of any Joomla! site.

Using the following method, the Joomla configuration.php file does not reside in the public_html directory but resides instead outside of (or above) the public_html directory and is much better protected from the internet access.

NOTE: The above procedure modifies core files in a Joomla install. Later Joomla upgrades, updates, re-installs etc. may remove these core modifications. Modifying core files may make the Joomla install incompatible with certain extensions.

WARNING: Do not attempt this procedure unless you understand what you are doing and are willing to possibly break your site while testing. This is not for beginners or inexperienced persons, ensure you have a back up of your site and also of the files you will be modifying before attempting this modification.


1. Create a directory in your domain outside of your public_html directory. You can name it anything you want but it should reflect the site name in some way. I used the name design2-files for the directory name in this example. Note: If you have multiple Joomla installs then each Joomla install you have should have its own directory outside of public_html to contain its configuration.php file.

2. Place a copy of your current configuration.php file, completely unaltered and NOT renamed into this directory. I have permissions set at 644 on the file in this directory and the directory set to 755 permissions. Permissions of 444 on the configuration.php file are also acceptable if that is the current permissions of your configuration.php file.

3. Go to the root/includes/ directory in your Joomla install, backup the file defines.php.

4. Now open the file defines.php in your favorite editor

5. Around line 26 you will see this:


Replace it with this:


If Joomla has been installed in a subdirectory under public_html ( public_html/subdirectory/ ) then replace it with this


NOTE: The /design2-files is our example subdirectory. Replace this with the name of your subdirectory.

6. Repeat these exact same steps with the defines.php file that is located in the root/administrator/includes/ directory. If you don’t do this access to your admin area will be prevented.

7. Go to the root of your installation and rename the configuration.php file to something like somefile.html while testing the modifications.

8. Using a browser, go to your website and test as many pages as you can to make certain it is working correctly.

9. When you are satisfied everything is working properly, delete the old renamed configuration.php file from the root of your Joomla installation.

10. Retest your website thoroughly to make sure everything is still working correctly.

11. Make sure you add the new directory (design2-files in our example) with the configuration.php file in it to your backup job so it doesn’t get missed.

12. You can access and modify the Joomla configuration as you would normally from the Joomla administration area. This access will not create a new configuration.php file, but will modify the moved configuration.php file.


Leave a Reply