Using PHP Scripts

PHP is the fastest growing language for web development. PHP is a language that is embedded on HTML code, simplifying web development. PHP is suitable for any sites that requires dynamically generated contents.

To use PHP, you need to named your PHP files with .php, .php3, .php4 or .phtml. You can also define additional extensions to be parsed by PHP if you wish to do so.

Important

Traditionally, our system require every PHP files to be set with their executable bit on (chmod +x). However, as of June 2004, this is no longer the case. It is no longer required to do an AutoCorrect after uploading your PHP files.

Note

Our PHP system is CGI based, not the more common Apache module based. This has the advantage that we don't have to restrict you using safe_mode while still retaining security. That means you don't have to worry about PHP disabling some function calls.

Configuring PHP

Our customers can configure their PHP settings themselves. You don't have to rely on our administrators to install PHP modules or changing configuration parameters. You can even install your own PHP modules by yourself.

To configure PHP, you need to do it from SiteManager. Go to Language Settings and then PHP Setttings. From there you will see the list of regular domains you have. Every regular subdomains can use the main global PHP settings or have their own PHP configuration. The configuration to use is shown in PHP Settings column. 'Use global configuration file' means the subdomain is using the main account's PHP configuration file. 'Use local configuration file' means the subdomain is using its own PHP configuration file. You can change that by using the action menu use local settings or revert to global respectively.

To edit PHP configuration for subdomains that set to use local settings, you need to use view settings action menu. To edit the main global PHP configuration you need to use View global settings menu on the bottom of the page.

Inside Configuration Menu

Inside the configuration menu you change the way PHP works. To add modules, use the Edit Loaded Extensions menu. From there you can add or remove modules that will be used by the particular configuration. For example, you can enable gd and mysql module if you are going to use image functions and MySQL database.

Caution

Loading more extensions will require more resources on your account and might cause problems with PHP scripts. Please consider splitting multiple PHP functions into multiple subdomains if you need a lot of modules.

You can also change various PHP configuration parameters from this menu. For example, you can change register_globals and magic_quotes_gpc settings here. For more information about PHP configuration parameters, please refer to the official PHP documentation.

Caution

Do not blindly change PHP settings without knowing their functions. Incorrectly altering PHP configuration might result in problems running PHP scripts.

Note

Since we don't use Apache module version of PHP, please do not attempt to alter configuration parameters using .htaccess file. It will result in web server errors.

Installing Your Own PHP Module

You have the option to install your own PHP module if the needed module is not already installed on our server. For example if you obtain a commercial module from a third party.

To install a PHP module, go to Custom PHP extensions under PHP Settings menu. It will open a new page listing the currently installed custom PHP modules. You can upload a new PHP module by using Upload new extension menu here.

Caution

Please make sure that the module you are trying to install is compatible for the version of PHP on our server. Our system will tell you the current version of PHP when you are trying to upload the extension. You will also need to upgrade the PHP extension you uploaded whenever we upgrade PHP on our servers.

After the module get installed, you can enable it just like any other modules using Edit Loaded Extensions menu.

Installing PEAR Modules

PEAR is is a framework and distribution system for reusable PHP components. Your application might need to use some PEAR modules, before you can run your application, you will need to install the appropriate PEAR modules.

To manage PEAR modules, you need to go to Manage PEAR Packages menu from the main PHP Settings page. In that page, there will be a list of PEAR packages, globally installed or locally installed.

You can install PEAR packages by using Install new PEAR module on the bottom of the screen. From there you can choose which package to install. The list of packages should be current as listed on PEAR web site.

Manually Editing PHP Configuration File

If you don't want to use SiteManager to configure PHP or if the setting you want to change is not editable yet on SiteManager, you can manually edit the php.ini files by yourself.

Assuming your account username is u777, the global PHP configuration is located on /home/u777/var/lib/php/php.ini. And the local configuration for subdomain bangalore.example.com is /home/u777/domain/bangalore.example.com/php.ini.

Warning

Using SiteManager to configure your PHP settings after manually editing it could result in loss of your manual changes.

Adding Another Extension To Be Used By PHP

By default, our system will treat filenames ending with .php, php3. php4 or .phtml as PHP files. However, sometimes it is necessary to add additional files to be treated as PHP files. For example, if you want files ending with .html to be parsed as PHP files.

To add additional extensions to be parsed as PHP, please do the following:

  1. Log on to SiteManager if you haven't already logged on.

  2. Go to File Manager and then choose Properties for a subdomain you want to add additional extension to. Or you can also choose Default Subdomain Properties if you want your additions to be recognized by all of your subdomains.

  3. Go to section MIME Types, Apache Handlers, Charsets, Encoding, Language and then choose Map an extension to an Apache handler (AddHandler)..

  4. On Apache Handler field, choose x-httpd-php. On File extension field, specify an extension (e.g. html). Click Add Extension to continue.

  5. Repeat previous two steps if you need to add additional extensions to be recognized as PHP files.

Differences From Apache Module Version of PHP

There are several differences between Apache modules version of PHP and our unique PHP system. Most of the time you will not notice them, however there are a few differences that might affect your PHP scripts development:

  • Our PHP system run as CGI mode. This means PHP scripts run more or less the same way as CGI scripts like Perl, Python or Ruby scripts.

  • Apache specific functions are not available, these include but not limited to: apache_child_terminate, apache_get_modules, apache_get_version, apache_getenv, apache_lookup_uri, apache_note, apache_request_headers, apache_response_headers, apache_setenv, ascii2ebcdic, ebcdic2ascii, getallheaders, virtual. Please see http://www.php.net/manual/en/ref.apache.php for more information about these Apache specific functions. While these functions are unavailable, there should be other ways to accomplish the same task. You will need to use other calls and functions that are not Apache specific.

  • PHP running inside Apache will honor php_flag and php_value directives inside .htaccess file. Since our system is not running Apache module version of PHP, these directives will cause error. In order to modify PHP settings on our system, please refer to the section called “Configuring PHP”.

  • HTTP Authentication works a little differently. The PHP Manual at http://www.php.net/manual/en/features.http-auth.php states that HTTP authentication will not work with CGI version of PHP, however it does work on our system with a little modification. The following is an example of HTTP authentication on our system:

    <?php
    if (!isset($_SERVER['PHP_AUTH_USER'])) {
       header('WWW-Authenticate: Basic realm="My Realm"');
       header('Status: 401 Unauthorized');
       header('HTTP-Status: 401 Unauthorized');
       echo 'Text to send if user hits Cancel button';
       exit;
    } else {
       echo "<p>Hello {$_SERVER['PHP_AUTH_USER']}.</p>";
       echo "<p>You entered {$_SERVER['PHP_AUTH_PW']}
          as your password.</p>";
    }
    ?>

    Note that the only difference than the example from PHP manual is how we send status headers.

  • On some PHP providers, you are not allowed to configure PHP yourselves. Any reconfiguration or module additions will require pestering their system administrator. On our system, it is not necessary to get in touch with our system administrator to change PHP configuration (however we will be gladfully help you if you ask us). Please see the previous sections on how to configure PHP on our system.

Copyright © 2003 indoglobal.com

. .