You are using a browser which is not compatible with CSS (for more information, see Tara's tutorial). Because of this, it is possible that our website may not appear correctly in your browser. We apologise for the inconvenience, and recommend you upgrade your browser to one which is compatible with CSS. For more information, please visit our Browser Upgrade page.


Configuring PHP in a shared hosting environment by Daniel

Last updated: 02/05/2012
Biography: Daniel has been interested in web design since 1999, when he first started designing a personal website. Since then, he has learnt much, and is interested in new web standards like XHTML and CSS, and in PHP.

Daniel is responsible for managing the 4WebHelp Forums, along with the forum moderators. He should be contacted for any modifications to your forum account (which you cannot do through the phpBB interface) and for any issues you may have with moderation.
See 9 more tutorials by Daniel

Shared web hosting always has been and always will be a low cost way of hosting your average website. After all, most people cannot afford to rent/buy a dedicated server for their website. However, shared hosting presents a major inconvenience: customisability. Since you're "sharing" this server with other people, you can't just do what you want. Your host will decide on all server wide settings, in the interests of all. These settings will include PHP settings.

But let's say you need to change these settings: how are you going to do it? One way would be to get down on your hands and knees and plead with your host. But that's not exactly an easy or sure way of getting the PHP configuration changed. No, there's a much easier solution: set them yourself! "But they're server wide settings" I hear you say. Wrong! Most of the PHP settings which developers use can actually be changed by the user, surprisingly enough.

Now, let's get down to the technical aspect of this. Let's say I want to turn off magic quotes (automatic escape of special characters, usually in preparation for use in an SQL query). The relevant setting for this would be magic_quotes_gpc. You now have two ways of setting it to off:

  1. In your PHP script:

      ini_set ('magic_quotes_gpc', 0);

    This would turn off magic quotes in that particular script. Or you could include it in your template/header file, and have it take effect in all your PHP scripts.

  2. In a particular directory/your whole site:
    Let's say you're in a hurry, or you don't want to edit a script. Apache lets you control its settings in your .htaccess file. However, you can also control PHP settings from this file, using the php_value command. Simply place the following code in your .htaccess file:

    php_value magic_quotes_gpc 0

    You can place this file in different places:
    • If you place this file in the root directory of your site, then it will affect all PHP scripts in your site.
    • If you place it in a particular directory of your site, it will only affect the PHP scripts in that directory.

Simple, eh? Now didn't that save you (and your server administrator!) a lot of trouble? Wink For a complete list of settings which you can or cannot set by yourself, please see

© 4WebHelp and Daniel

Latest comments on this tutorial
how do i set php session save part with this tutor
Hey, so Daniel I have a ? for you:

If I am hosting 2 domains on one hosting plan and I would like the emails to go to different places, how would I configure that?  The issue I am having is that the emails will work for one domain or the other, not both. I thought you might know.
My current host blocks the use of php_value in .htaccess files. That's
.htaccess can be used on both - Windows and Linux

ini_set ('magic_quotes_gpc', 0);

will not do anything. Magic quotes are added before the script starts running, so by the time you call ini_set it's too late.

A better example might be:

ini_set('error_reporting', E_ALL);

which enables all error/warning/debug/info messages to be displayed.
How can I set mod_rewrite on using htaccess or using a PHP script. I'm on shared hosting.
Dave (again
actually .htaccess is available to windows i now no this, however your article still gives wrong information. The value of magic quotes cannot be changed in a users script. It can only be changed in php.ini, httpd.conf or .htaccess.
Yes very useful indeed. However isn't .htaccess only available on UNIX? I might be advisable to recommend the embedded option as this will always work on both platforms -WINDOWS AND UNIX.
Excellent tips, very useful!

Add a new comment

This page is © Copyright 2002-2024, 4WebHelp. It may not be reproduced without 4WebHelp's prior permission.