PHP Server-Side Scripting Language

Table of Contents

 
I. What is PHP?
  • PHP is an open-source server-side scripting language (php.net  and zend.com ). 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 create dynamic web pages with the PHP scripting language. A dynamic Web page interacts with the user, so that each user visiting the page sees customized information. PHP can also be used to create dynamic web pages that are generated from information accessed from a MySQL database. 
  • You can embed PHP commands within a standard HTML page. PHP's syntax is similar to that of C and Perl, making it easy to learn for anyone with basic programming skills. 
  • Another feature that PHP offers is connectivity to most of the common databases. PHP also offers integration with various external libraries, which allow the developer to do anything from generating PDF documents to parsing XML.

 
II. Using PHP on Webserve
  1. Bang lines are not required and will be ignored if present. (This information is provided for historical purposes as the previous web server environment required bang lines.)
  2. You should use .php as the file extension. This refers to only 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 move toward using .php for these instead.
  3. The script must have owner execute permission. For best security, we strongly recommend using permissions set to 700 (only owner has read, write, and execute privileges).

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

    chmod 700 script.php
    

 
III. Troubleshooting
When running your scripts, if you receive a 500 Internal Server Error message, please check the following:

1. Check to make sure the file permission is set to 700 (read, write, and execute for owner only).

2. Check the Directory (folder) permission. Setting it to 777 will give you a 500 - Internal Server Error.
Set it to 711.

3. When the file/directory permissions are set correctly, and you are still getting a 500 error, it is likely due to line compatibility between the program used to create/upload the file and the Linux server. To correct this, login to the account on Webserve via an SSH client that provides a command line interface and do the following:

  1. Move to the directory where your php file is using the 'cd' command (e.g., cd www).
  2. Open the file using an editor such as nano and save it by typing Ctrl + o
This simple steps may solve your problem because it converts Windows CR/LF (carriage return/line feed) to Unix LF (line feed) or Mac CR to Unix LF.

To prevent this problem, you need to change 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).


 
V. 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, you would then provide the web site address to the file. For example:
http://www.indiana.edu/~account/info.php

It will output information about the current state of PHP, which includes information about PHP compilation options and extensions, the PHP version, server information and environment (if compiled as a module), the PHP environment, OS version information, paths, master and local values of configuration options, HTTP headers, and the PHP License. Because every system is setup differently, phpinfo() can be used to check configuration settings and for available predefined variables on a given system . For more information see php.net's entry for phpinfo .


 
VI. 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 will need to place the php.ini file in each subdirectory that has php scripts.

In that php.ini file you can specify the memory_limit you wish to set by using:

memory_limit = whatever integer you wish
You can verify the memory_limit has changed by creating a php info file.
 
VII. Resources: Links to PHP Information