Wednesday, June 29, 2011

Issue in APC

Site seems to function without issues, but our error logs just fill with the following PHP errors after enabling APC.

PHP Notice: include() [function.include]: 1. h->opened_path=[null] h-

Windows Server 2008 R2
Apache 2.2
PHP 5.2.17 THREAD-SAFE VC6

For this just changed the error_reporting variable in php.ini to -

error_reporting = E_ALL & ~E_DEPRECATED & ~E_NOTICE

I am getting an error saying The mysql driver is not currently installed

PDO, unlike the mysql_* functions, supports a number of database engines. To do this it needs a driver library for each one.

You have the "core" of PDO installed but not the MySQL driver - just get that installed (called pdo_mysql) and everything will be OK.

Your php.ini should have one of these (windows or linux):

extension=php_pdo_mysql.dll
extension=php_pdo_mysql.so

Enable Short tags in PHP

you need to turn on short_open_tags.

short_open_tag = On

Restart apache..

Friday, June 17, 2011

Install Mcrypt in linux

Command to install Mcrypt is as usual

sudo apt-get install php5-mcrypt
sudo /etc/init.d/apache2 restart

You can install Mcrypt from the PHP Source Tree as a module if you choose.

You first need to ensure you have libmcrypt, libmcrypt-devel, and mcrypt installed, then do:

# cd php-5.x.x/ext/mcrypt
# phpize
# aclocal
# ./configure
# make && make install

Enable the module by adding: 'extension=mcrypt.so' to PHP.ini.
Now restart Apache and you can see Mcrypt working :)

Install APC for PHP on Linux

APC is the Alternative PHP Cache, which is a free, open, and robust framework for caching and optimizing PHP intermediate code. What this means is that APC reads your PHP files, parses them into a more efficient binary format and then caches them in memory so that each request for your PHP files and PHP library files can be fed from the parsed cache. This will generally lead to a speed increase when serving a PHP site, especially one with a lot of library files. This post looks at how to install APC for PHP on Linux. The Linux distribution I used was CentOS 5, but it should be fairly similar for most distros.

First of all you need to download the APC code from the PHP PECL library. So change directory to somewhere like /tmp and then get the latest version like so:

$ wget http://pecl.php.net/get/APC
This will always get the latest version, and in my case when I installed it just now downloaded APC-3.0.16.tgz like so:

Now you need to extract the files:

$ tar -zxf APC-3.0.16.tgz

and change into the APC directory:

$ cd APC-3.0.16
The next step is to run the "phpize" command. This requires that you have PHP development package installed. On CentOS this is php-devel (installed by running "yum install php-devel") and it should have a similar name on other Linux distros.

$ phpize
Configuring for:
PHP Api Version: 20041225
Zend Module Api No: 20050922
Zend Extension Api No: 220051025
You then configure APC, telling it where the executable file php-config is. If you don't know where this is, then do this:

$ whereis php-config

which will return something like:

php-config: /usr/bin/php-config /usr/share/man/man1/php-config.1.gz

and then run the configure command like so:

./configure --enable-apc --enable-apc-mmap --with-apxs --with-php-config=/usr/bin/php-config



$ make


$ make install


/etc/init.d/httpd restart
The APC cache will now be enabled. You can confirm this by creating a script which calls the phpinfo() command and looking for the APC section. It will have been switched on by default by adding a "extension=apc.so" line to your /etc/php.ini file, but you may want to add more settings to configure it more. The INSTALL file suggests this (I have put the default values at the end of each line which is what is set if you don't set anything in the php.ini file):

apc.enabled=1 # default = 1
apc.shm_segments=1 # default = 1
apc.shm_size=128 # default = 30
apc.ttl=7200 # default = 0
apc.user_ttl=7200 # default = 0
apc.num_files_hint=1024 # default = 1000
apc.mmap_file_mask=/tmp/apc.XXXXXX # default = no value
apc.enable_cli=1 # default = 0

And that's all there is to it. There is also a monitoring script available so you can see what's being cached and how much memory is being used etc.

Tuesday, June 14, 2011

APC with PHP 5.3 on Xamp Windows

The php_apc.dll version 3.1.3 in 1.7.3 is for php version 5.3.1 and so would not be compatible.

You could download this file:
php_apc-3.1.5-5.3-vc6-x86.zip
from here:
http://downloads.php.net/pierre/
which may be more compatible.

Just follow the procedure to include that you used with the one you copied from XAMPP 1.7.3.