PHP

Install PHP-uploadprogress on CentOS

To install the PECL package uploadprogress on CentOS, we do:

  1. Yum up some packages:
    # yum install php-pear php-devel httpd-devel
  2. Install uploadprogress through PEAR:
    # pear install pecl/uploadprogress
  3. Tell PHP to load uploadprogress:
    # echo extension=uploadprogress.so > /etc/php.d/uploadprogress.ini
  4. Restart Apache:
    # /sbin/service httpd graceful

 

 

Install PHP-APC on CentOS

  1. Yum up some packages:
    yum install make php-pear php-devel httpd-devel
  2. Install APC using pear (the pear installer is smarter than the pecl installer):
    When the installer asks about APXS, say ‘no’. 
    pear install pecl/apc
  3. Tell PHP to load APC:
    echo extension=apc.so > /etc/php.d/apc.ini
  4. Edit the file /etc/php.d/apc.ini, and add the following lines:
    apc.ttl="7200"
    apc.user_ttl="7200"
    apc.shm_segments="3"

PHP Graphing Packages

Configure PHP Securely

Make the following changes to /etc/php.ini:

# Do not expose PHP error messages to external users
display_errors = Off

# Enable safe mode
safe_mode = On

# Only allow access to executables in isolated directory
safe_mode_exec_dir = php-required-executables-path

# Limit external access to PHP environment
safe_mode_allowed_env_vars = PHP_

# Restrict PHP information leakage
expose_php = Off

# Log all errors
log_errors = On

# Do not register globals for input data
register_globals = Off

Install and Configure lighttpd + PHP on Gentoo

Install lighttpd and php

  1. Read http://gentoo-wiki.com/HOWTO_Lighttpd and decide which USE flags you will need. Write those flags into /etc/portage/package.use. Since I plan to use fastcgi and php, I do have at least these two flags set.
  2. Check php installation. If php was installed but cgi USE flag was off, you have to reinstall php with "USE=cgi".
  3. Now install lighttpd:
    # emerge -v lighttpd
  4. Among the few opcode cache for php, xcache is quite stable on lighttpd. So install that:

Tune APC to Improve PHP Performance

Adjust the parameters

Having installed APC for PHP does not automatically improve the performance. You have to adjust the parameters. At the very least, change these values:

apc.ttl="7200"
apc.user_ttl="7200"
apc.shm_segments="3"
apc.shm_size="90"

Setting apc.ttl and apc.user_ttl to none-zero can ensure that the cached php code gets refreshed at the given number of seconds without filling up the memory with stale entries.