PHP server-side scripting language

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 schema. 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.

Use 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

Specify PHP versions on Webserve

On Webserve, the default version of PHP is 7.1; however, PHP 5.6 will still be available until it is retired at the end of December 2018. Webtest servers are already using PHP 7.1.

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.

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

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

Troubleshoot

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.

Increase 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 2018-08-15 10:05:58.

Contact us

For help or to comment, email the UITS Support Center.