5

I'm using an iMac which I've just updated to macOS Sierra. Prior to this it was running El Capitan.

Under my El Capitan set up I had Apache, PHP and MySQL configured as per this guide. This worked without any problems.

When I updated to Sierra it overwrote a load of config files. So I went back through the guide and configured everything as I had under El Capitan.

http://localhost is working as I'd expect and I can see files in my webroot. However, if I open a PHP page, it just shows the raw PHP code rather than executing it.

I'm using the following:

Apache

  • Server version: Apache/2.4.23 (Unix)
  • Server built: Aug 8 2016 16:31:34

PHP

  • PHP 7.0.10 (cli) (built: Aug 31 2016 10:25:51) ( NTS )

macOS

  • Sierra 10.12
Giacomo1968
  • 58,727
Andy
  • 163

5 Answers5

24

Sierra comes with PHP 5, not PHP 7. Anyway, check if the module is loaded in httpd.conf:

LoadModule php5_module libexec/apache2/libphp5.so

If this doesn't work, probably you didn't told Apache to recognize *.php files as php executables. To do so, locate and edit httpd.conf and add the following lines (if not already present):

<FilesMatch .php$>
    SetHandler application/x-httpd-php
</FilesMatch>

and edit the DirectoryIndex parameter:

<IfModule dir_module>
    DirectoryIndex index.php index.html
</IfModule>

Another common solution is to activate the short open tags (if you have any in your PHP code). Locate php.ini, search for the string short_open_tag = Off and change it to short_open_tag = On.

Restart Apache.

pietrop
  • 366
3

Your apache isn't processing php files any more. There is line

LoadModule **php5_module** libexec/apache2/**libphp5.so**

in your config file /etc/apache2/httpd.conf

But you have installed PHP7. Change it to:

LoadModule **php7_module** libexec/apache2/**libphp7.so**

or maybe modules/mod_php.so or whenever php module is located.

1

Ensure the #LoadModule php5_module libexec/apache2/libphp5.so line is uncommented in the main httpd.conf file. Don't forget to restart Apache sudo apachectl restart.

-1

I had this problem as well. Check your /private/ect/apache2/extra/htttpd-vhosts.conf to see if still has your virtual hosts settings. My original one was renamed to httpd-vhosts.conf~previous.

curt
  • 119
  • 4
-1

You cannot open the .php file using open file from the browsers File menu, You have to type localhost/info.php(or whatever file and path you're trying to open) in your browsers address bar... This works for me at least. Hope you work it out.