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.
The homebrew package installer can be used to install Apache 2.0 on MacOS. The installer installs the Apache HTTP server on the location /usr/local/Cellar/httpd . Apache provides a service named as apachectl which needs to be started in order to start Apache.
Verify if apache is running by accessing http://localhost: If you get “This site can't be reached”, you need to start apache, just type, sudo apachectl start and press enter: Verify localhost again: if you see “It works!” apache is running.
Make sure that:
You've followed the instructions from brew info [email protected]
:
==> Caveats To enable PHP in Apache add the following to httpd.conf and restart Apache: LoadModule php7_module /usr/local/opt/[email protected]/lib/httpd/modules/libphp7.so <FilesMatch \.php$> SetHandler application/x-httpd-php </FilesMatch> Finally, check DirectoryIndex includes index.php DirectoryIndex index.php index.html
You restarted Apache via sudo apachectl restart
.
For step by step tutorial, see: Setup Apache, MySQL and PHP using Homebrew on macOS Sierra.
When something doesn't work, check the logs in real-time via:
tail -f /usr/local/var/log/apache2/*error*
Then start/restart the server.
Note: When finished, hit Control-C to quit tail
.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With