Installing and configuring PHP

PHP is often used as part of a LAMP installation to accommodate a web application such as a CMS.

INSTALLING PHP
PHP should be installed out of the box on a remote web hosting account, but if you are setting up your own server you will have to install it yourself. First, install and test Apache and MySQL. Then use your distribution’s package management tool to install PHP. Distributions have different names for the appropriate packages; examples include:

  • Mandriva 2010.2: task-lamp-php
  • Ubuntu 12.10: php5

CHECKING YOUR INSTALLATION
Whether PHP was installed by your web host or you did it yourself, confirm that it is working with a phpinfo.php file. If PHP is working you will see a report of its current configuration. The first thing you should check is the value of “Server API”. If the value is “CGI”, that means the server is running PHP as a CGI module. If the value is “Apache”, that means ther server is running PHP as an Apache module. Both are valid methods to run PHP but how we configure it requires us to know which method is being used.

CONFIGURING PHP
You will usually have to configure your PHP installation. Many PHP applications recommend or require a particular configuration. If your PHP installation will be used in an insecure environment such as a world-accessible web server, security and common sense demand that you not use the insecure default configuration. And if you are setting up a local server for testing purposes, you will want to duplicate whatever configuration the production server will require.

Use phpinfo.php as described above to view the current configuration, and then make changes as required. You can change PHP’s configuration in either php.ini or in .htaccess depending upon how your server runs PHP and whether or not you have complete control of your server. My own preference is to use php.ini for PHP configuration and keep .htaccess free of non-Apache stuff. Whatever your preference, be consistent: you don’t want the headache of a system with PHP configuration split across multiple files.

Using php.ini
Using php.ini is an option if you have complete control of your server, or if your remote server runs PHP as a CGI module. Changes to the system php.ini (often found at /etc/php.ini) are effective system wide. This is the only file on local installations that I have had success in editing. Changes to the account php.ini (often found at apache_docroot/cgi-bin/php.ini) are effective account wide. This is the file I usually edit on a remote installation, although not all hosting companies implement this. Changes to a php.ini elsewhere in the Apache docroot are said to affect only that directory and are not recursive, although I have yet to find a hosting company that implements this.

As root, back up the original php.ini file with a different name such as php-original.ini. Open php.ini for editing, change values as needed, and save. Here’s a simple example php.ini:

[PHP]
; Example php.ini for Joomla on a shared hosting account

disable_functions = show_source, system, shell_exec, passthru, exec, popen, proc_open
display_errors = Off
output_buffering = Off

; Joomla Extension Manager requires this
allow_url_fopen = On

; Set basedir to (1) Apache docroot and (2) backup directory outside docroot
open_basedir = /home/USER/public_html:/home/USER/backup

; Define temporary directory for uploads
upload_tmp_dir = /home/USER/public_html/tmp

; Per-extension configuration needed per documentation or experience
; CiviCRM
memory_limit = 64M

Regarding the open_basedir variable, my web host’s environment uses a colon to separate values. Your host’s environment may differ.

Once you’ve made your changes to php.ini, restart apache and reload phpinfo.php in your browser to confirm that the new values have taken.

Using .htaccess
Using .htaccess is an option if you have complete control of your server, or if your remote server runs PHP as an Apache module. Changes to .htaccess (usually found in the Apache docroot) are recursive to subdirectories.

As root, back up the original .htaccess file with a different name such as .htaccess-original. Open .htaccess for editing and add the PHP values in the form:

# Set PHP variables
php_flag display_errors Off
php_flag register_globals Off

Consult your web host for exact syntax. For example, Pair Networks uses “php_flag” as shown, while InMotion Hosting uses “php_value” instead.

REFERENCES
Webhost-specific PHP information
InMotion: Update your local php settings
Site5: Set up a custom php.ini file, Change your PHP Version

Application-specific PHP information
Joomla: PHP configuration instructions, Running PHP as a CGI script or Apache module

Advertisements

About Warren Post

So far: Customer support guy, jungle guide, IT consultant, beach bum, entrepreneur, teacher, diplomat, over-enthusiastic cyclist. Tomorrow: who knows?
This entry was posted in Uncategorized and tagged , , , . Bookmark the permalink.

6 Responses to Installing and configuring PHP

  1. Pingback: Installing and configuring vtiger | Warren's tech notes

  2. Pingback: Installing and configuring Joomla | Warren's tech notes

  3. Pingback: Installing MySQL locally | Warren's tech notes

  4. Pingback: Backing up a Joomla site with Akeeba Backup | A maze of twisty little passages

  5. Pingback: Installing and configuring WebCalendar | A maze of twisty little passages

  6. Pingback: Securing Joomla with GuardXT | A maze of twisty little passages

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s