5.3.9. Enable PHP handler for web server

In some cases, the PHP handler may not be enabled after installing the web server. The method for enabling it depends on the web server you have installed.

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

    The output should look something like this:

    libphp*-zts.so
    libphp*.so
  4. Check the Apache configuration files:
    grep -n 'php' /etc/httpd/conf/*
    1. If the previous command did not return any output, check for additional configuration files:
      grep 'Include conf.d\/\*.conf' /etc/httpd/conf/*
      1. If the command also didn't produce any output, edit the Apache configuration file by adding an option to load additional configuration files:
        echo "Include conf.d/*.conf" >> /etc/httpd/conf/httpd.conf
      2. If the command output was /etc/httpd/conf/httpd.conf:Include conf.d/*.conf, then the additional configuration files have been included.
      3. Проверьте наличие файла конфигурации PHP:
        ls /etc/httpd/conf*/* | grep php
        1. If the previous command didn't produce any output, create a configuration file (replace X with the number of the desired PHP version):
          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 run in step 4 or 4.1.3 produced an output (which will typically resemble the text shown in step 4.1.3.1), compare the PHP versions listed in the configuration file with the output of the command run in step 3. If they differ, edit the corresponding configuration file and replace the version:
      nano /etc/httpd/conf*/*.conf

      Replace the X symbol in the following lines with the appropriate version:

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

      Depending on the previous step, modify the appropriate configuration file:

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