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
Answer
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):
SetHandler application/x-httpd-php
and edit the DirectoryIndex
parameter:
DirectoryIndex index.php index.html
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.
Comments
Post a Comment