Thursday, September 22, 2016

osx php7 apache not working

Leave a Comment

I am trying to upgrade to php7 which I installed via homebrew.

In CLI php -v returns

PHP 7.0.10 (cli) (built: Aug 21 2016 19:14:33) ( NTS ) Copyright (c) 1997-2016 The PHP Group Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies 

But for localhost, firefox pops up a problem loading page, and I can't view a localhost/phpinfo.php; if I swap the module lines out back to php5 it works fine.

Here's a pastebin http://pastebin.com/950yC7wA of my apache2/httpd.conf, I have no idea how to go about fixing this.

  • osx version El Capitan 10.11

3 Answers

Answers 1

While Homebrew is an excellent tool, it is unnecessary at times.

I mention in my posts on Installing Apache, PHP, and MySQL on Mac OS X, OS X comes with Apache and PHP pre-installed. As such, you simply have to configure and enable them.

Unfortunately, as of Mac OS 10.11 (El Capitan), the PHP version is still 5.5. I imagine this will change with 10.12 (Sierra) since PHP 5.5 is EOL. However, it may only be PHP 5.6.

For installing PHP 7, I recommend using PHP OSX. They offer package installs for PHP versions 5.3 to 7.1 (latest). It's available for Mac OS 10.6+ (Snow Leopard).

Since it is a package install, it works out of the box with the default Apache install. You'll only need to update your PATH and modify their PHP ini file. Both of which are outlined in their FAQ.

If you want a more step by step tutorial, check out my recent post on Updating PHP on Mac OS X.

Answers 2

Running $ apachectl -t will show any issues with your current configuration. When I ran it I got this:

httpd: Syntax error on line 171 of /private/etc/apache2/httpd.conf: Cannot load /usr/local/opt/php70/libexec/apache2/libphp7.so into server: dlopen(/usr/local/opt/php70/libexec/apache2/libphp7.so, 10): Symbol not found: _ldap_control_find\n Referenced from: /usr/local/opt/php70/libexec/apache2/libphp7.so\n Expected in: /System/Library/Frameworks/LDAP.framework/Versions/A/LDAP\n in /usr/local/opt/php70/libexec/apache2/libphp7.so

I can confirm this workaround posted on github, installing the package without LDAP support will prevent this error:

brew reinstall php70 --without-ldap 

Answers 3

Not a direct solution to your problem, but I've had countless issues with php on OS X. Most recently was trying to get OCI libraries working after upgrading to El Capitan.

I've given up trying to use it now and began using docker for my development. I find it as a far better solution and you can even set up multiple environments on the same code base which is really useful for testing different versions.

Docker is really easy to set up on OS X, and has a huge range of prebuilt containers available in the repository, you just install and set the mount point to your source directory and use the port it gives you to access.

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment