Linux: enable or disable PHP APC opcode cache for virtual host

1. To install PHP APC module run commands:
# yum install php-devel php-pear pcre-devel
# pecl install apc

2. Example configuration file for APC
# more /etc/php.d/apc.ini
extension=apc.so
apc.enabled=”1″
; [ disable APC opcode cache by default
apc.cache_by_default=0
; ]
apc.shm_segments=”1″
apc.num_files_hint=”1024″
apc.ttl=”7200″
apc.user_ttl=”7200″
apc.gc_ttl=”3600″
apc.cache_by_default=”1″
;apc.filters=””
apc.slam_defense=”0″
apc.file_update_protection=”2″
apc.enable_cli=”0″
apc.max_file_size=”1M”
apc.stat=”1″
apc.write_lock=”1″
apc.report_autofilter=”0″
apc.include_once_override=”0″
apc.rfc1867=”0″
apc.rfc1867_prefix=”upload_”
apc.rfc1867_name=”APC_UPLOAD_PROGRESS”
apc.rfc1867_freq=”0″
apc.localcache=”0″
apc.localcache.size=”512″
apc.coredump_unmap=”0″
;default is 32M
apc.shm_size=512M
apc.mmap_file_mask=”/tmp/apcphp5.XXXXXX”
apc.mmap_address=703687441776
; file uploads progress for Drupal
apc.rfc1867=”1″
#

To check web server Apache configuration run command:
# /sbin/service httpd configtest

To apply new APC module configuration restart web server Apache using command:
# /sbin/service httpd restart

3. Example changes in main .htaccess file for virtual host shkodenko.com
# vim /home/taras/shkodenko.com/public_html/.htaccess

3.1. To enable APC opcode cache for virtual host inside IfModule block add line:

# PHP 5, Apache 1 and 2.
<IfModule mod_php5.c>

# [ enable APC opcode cache for domain
php_flag apc.cache_by_default On
# ]

</IfModule>

3.2. To disable APC opcode cache for virtual host inside IfModule block add line:

# PHP 5, Apache 1 and 2.
<IfModule mod_php5.c>

# [ disable APC opcode cache for domain
php_flag apc.cache_by_default Off
# ]

</IfModule>

3 thoughts on “Linux: enable or disable PHP APC opcode cache for virtual host

  1. Howdy there, I just saw your website via bing, and I must tell that you express interestingly good via your site.
    I am very struck by the way that you write, and the subject is excellent.
    Anyhow, I would also love to acknowledge whether you would love to exchange links with my web portal?
    I will be more than willing to reciprocate and put your link off in the link section.
    Waiting for your response, I give my sincere thanks and enjoy your day!

  2. Lovely blog! I am loving it!! Will be back later to read some more. I am bookmarking your feeds also.
    Werner Johson

Comments are closed.