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.

[ Submitted by John on Tue, 2008-08-12 16:13. | | ]

Thanks, exactly what I was

Thanks,

exactly what I was searching for...

[ Submitted by Lars Pohlmann (not verified) on Tue, 2008-09-23 09:24. | ]

Life saver! Never used RHEL

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!

[ Submitted by Anonymous (not verified) on Fri, 2009-10-16 13:39. | ]

Thanks !

Thanks !

[ Submitted by Seb (not verified) on Tue, 2011-02-22 07:09. | ]

Nice Post

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 ^_^ ...

[ Submitted by Tono (not verified) on Tue, 2011-03-01 04:12. | ]

Joining the crowd...

... to thank you ;-)

[ Submitted by SergeW (not verified) on Mon, 2011-08-08 03:14. | ]

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

CAPTCHA
This question tests your humanity.