5.3.9 Enabling the PHP handler for the web server

In some cases, after installing the web server, the PHP handler may not be connected. The connection method depends on the installed web server.

  1. Connect to the server via SSH.
  2. Go to the web server directory:
    cd /etc/httpd/
  3. Check for PHP module:
    ls /etc/httpd/modules/ | grep php

    The output should be something like this:

    libphp*-zts.so
    libphp*.so
  4. Check your Apache configuration files:
    grep -n 'php' /etc/httpd/conf/*
    1. If the previous command did not output anything, check for additional configuration files:
      grep 'Include conf.d\/\*.conf' /etc/httpd/conf/*
      1. If the command also produces no output, edit the Apache configuration file, adding an option to load additional configuration files:
        echo "Include conf.d/*.conf" >> /etc/httpd/conf/httpd.conf
      2. If the command output was like /etc/httpd/conf/httpd.conf:Include conf.d/*.conf, then additional configuration files are included.
      3. Check for the presence of the PHP configuration file:
        ls /etc/httpd/conf*/* | grep php
        1. If the previous command did not output anything, create a configuration file (instead of X specify the PHP version you want):
          cat > /etc/httpd/conf.d/php.conf <<EOF
          <IfModule prefork.c>
            LoadModule phpX_module modules/libphpX.so
          </IfModule>
           
          <IfModule !prefork.c>
            LoadModule phpX_module modules/libphpX-zts.so
          </IfModule>
           
          AddHandler phpX-script .php
          AddType text/html .php
           
          DirectoryIndex index.php
           
          php_value session.save_handler "files"
          php_value session.save_path    "/var/lib/php/session"
          php_value soap.wsdl_cache_dir  "/var/lib/php/wsdlcache"
          EOF
    2. If the command executed in step 4 or 4.1.3 produces a result (usually it will be similar to the text specified in step 4.1.3.1), then compare the PHP versions specified in the configuration file with the result of the command executed in step 3. If they are different, edit the corresponding configuration file and replace the version:
      nano /etc/httpd/conf*/*.conf

      Specify the required version instead of the symbol X in lines like this:

      LoadModule phpX_module modules/libphpX.so
      LoadModule phpX_module modules/libphpX-zts.so
      AddHandler phpX-script .php

      Modify a specific config file depending on the previous step:

      • If the previous step was 4, then you need to edit the file /etc/httpd/conf/httpd.conf.
      • If the previous step was 4.1.3, then you need to edit the file /etc/httpd/conf.d/php.conf.
  5. Restart Apache:
    service httpd restart
    • If the restart was successful, check the PHP functionality on the sites.
    • If errors occur during the restart, check the configuration files for line breaks or incorrect parameters.
Content