1

PHP, WHM, and several other services are already installed on a CentOS x64 server I am trying to migrate data to. Many of my existing PHP scripts are dependent on PHP's apache_request_headers() function, which the current server's PHP configuration does not support. Apparently, compiling PHP as an Apache module is one solution, but are there other ways to enable this (without uninstalling PHP, reinstalling, etc., and all dependent services), perhaps as easy as modifying php.ini, somehow?

3
  • If not, what is the best process to uninstall PHP and reinstall, especially if there are other services preinstalled that may depend on PHP. (The server is not yet live, still configuring it.)
    – inac
    Jun 21, 2010 at 4:03
  • Won't yum install php help?
    – skarap
    May 12, 2013 at 7:07
  • please add version information for php apache and centos if possible
    – pqnet
    Sep 4, 2014 at 15:04

3 Answers 3

1

The Apache functions are only available if running the httpd SAPI, also known as mod_php.

The stock CentOS PHP packages make mod_php available, so they are enough to allow them. If you need a newer version than the stock packages then you will need to find newer packages somewhere, or you will need to build PHP or the PHP packages yourself with the proper SAPI.

4
  • How do you enable mod_php on a stock CentOS install?
    – inac
    Jun 21, 2010 at 4:35
  • Installing the php package will install mod_php and pull in the httpd package as well. The default configurations for the two, when installed together, enables mod_php. Jun 21, 2010 at 4:53
  • PHP has already been installed - any advice on the best process to uninstall PHP and reinstall, especially if there are other services preinstalled that may depend on PHP. (The server is not yet live, still configuring it.)
    – inac
    Jun 21, 2010 at 10:53
  • I'm guessing you have compiled php from sources, right? You can try to make uninstall, but I'm not sure it will work. If starting from scratch is an option, I'd go with it.
    – skarap
    May 12, 2013 at 8:21
0

Here is documentation on setting up PHP to run under Apache 2. The site also contains info for Apache 1. http://www.php.net/manual/en/install.unix.apache2.php

The most directly relevant items are 6, 7, and 8
6.Setup your php.ini
7.Edit your httpd.conf to load the PHP module.
8.Tell Apache to parse certain extensions as PHP.

4
  • PHP has already been installed - any advice on the best process to uninstall PHP and reinstall, especially if there are other services preinstalled that may depend on PHP. (The server is not yet live, still configuring it.)
    – inac
    Jun 21, 2010 at 11:03
  • These steps (6, 7, 8 ...) address the part of the question where you asked "change PHP into an apache module". Are you focusing on only uninstall/reinstall now?
    – Beel
    Jun 21, 2010 at 12:36
  • I'm trying to work this with the existing install, but after going through 6,7,8 (in 8, skipping "mod_rewrite may be used To allow any arbitrary .php file to be displayed as syntax-highlighted source code, without having to rename or copy it to a .phps file"), my .php / .phps files become interpreted as file downloads, rather than being displayed in the browser.
    – inac
    Jun 21, 2010 at 23:19
  • LoadModule auth_passthrough_module modules/mod_auth_passthrough.so<br /> LoadModule bwlimited_module modules/mod_bwlimited.so<br /> LoadModule frontpage_module modules/mod_frontpage.so<br /> LoadModule php5_module modules/libphp5.so << added in step 7
    – inac
    Jun 21, 2010 at 23:20
0

If you're running PHP as CGI/FastCGI then you don't get the apache_request_headers() (also known as getallheaders()) function.

However...

As of 5.4.0, PHP includes a version of this function which works in FastCGI.

For previous versions of PHP you can roll your own. Though this approach loses case sensitivity for header names (CGI/FastCGI capitalize all header names) it's generally good enough for 99.9% of possible purposes.

This is my code for doing so, written long ago and published under LGPLv3:

if (!is_callable('getallheaders')) {
    # Convert a string to mixed-case on word boundaries.
    function uc_all($string) {
        $temp = preg_split('/(\W)/', str_replace("_", "-", $string), -1, PREG_SPLIT_DELIM_CAPTURE);
        foreach ($temp as $key=>$word) {
            $temp[$key] = ucfirst(strtolower($word));
        }
        return join ('', $temp);
    }

    function getallheaders() {
        $headers = array();
        foreach ($_SERVER as $h => $v)
            if (preg_match('/HTTP_(.+)/', $h, $hp))
                $headers[str_replace("_", "-", uc_all($hp[1]))] = $v;
        return $headers;
    }

    function apache_request_headers() { return getallheaders(); }
}
0

You must log in to answer this question.

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