How do I use PHP scripts?
Our Web hosting service allows you to use scripts created in the PHP programming language.
On this page:
- Installing a PHP script
- Using the script you installed
- Sending e-mail
- What php.ini settings do you use?
- Changing basic php.ini settings
- Changing advanced php.ini settings
- Can I see the output of phpinfo()?
- PHP memory limits
- Can I use PEAR packages?
- Can I use Zend Optimizer or ionCube Loader?
Installing a PHP script
Unlike Perl scripts, PHP scripts can be placed anywhere on your Web site. You don't need to enter any special text on the first line, and you don't need to change the permissions to make them "executable" after uploading them.
To install a PHP script, just be sure to follow these two rules:
-
Name your PHP script so that it ends in ".php".
For example, you could call a search script "search.php". (If you name a PHP script "index.php" and place it in a directory that does not contain an "index.html" or "index.htm" file, the PHP script will be displayed as the default file for that directory.)
-
Use your FTP program to upload the script file in text (or "ASCII") mode, not "binary" mode.
Although text mode is the default for most FTP programs, your PHP script may not work if accidentally uploaded in binary mode, so it's wise to check. Text mode is sometimes called "ASCII mode".
Using the script you installed
When your PHP script is installed, you'll be able to access it just like any other Web page. For example, if you named your script "search.php" and placed it in the top level of your Web site, you would access it as:
http://www.example.com/search.php
Sending e-mail
If you send e-mail from a PHP script, you'll probably want to make sure your script sets the correct "bounce" address.
What php.ini settings do you use?
Certain aspects of the way PHP works are controlled through the server's "php.ini" file. By default, we use php.ini settings that are tuned for maximum security. In particular, people who are asking this question are probably interested in these three settings:
allow_url_fopen = "On" magic_quotes_gpc = "On" register_globals = "Off"
(However, for compatibility reasons, register_globals may be "On" for accounts that were established with us before March 2005.)
We do allow our customers to change these settings if they wish (but be sure you understand the security implications of enabling register_globals). See the next sections for more information on changing the php.ini settings.
Changing basic php.ini settings
Our version of PHP allows our customers to override any php.ini settings. This lets us use a global php.ini file that has the settings turned to high security levels, while giving our customers a way to lower those security settings for the few scripts that require it. (In particular, you probably need to turn on the "allow_url_fopen" setting if you see PHP error messages saying "URL file-access is disabled in the server configuration".)
You can easily change the "register_globals", "magic_quotes_gpc", "allow_url_fopen" and Zend Optimizer PHP settings for your account in the customer control panel:
- Login to the customer control panel
- Click PHP Settings
- Check the boxes to choose the options you wish, then click Save Settings
Changing advanced php.ini settings
If you need to change php.ini settings other than "register_globals", "magic_quotes_gpc" or "allow_url_fopen", advanced users can do that, too. It involves editing a file in a subdirectory of your home directory.
First, follow the instructions above to use the control panel to set the "register_globals", "magic_quotes_gpc" and "allow_url_fopen" options the way you want them. (You should view the PHP Settings section of the control panel and press Save Changes even if you don't change these settings, because doing that creates the "php.ini" file you're going to edit next.)
After doing that:
- Make a telnet or SSH connection to our servers
- Use a text editor to modify the php.ini file inside the php-settings directory
The php.ini file only needs to contain the line(s) you want to change from the defaults we use. For example, if you want to turn on PHP's "asp_tags" option, you would need to add only this single line to the php.ini file (leaving any existing lines in place):
asp_tags = On
If you have any trouble, or you don't feel comfortable using the Unix shell, please contact us and let us know what php.ini settings you want to change. We can take care of it for you.
(We should also mention that there are a small number of php.ini settings that can't be changed.)
Can I see the output of phpinfo()?
This page shows the phpinfo() settings for an account on our servers:
Remember that you can override most of these settings; the sample page is useful for showing what modules we have installed and what defaults we use.
PHP memory limits
Our default PHP memory_limit is about 149 MB of RAM. In the unlikely event that your PHP script requires more than that, you can increase it by placing this type of line in the "php.ini" file:
memory_limit = 200M
However, you won't be able to increase it beyond the individual script memory limit shown on our Script Policies page — and in fact, it should be at least 20 MB less than shown there, because PHP itself uses some memory.
If you try to go beyond that, the server will silently "kill" your script. It's better to keep the PHP memory_limit lower so that PHP shows a useful error message if a bug causes your script to use too much memory.
Can I use PEAR packages?
PEAR packages are files that contain prewritten PHP code. Some scripts use PEAR packages to perform tasks such as connecting to a database.
We do support PEAR, with many PEAR packages preinstalled. See our PEAR support page for more details.
Can I use Zend Optimizer or ionCube Loader?
Zend Optimizer and ionCube Loader allow you to run certain "encoded" PHP scripts. We have instructions explaining how to use them on our Zend Optimizer and ionCube Loader pages.
