1

I have compiled PHP from source and installed it to /opt/php/5.5.15/

I have also installed (with yum) httpd, and mod_fcgid.

I am trying to configure a virtual host to exec php like this:

<VirtualHost *:80>
    ServerAdmin [email protected]
    DocumentRoot /var/www/my-site.example.com/site/public
    ServerName my-site.example.com
    ErrorLog /var/www/my-site.example.com/logs/my-site.example.com-error_log
    CustomLog /var/www/my-site.example.com/logs/my-site.example.com-access_log common
    <Directory /var/www/my-site.example.com/site/public>
        Options +indexes
        AllowOverride all
        Order allow,deny
        Allow from all
        Action application/x-httpd-php /php-5.5.15-bin/php-cgi
    </Directory>
</VirtualHost>

<IfModule mod_fcgid.c>
    IdleTimeout 3600
    ProcessLifeTime 7200
    MaxProcessCount 64
    DefaultMaxClassProcessCount 8
    IPCConnectTimeout 300
    IPCCommTimeout 7200
    BusyTimeout 300

    <FilesMatch ".+\.ph(p[345]?|t|tml)$">
        SetHandler application/x-httpd-php
    </FilesMatch>

    ScriptAlias /php-5.5.15-bin/ /opt/php/5.5.15/bin/

    <Directory "/opt/php">
        AllowOverride None
        Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
        Order allow,deny
        Allow from all
    </Directory>
</IfModule>

I am getting this error:

[Thu Aug 14 17:36:20 2014] [error] [client 127.0.0.1] (13)Permission denied: exec of '/opt/php/5.5.15/bin/php-cgi' failed, referer: http://my-site.example.com:10080/
[Thu Aug 14 17:36:20 2014] [error] [client 127.0.0.1] Premature end of script headers: php-cgi, referer: http://my-site.example.com:10080/

I have tried chmod 777 php-cgi and chown apache:apache php-cgi, both made no difference.

Any ideas?

Note: this setup works fine on Debian

4
  • Do you run SELinux? Try setting it in permissive mode, by changing /etc/selinux/config: SELINUX=permissive After that, reboot the server. Commented Aug 14, 2014 at 10:49
  • Its standard CentOS 6, so presumably so (I will have to check for sure tomorrow). Is there anyway to get around it without doing this, as this is not ideal.
    – Petah
    Commented Aug 14, 2014 at 10:59
  • You can turn on auditing and see what rules are appliend, and then write your own policy which allows Apache user to run binaries from /opt/php/5.5.15/bin That's why it's always smart to use RPM packages and not compile your own stuff. For php 5.5, you can use php55 pacakges from IUS repo: dl.iuscommunity.org/pub/ius/stable/Redhat/6/x86_64 Install epel-release and ius-release manually, and then do yum install php55u-cli php55u-bcmath ... and all the other php plugins you need. Commented Aug 14, 2014 at 12:50
  • @JakovSosic looking in the current audit log it looks like httpd doesn't have exec rights (under SELinux policies) on the php-cgi bin. Any idea on how to allow it? Also the reason for this particular setup and compiling from source is that I need to run multiple version of PHP side by side.
    – Petah
    Commented Aug 14, 2014 at 21:16

1 Answer 1

1

So it turns out SELinux was denying httpd exec rights on the php-cgi bin.

Viewing the /var/log/audit/audit.log showed this.

Running the following allows it:

sudo chcon -t httpd_sys_script_exec_t /opt/php/5.5.15/bin/php-cgi

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .