PHP server-side scripting language

Important:
On Webserve, PHP 7.1 will become the default version in spring 2018; however, PHP 5.6 will still be available until it is retired at the end of December 2018. For help specifying which version of PHP to use, follow the steps in Specifying PHP versions on Webserve below.

On this page:


About PHP

PHP is an open-source server-side scripting language with syntax similar to that of C and Perl; for more, see php.net and zend.com. At Indiana University, PHP version 5.6 is available on Webserve (www.indiana.edu, www.iupui.edu, www.iun.edu, www.iuk.edu, and www.iue.edu).

You can use the PHP scripting language to create dynamic web pages; a dynamic page interacts with the user, so that each user visiting the page sees customized information. You can also use PHP to create dynamic web pages that are generated from information in a MySQL database. PHP commands can be embedded within a standard HTML page.

PHP offers connectivity to most common databases. PHP also offers integration with various external libraries, so you can do anything from generating PDF documents to parsing XML.

Using PHP on Webserve

Keep the following in mind when using PHP on Webserve:

  • Bang lines are not required and will be ignored if present. (The previous web server environment required bang lines.)
  • Use .php as the file extension.
    Notes:
    • This refers only to PHP files executed directly via a URL. Include files may use other extensions, such as .inc.
    • If you have PHP files that currently use .php4 extensions, it is strongly recommended that you use .php instead.
  • The script must have owner execute permission. For best security, setting permissions to 700 (i.e., read, write, and execute privileges for owner only) is strongly recommended.

    For example, where script.php is the name of the file containing the script, change the file permission as follows:

      chmod 700 script.php

Specifying PHP versions on Webserve

Webserve currently supports PHP versions 5.6 and 7.1. PHP 5.6 is the default version, but you can specify which version of PHP to use in the .htaccess file; this setting will apply to the directory where the .htaccess file resides and any subdirectories, unless you specify a different version in a subdirectory.

To use PHP 5.6, add the following to the .htaccess file:

<FilesMatch "\.php$">
AddHandler x-httpd-php5.6 .php
</FilesMatch>

To use PHP 7.1, add the following to the .htaccess file:

<FilesMatch "\.php$">
AddHandler x-httpd-php7.1 .php
</FilesMatch>

Troubleshooting

If you receive a "500 - Internal Server Error" message when running your scripts, check the following:

  1. Make sure the file permission is set to 700 (read, write, and execute for owner only).
  2. Make sure the directory (folder) permission is set to 711. Setting it to 777 will cause a "500 - Internal Server Error".
  3. If the file/directory permissions are set correctly and you still get a 500 error, it is likely due to line compatibility between the program used to create/upload the file and the Linux server. To fix this, log into the account on Webserve via an SSH client with a command line interface, and then do the following:
    1. Use cd to move to the directory where your PHP file is located (e.g., cd www).
    2. Open the file using an editor (e.g., nano), and then save it:
        Ctrl + o

      This converts Windows CR/LF (carriage return/line feed) to Unix LF (line feed) or Mac CR to Unix LF.

    To prevent this problem in the future, change the settings/preferences in the program you are using to develop PHP files. To set preferences in Dreamweaver, go to Edit > Preferences. Select Code Format or HTML Format, depending on the versions. Change Line Breaks to LF (Unix).

Sample PHP code

Place a file containing the code below inside the www directory of your Webserve account and save it as info.php:

  <?php
  phpinfo();
  ?>

To view the file, provide the web site address to the file. For example:

  http://www.indiana.edu/~account/info.php

This will output information about the current state of PHP, which includes information about PHP compilation options and extensions, PHP version, server information and environment (if compiled as a module), PHP environment, OS version information, paths, master and local values of configuration options, HTTP headers, and the PHP license. Because every system is set up differently, you can use phpinfo() to check configuration settings and for available predefined variables on a given system. For more, see phpinfo from php.net.

Increasing the memory limit

You can increase the memory limit with a php.ini file in the same directory as your PHP script. If you have multiple subdirectories, you'll need to place the php.ini file in each subdirectory that has PHP scripts.

In the php.ini file, to specify the memory_limit you wish to set, use:

  memory_limit = whatever integer you wish

To verify the memory_limit has changed, create a php info file.

Resources

For more about PHP, see:

This is document bfsu in the Knowledge Base.
Last modified on 2017-08-17 13:33:48.

  • Fill out this form to submit your issue to the UITS Support Center.
  • Please note that you must be affiliated with Indiana University to receive support.
  • All fields are required.

Please provide your IU email address. If you currently have a problem receiving email at your IU account, enter an alternate email address.

  • Fill out this form to submit your comment to the IU Knowledge Base.
  • If you are affiliated with Indiana University and need help with a computing problem, please use the I need help with a computing problem section above, or contact your campus Support Center.

Please provide your IU email address. If you currently have a problem receiving email at your IU account, enter an alternate email address.