PHP configuration

PHP can vary between OS distributions; see the documentation specific to your installation of PHP.

  1. First determine which php.ini file is in use by the PHP Apache module. Note that it may not necessarily be the same php.ini file that is in use when calling PHP from the command line (running php --ini from the command line reports this).

    If you're having trouble determining which php.ini the PHP Apache module is using, create a PHP file that can be served through Apache with the following contents:

    <?php phpinfo();?>
    

    Point your browser to this file and look for this table row in the resulting table:

    Loaded Configuration File
    
  2. Ensure that date.timezone is set correctly for your system.

    Some distributions do not make a default timezone available to PHP, so the best practice to set the timezone for PHP explicitly. See the list of supported timezones.

    An example date.timezone setting in php.ini:

    date.timezone = America/Vancouver
    
  3. Verify that the iconv, json, and session extensions are present.

    They are usually enabled by default, although you may have to install packages for them through your OS distribution. Verify they are present by searching for their respective names in the phpinfo output above.

  4. Enable P4PHP, the Perforce extension for PHP:

    For Swarm to communicate with a Helix Versioning Engine, it needs the P4PHP extension. Swarm comes with a number of variants of the P4PHP binary, for Linux platforms (32- and 64-bit) and Mac OS X (Darwin), and for PHP 5.3, 5.4, and 5.5.

    Note

    For Linux, the default variants are compiled with glibc 2.11. We have also included PHP 5.3 variants compiled with glibc 2.3.3 to support those customers on older distributions, such as Red Hat Enterprise Linux 5.9.

    To enable P4PHP, edit the web server's php.ini file and add the following line:

    extension=/path/to/swarm/p4-bin/bin.<platform>/perforce-<variant>.so
    

    Example 1: for a 64-bit Linux system running PHP 5.4:

    extension=/path/to/swarm/p4-bin/bin.linux26x86_64/perforce-php54.so
    

    Example 2: for a 32-bit Linux system running PHP 5.3 with glibc older than 2.11:

    extension=/path/to/swarm/p4-bin/bin.linux26x86/perforce-php53-glibc2.3.3.so
    

    Alternatively, copy the extension file to the default location for PHP extensions, and then just add this line instead:

    extension=perforce-<variant>.so
    
  5. Restart Apache for the changes to become active.

  6. To verify that P4PHP is active, navigate to the phpinfo file you created above. You should then see a perforce section (search for "Perforce Module"). It should report that the module is enabled and display the version information.

Note

Be aware that any operating system upgrades on the machine hosting Swarm may involve updates to PHP. If this occurs, the php.ini needs to be updated to point to the correct variant of P4PHP to match the version of PHP that the upgraded operating system is using.

Alternative PHP Cache (APC) extension for PHP

APC is a free, open, and robust framework for caching and optimizing PHP intermediate code. Enabling APC improves Swarm performance by caching Swarm's compiled bytecode.

  1. We recommend that you install APC from your OS distribution, via apt-get, yum, etc. If your distribution does not offer the APC package for PHP, do so via PECL (although you may have to resolve system dependencies):

    $ sudo pecl install apc
    
  2. Verify that APC is enabled in your PHP Apache module's php.ini file (as determined in the section above for P4PHP). You may need to add the following line:

    extension=apc.so
    
  3. Restart Apache for the changes to become active.

  4. To verify that APC is active, navigate to the phpinfo file you created above. You should then see an apc section (you may have to search for "APC Support"). It should report its version information and a table for its directives.

    We currently do not have any specific recommendations for which APC directives to set.

    Warning

    Once you have completed installing and enabling P4PHP and APC, we recommend that you remove the phpinfo file you created to avoid disclosing information about your installation.

Zend OPCache extension for PHP

Zend OPCache, like APC, improves PHP performance by storing compiled PHP code into a cache, removing the need for PHP to load and parse scripts on each request.

Zend OPCache is bundled with PHP 5.5.x, and is recommended for use instead of APC. For PHP versions 5.3 and 5.4, Zend OPCache is not bundled, but is available via PECL.

Install Zend OPCache

  1. We recommend that you install Zend OPCache from your OS distribution, via apt-get, yum, etc. If your distribution does not offer the Zend OPCache package for PHP, do so via PECL (although you may have to resolve system dependencies):

    $ sudo pecl install zendopcache
    
  2. Verify that Zend OPCache is enabled in your PHP Apache module's php.ini file (as determined in the section above for P4PHP). You may need to add the following line:

    zend_extension=/path/to/opcache.so
    
  3. Restart Apache for the changes to become active.

  4. To verify that Zend OPCache is active, navigate to the phpinfo file you created above. You should then see a Zend OPcache section. It should report its version information and a table for its directives.

    We currently do not have any specific recommendations for which Zend OPCache directives to set.

    Warning

    Once you have completed installing and enabling P4PHP and Zend OPCache, we recommend that you remove the phpinfo file you created to avoid disclosing information about your installation.

Enable Zend OPCache

For PHP 5.5+, while Zend OPCache is included, it may not be enabled. If you choose to use it, you may need to add the following line to your PHP Apache module's php.ini file:

opcache.enable = 1

If you have edited php.ini, ensure that you restart Apache for the changes to become active.

ImageMagick (imagick) extension for PHP

Imagick is a PHP extension that integrates the ImageMagick graphics library's API for the creation and manipulation of images. Enabling Imagick improves Swarm's ability to preview graphics formats that web browsers typically cannot display.

  1. We recommend that you install Imagick from your OS distribution, via apt-get, yum, etc. If your distribution does not offer the imagick package for PHP, do so via PECL (although you may have to resolve system dependencies):

    $ sudo pecl install imagick
    
  2. Verify that imagick is enabled in your PHP Apache module's php.ini file (as determined in the section above for P4PHP). You may need to add the following line:

    extension=imagick.so
    
  3. Restart Apache for the changes to become active.

  4. To verify that imagick is active, navigate to the phpinfo file you created above. You should then see an imagick section. It should report its version information and a table for its directives, supported image file formats, and more.

    Warning

    Once you have completed installing and enabling P4PHP and imagick, we recommend that you remove the phpinfo file you created to avoid disclosing information about your installation.