Installing APC on RHEL5

Here's how to install APC on RHEL5.

# yum install php-pear php-devel httpd-devel
# pecl install apc
# echo "extension=apc.so" > /etc/php.d/apc.ini
# service httpd restart

Check for the apc section in your phpinfo() page. If it's not there:

# tail /var/log/httpd/error_log
[Tue Aug 12 15:43:59 2008] [notice] Digest: done
PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/lib/php/modules/apc.so' - /usr/lib/php/modules/apc.so: cannot open shared object file: Permission denied in Unknown on line 0

SELinux is preventing the extension from loading, I'll bet. Let's check:

# tail /var/log/messages
Aug 12 15:42:40 mybox yum: Installed: httpd-devel - 2.2.3-11.el5_1.3.i386
Aug 12 15:44:01 mybox setroubleshoot: SELinux is preventing the httpd from using potentially mislabeled files (./apc.so). For complete SELinux messages. run sealert -l 9e4bbfa8-327b-4bb2-94df-f154045a1ef1

Let's view the security contexts for our PHP extensions:

# ls -Z /usr/lib/php/modules
-rwxr-xr-x  root root root:object_r:tmp_t              apc.so
-rwxr-xr-x  root root system_u:object_r:textrel_shlib_t dbase.so
-rwxr-xr-x  root root system_u:object_r:textrel_shlib_t gd.so
...

Yup. Notice how the security context is missing (it's tmp_t for apc.so). Let's fix that.

# restorecon /usr/lib/php/modules/apc.so
]# ls -Z /usr/lib/php/modules
-rwxr-xr-x  root root system_u:object_r:textrel_shlib_t apc.so
-rwxr-xr-x  root root system_u:object_r:textrel_shlib_t dbase.so
-rwxr-xr-x  root root system_u:object_r:textrel_shlib_t gd.so
...

Now let's try again:

# service httpd restart

Yay!

P.S. On x86_64, apc.so is in /usr/lib64/php/modules.

Comments

Thanks,

exactly what I was searching for...

Life saver!

Never used RHEL before and I keep forgeting about SeLinux.

Installing APC, 1.5 minutes.
Figuring out SeLinux was the problem, 45 minutes.
Fixing it after finding this post, 0.5 minutes.

Thanks!

Thanks !

Thanks,

You really help me, a whole day facing this kind of problem, finally I found your post....my problem was solve in a minute.

p.s. Using CentOS for first time ^_^ ...

... to thank you ;-)