Apache 2.4 on Amazon Linux (roughly equivalent to RH 7, I suppose), with various versions of PHP.

I'm having an issue trying to get PHP CGI scripts running on my webserver when SSL is enabled. For example:


gives the proper output, but when I enable SSL (i.e, https://52.example.com), I get a 404 error:

The requested URL /php-fcgi/php-cgi-5.2.17/phpinfo.php was not found on this server.

Here are the contents of the 52.conf file in my /var/www/vhosts directory:

 <VirtualHost *:443>

    ServerName 52.example.com

    DocumentRoot /var/www/vhosts/52

 <Directory "/var/www/vhosts/52/">

     AddHandler php-cgi .php
     Action php-cgi /php-fcgi/php-cgi-5.2.17

    <FilesMatch "\.php$">
            Options ExecCGI
            SetHandler php-cgi

where site.conf is a virtual host definition.

And here are the contents of the php-cgi-5.2.17 file:


export PHPRC



# which php-cgi binary to execute
exec /opt/phpfarm/inst/php-${version}/bin/php-cgi

As you can probably tell, I'm using PHPFarm to server different versions of PHP to different subdomains.

Note that I don't know for sure that SSL is the cause of my grief, but it seems awfully suspicious.

If anyone has any thoughts or ideas I would be eternally grateful. Thanks in advance.


Apache by default uses a different host config file for the default ssl server. And I don't see any reference to SSL in the snippets of your config that you posted....

So.. it is probably falling back to whatever default host is defined and is pointing at the wrong DocumentRoot.

Run apache2ctl -S to see what names/aliases, addresses, and ports are in play as it is currently running. It will also tell you what config file defines it and what line the definition starts on.

VirtualHost configuration:      is a NameVirtualHost
         default server example.com (/etc/apache2/sites-enabled/example.com.conf:1)
         port 443 namevhost example.com (/etc/apache2/sites-enabled/example.com.conf:1)
                 alias www.example.com
         port 443 namevhost mail.example.com (/etc/apache2/sites-enabled/mail.example.com.conf:1)
         port 443 namevhost ww2.example.com (/etc/apache2/sites-enabled/ww2.example.com.conf:1)
*:80                   is a NameVirtualHost
         default server www.example.com (/etc/apache2/sites-enabled/000-default.conf:2)
         port 80 namevhost www.example.com (/etc/apache2/sites-enabled/000-default.conf:2)
                 alias example.com
         port 80 namevhost ww2.example.com (/etc/apache2/sites-enabled/000-default.conf:7)
         port 80 namevhost mail.example.com (/etc/apache2/sites-enabled/000-default.conf:11)

Edit to include an example of a host definition wtih SSL directives pointing to a letsencrypt certificate with a redirect for the same site on http to bounce them to https -

    ServerName example.com
    ServerAlias www.example.com
    ServerAdmin webmaster@example.com
    SSLEngine on
    SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem
    SetEnvIf User-Agent ".*MSIE.*" nokeepalive ssl-unclean-shutdown
    DocumentRoot /var/www-example.com
    <directory /var/www-example.com>
        Options All
        AllowOverride All
        Require all granted
    ErrorLog ${APACHE_LOG_DIR}/ssl-example.com-error.log
    CustomLog ${APACHE_LOG_DIR}/ssl_request_log "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
    CustomLog ${APACHE_LOG_DIR}/ssl-example.com-access.log combined
<VirtualHost *:80>
   ServerName example.com
   ServerAlias www.example.com
   Redirect permanent / https://www.example.com
  • Thanks for the reply. Unfortunately, the first line of my VirtualHost definition got cut off, where it shows <VirtualHost *:443>. I tried making some changes to this file, which is 52-le-ssl.conf, but it was all in vain. I've edited my original post to fix this issue. – Richard Scott Crawford Apr 17 '17 at 15:44
  • I'm still not seeing SSL info for certs, etc. in your config. I'm editing my response to show what is in mine using letsencrypt as a CA – ivanivan Apr 18 '17 at 1:53
  • Turns out it was an error in one of my config files. I was led astray by a rogue ScriptAlias directive. I appreciate your answers, though. – Richard Scott Crawford Apr 19 '17 at 15:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.