PHP

Lightweight PHP Framework

I was looking for a lightweight PHP framework. Some projects just don't want the frameworks with heavy footprint, like zend does. 

PHP Fat-Free Framework may be the one that wins in this category. I will post some update after I try it out.

Gentoo Allows Switching PHP Version

Maybe they had it before, but I just noticed this today, that we can install more than one versions of PHP, and then use eselect to switch the version.

In short, we can set in /etc/make.conf:

PHP_TARGETS="php5-3 php-5-2"
PHP_INI_VERSION=production

Then call eselect to see what php versions we have available in apache:

# eselect php list apache2 

Without "PHP_INI_VERSION=production", a dev version of php.ini will be installed.

Search for More Recent PHP RPM Packages on CentOS-5

I found this guy http://www.atoomnet.net/php/  offers the RPM and SRPM for the more recent php packages on CentOS.

Another one here: http://www.jasonlitka.com, or http://www.jasonlitka.com/media/SRPMS/ for the SRPM.

  

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"

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.