Ben_hawk
Ben_hawk

Reputation: 2486

OSX Apache using wrong version of PHP

I followed a guide which used home-brew to install the lastest version of php (5.4.8) on OSX Mountain Lion.

I then followed a guide which showed me how to setup and use the pre-installed apache on OSX.

However when I try running up a base Symfony 2 project I get a bunch of errors relating to missing date.timezone in the php.ini.

However I have this correctly setup the php.ini but doing a quick phpinfo() in the Symfony project shows that its using the old preinstalled version of php (5.3) rather than the new one.

In terminal if I type which php & php -v, It shows the correct new version is being used.

enter image description here

But the phpinfo() shows

enter image description here

enter image description here

Upvotes: 29

Views: 25495

Answers (3)

Azzam Jihad Ulhaq
Azzam Jihad Ulhaq

Reputation: 111

Today I have same issue for updating php 7.2 to 7.3 as requirement of Laravel 6. Here is my solution.

  1. Open your httpd.conf file in "/etc/apache2/http.conf"
  2. Search (Ctrl + w) for "LoadModule php"
  3. Uncomment that row
  4. Restart your apache with "sudo apachectl restart"

Then, your php version in local web server (apache2) will be updated

Upvotes: 1

Jason McCreary
Jason McCreary

Reputation: 72991

Apache is not aware of the homebrew version of PHP (i.e. /usr/bin/php). You see it on the command line because you've likely modified your PATH (i.e. /usr/local/bin/php).

You can modify this in your httpd.conf file.

I am not a fan of homebrew or other package libraries. Primarily because Mac OS X is built atop Unix. Furthermore, all but MySQL are installed natively. Here's an article on installing Apache, MySQL, and PHP on Mac OS X.

Disclaimer: I wrote that article.

Upvotes: 4

Bob Fanger
Bob Fanger

Reputation: 29897

Did you follow all the instructions provided in the Caveats?

Run brew info php54 to see them again.

Especially the line:

To enable PHP in Apache add the following to httpd.conf and restart Apache:
LoadModule php5_module /usr/local/Cellar/php54/5.4.8/libexec/apache2/libphp5.so

Upvotes: 80

Related Questions