9

So, I added the following to my http.conf file:

Listen443

NameVirtualHost *:443

<VirtualHost *:443>
    DocumentRoot /PATH_TO/www
    ServerName www.domain.com
    SSLEngine on
    SSLCertificateFile /PATH_TO/domain.crt
    SSLCertificateKeyFile /PATH_TO/domain.key
    SSLCertificateChainFile /PATH_TO/intermediate.crt
</VirtualHost>

https://www.domain.com works now, but it displays the PHP source code? What could be the reason for this?

  • What is your Apache version, what platform are you running on and are you running PHP as a module or CGI? – DaveRandom Aug 31 '11 at 22:08
  • Module, but I already got it working thanks to pst. But thanks for your help anyways, Dave! –  Aug 31 '11 at 22:14
  • 1
    Possible duplicate of [PHP code is not being executed, instead code shows on the page](https://stackoverflow.com/questions/5121495/php-code-is-not-being-executed-instead-code-shows-on-the-page) – John Conde Oct 24 '18 at 17:00

4 Answers4

6

"Server configuration error" is the reason ;-)

It is choosing to serve PHP files as "plain content" instead of handing them to a PHP engine for processing. This doesn't have anything to do with SSL (it will just as happily send the "plain content" over a secure connection).

From PHP: Installation:

AddModule mod_php.c
LoadModule php_module         modules/mod_php.so
LoadModule php5_module        modules/libphp5.so
AddType application/x-httpd-php .php

And from PHP pages won't load:

AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps

See a pattern? :-) In any case, read the fine installation instructions for the particular platform/server.

Happy coding.

  • That worked thanks! :) I just tried to install SSL, and I never saw anyone mention to add these lines. –  Aug 31 '11 at 22:09
  • I just had to install libapache2-mod-php on an Ubuntu based Linux liked explained here https://stackoverflow.com/questions/12142172/apache-shows-php-code-instead-of-executing#comment65841862_12142315 – baptx Oct 11 '17 at 09:27
5

It could also be that your php.ini configuration is set to not parse code between short php tags.

Alex
  • 556
  • 5
  • 8
  • AWESOME!! Thank you!! Ran into this problem when I ported my site to a local server. I never even realized I accidentally used the shorttags in one of my files! – JamesHoux Nov 20 '12 at 10:05
0

In centos this can happen because of php-module missing, to fix that issue we have to install

sudo yum install php-mysql php-devel php-gd php-pecl-memcache php-pspell php-snmp php-xmlrpc php-xml

Md Azaharuddin Ali
  • 1,889
  • 17
  • 13
0

Just type LOCALHOST in your browser. then it will open the http://localhost/htdocs/ location. then navigate to your php file. It will open accordingly.

Suresh Dooly
  • 47
  • 2
  • 7