2

having some issues getting PHP working and it's really frustrating.

I installed PHP from here: http://php-osx.liip.ch/

I have read and reviewed all of the tips/troubleshooting here: PHP code is not being executed, instead code shows on the page

I have: uncommented the LoadModule for php

I have: added the command/line that makes files saved as .php be interpreted as php

I have: restarted apache, stopped and started apache

When I go to localhost/test.php I see the raw source code from my php file:

<!doctype html>
<html> 
<head>
<title> PHP Test </title>
</head>
<body>
<p>This is an HTML line. </p>
<?php echo “<p> This is a PHP line</p>”;
phpinfo();
?>
</body>
</html>

Any guidance appreciated!

Community
  • 1
  • 1
Bricky
  • 2,572
  • 14
  • 30
  • Welcome to Stack Overflow. What do your Apache Error logs show? – Twisty Oct 13 '15 at 17:27
  • OS X comes with PHP preinstalled. There's no need for another installation. – Evert Oct 13 '15 at 18:36
  • 1
    OS X comes with an *old* version of PHP (5.5.27 in the case of El Capitan). There's always a need to install a newer version with OS X. – Jeffwa Oct 13 '15 at 20:39

2 Answers2

7

Uncomment the following too from httpd.conf

LoadModule rewrite_module libexec/apache2/mod_rewrite.so

Try that and with already uncomment Loadmodule for php, it should work LoadModule php5_module libexec/apache2/libphp5.so

then restart apache

I have faced the similar issue and then this fixed it.

sudo apachectl restart

More detail can be found from url: http://coolestguidesontheplanet.com/get-apache-mysql-php-and-phpmyadmin-working-on-osx-10-11-el-capitan/

adang
  • 547
  • 4
  • 14
  • 1
    I have the same problem... That line is uncommented and so is the mod_rewrite.. I have verified that php does work on the command line. Any other ideas? – Christian Vermeulen Apr 14 '16 at 13:15
  • 1
    This is applicable on Mac Sierra too – adang Oct 15 '16 at 06:53
  • For MacOS Mojave refer https://stackoverflow.com/questions/52609414/apache-not-working-after-macos-mojave-update/52640238#52640238 – adang Oct 04 '18 at 06:28
1

I did

$ sudo mv /private/etc/apache2/other/+php-osx.conf   ~/Desktop
$ sudo apachectl start

and its working for me.

muTheTechie
  • 1,443
  • 17
  • 25
  • Nice THANK YOU SO MUCH! I've been struggling with this all week and these two terminal commands fixed it for me. Why does it work? – Nathaniel Flick Jul 07 '17 at 14:23