1

Upgraded to OS X Yosemite and now my virtualhosts are spitting out the PHP file contents instead of executing the file.

This works correctly:

http://localhost 

This spits out the file contents onto the screen:

http://localhost/~MYUSERNAME

<?php phpinfo();

http://testing.dev spits out the

<?php and the contents of this file (which is WordPress)

apachectl -t

Syntax OK

/etc/apache2/extra/httpd-vhosts.conf

<VirtualHost *:80>
    ServerName localhost
    DocumentRoot /Library/WebServer/Documents/
</VirtualHost>

<VirtualHost *:80>
    ServerName testing.dev
    ServerAlias www.testing.dev
    DocumentRoot "/Users/*/Sites/testing"
    ErrorLog "/private/var/log/apache2/testing.dev-error_log"

    <Directory "/Users/*/Sites/testing-env/">
         Options Indexes FollowSymLinks
         AllowOverride AlL
         Order allow,deny
         Allow from all
    </Directory>
</VirtualHost>

/etc/hosts

##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
127.0.0.1       localhost
255.255.255.255 broadcasthost
::1             localhost
fe80::1%lo0     localhost
127.0.0.1       testing.dev

Why is it spitting out the PHP file instead of executing it?

running php -v gives me

PHP 5.5.3 (cli) (built: Aug 28 2013 13:28:31)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2013 Zend Technologies
   with Xdebug v2.2.2, Copyright (c) 2002-2013, by Derick Rethans

error log shows:

[Mon Nov 17 17:30:08.338143 2014] [auth_digest:notice] [pid 3633] AH01757: generating secret for digest authentication ...
[Mon Nov 17 17:30:08.339341 2014] [mpm_prefork:notice] [pid 3633] AH00163: Apache/2.4.9 (Unix) PHP/5.5.14 configured -- resuming normal operations
[Mon Nov 17 17:30:08.339391 2014] [core:notice] [pid 3633] AH00094: Command line: '/usr/sbin/httpd -D FOREGROUND'
TonyaGM
  • 65
  • 7
  • From what I recall from my upgrade, it didn't keep my version of the file around, so I just restored it from a backup to check the differences. In [my earlier answer to virtually the same question](http://stackoverflow.com/a/6790666/300836) all I had to do was reinstate the LoadModule line, restart apache, and I was good to go. (Though to get the virtual hosts working, I'd have thought, from memory, you'd also need to uncomment the line that includes the `http-vhosts.conf`...) – Matt Gibson Nov 17 '14 at 22:07
  • And your file is definitely named with a PHP file extension? Anything in the apache error log? Even if the syntax is right, it might be throwing an error when trying to load the extension module, but still starting up. – Matt Gibson Nov 17 '14 at 22:13
  • @MattGibson I posted the error log. It says PHP/5.4.14 configured, but when I do php -v, it shows 5.5.3. Could this be the problem? – TonyaGM Nov 17 '14 at 23:34
  • No. `php -v` will be running whichever CLI version of PHP happens to be earliest in your path (to find out where the version you're running is installed, use `which php`.) I'm guessing that it's just picking up Mavericks' /usr/bin/php, which will probably be higher in your path than your custom version installed in /usr/local. I can't see that that's got much to do with the php module that you're using with Apache. – Matt Gibson Nov 17 '14 at 23:37
  • /usr/local/php5/bin/php – TonyaGM Nov 17 '14 at 23:39
  • @MattGibson even attempting to run phpunit tosses errors for PHP Warning: mysqli_real_connect(): (HY000/2002). – TonyaGM Nov 17 '14 at 23:40

2 Answers2

1

Upgrading OS X restores the Apache configuration files to their defaults. You’ll need to edit them again. From memory, this includes:

  • un-commenting the PHP handler so Apache executes files rather than serving them
  • Setting AllowOverride to All for your web root directory
  • un-commenting the line that loads the VirtualHosts configuration file
Martin Bean
  • 38,379
  • 25
  • 128
  • 201
  • In /etc/apache2/httpd.conf I do have this line uncommented: LoadModule php5_module libexec/apache2/libphp5.so. I wonder though as I'm using a local, older PHP version 5.5.3, if I had something different in this file previously before the upgrade. Now I just have to locate the backup of it to compare. – TonyaGM Nov 17 '14 at 22:03
  • You did restart apache after reinstating the PHP LoadModule, right? That's all I had to do when I got it working... – Matt Gibson Nov 17 '14 at 22:05
  • 1
    @MattGibson Yes, I did, actually several times. – TonyaGM Nov 17 '14 at 22:07
0

I had the same issue and found there was a missing configuration section in my httpd.conf. After adding the following and restarting Apache PHP files were processed correctly.

<IfModule php5_module>
        AddType application/x-httpd-php .php
        AddType application/x-httpd-php-source .phps
        <IfModule dir_module>
                DirectoryIndex index.html index.php
        </IfModule>
</IfModule>