Prepare Homebrew
brew update
brew doctor
Resolve pending issues, upgrade to latest version of XCode, etc.
Install PostgreSql
It doesn't come any easier than this.
Update PHP
First using Homebrew. I had a typo the first time. The PostgreSql extention didn't get generated. Make sure to read the caveats at the end of the process!
brew tap --repair
brew tap homebrew/homebrew-php
brew install php56 --with-apache --with-mysql --with-postgresql --with-intl
Point php.ini
to the right version.
sudo mv /etc/php.ini /etc/php.ini.pre-update
sudo ln -s /usr/local/etc/php/5.6/php.ini /etc/php.ini
Perhaps without any typos, the PostgreSql php extension gets generated. If the PostgreSql php extension doesn't get generated, these manual instructions are great. Especially if you installed PostgreSql as mentioned earlier in this document, you will need to specify where the installation directory is when you call ./configure
. It should look something like this:
./configure --with-pgsql=/Applications/Postgres.app/Contents/Versions/9.4
http://stackoverflow.com/questions/6588174/enabling-postgresql-support-in-php-on-mac-os-x
Once you know where the pgsql.so
extension resides, make sure it is included in php.ini
. E.g.,
; Mac Extensions
extension=/usr/local/Cellar/php56/5.6.4/lib/php/extensions/no-debug-non-zts-20131226/pgsql.so
Edit Apache's httpd.conf
and make sure that the php
and rewrite
modules are enabled. Also, you will likely need to update the path to the correct php module. You should use the new libphp5.so
that got generated when brew installed php.
LoadModule rewrite_module libexec/apache2/mod_rewrite.so
LoadModule php5_module /usr/local/opt/php56/libexec/apache2/libphp5.so
Test PHP
Before going to far, take a moment to verify that php is working well with Apache.
Keep an eye on Apache's error log file during this process. Run this in a separate terminal window.
tail -f /private/var/log/apache2/error_log
Create a test index.php
file. Note, the recent versions of php require "<?php" and not simply the shortform, "<?".
echo "<?php phpinfo(); ?>" > /Library/WebServer/Documents/index.php
open http://localhost/index.php
Troubleshooting PHP
If you are having trouble simply installing php using Homebrew, this may be useful:
https://github.com/Homebrew/homebrew-php#common-upgrade-issues
The first bullet might be satisfied with
xcode-select --install
Thanks, joshlopes; https://github.com/Homebrew/homebrew-php/issues/997
Build problems with phar.php?
/bin/sh: line 1: 92714 Segmentation fault...
make: *** [ext/phar/phar.php] Error 139
I'm not clear on what SNMP (some kind of mobile protocol?) is, but there is clear evidence that it gives some general grief with installing php. I resolved it by including --without-snmp
in the call to brew install. I have updated this command in the previous instructions.
If you don't see an html page with a dump of php configuration information, it's time to have some fun debugging. What follows are somethings that I needed to do in order to stop getting a white screen.
Go through this set of steps.
If php still doesn't seem to be running with Apache, I also found this useful to get brew install php56
to succeed. Again, this seems to be fallout from installing PostgreSql the way I did.
sudo mv /usr/lib/libpq.5.dylib /usr/lib/libpq.5.dylib.pre.php56.install
sudo ln -s /Applications/Postgres.app/Contents/Versions/9.4/lib/libpq.5.dylib /usr/lib/libpq.5.dylib
sudo apachectl restart
sudo apachectl configtest
https://github.com/Homebrew/homebrew-php/issues/1489
Once you are able to view the php information in the index.php
page and you have included the pgsql.so
extension in php.ini
, installing phppgadmin
should be easy.
Install phppgadmin
brew install phppgadmin
Follow the instructions that follow after this runs.
Other
To set the timezone in php.ini
, see the php manual for a list of supported values.
[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
date.timezone = "America/Los_Angeles"
The Apache log file may complain about ServerName missing from httpd.conf. Follow the instructions to stop it from complaining.
ServerName localhost:80
Add mime-type for php in the mime-types file instead of as a command in httpd.conf
.
sudo mvim /etc/apache2/mime.types
application/x-httpd-php php
Update PATH to support pear
and PostgreSql
. Edit .bash_profile
.
# add pear package manager (php)
export PATH="/usr/local/pear/bin:$PATH"
# add postgresql app
export PATH="/Applications/Postgres.app/Contents/Versions/9.4/bin:$PATH"
Location of DocumentRoot
cd /Library/WebServer/Documents
Location of Apache
cd /etc/apache2
Edit Apache configuration file
sudo mvim /private/etc/apache2/httpd.conf
Edit the php configuration file
sudo mvim /etc/php.ini
View the Apache logs
cd /private/var/log/apache2
tail -f /private/var/log/apache2/error_log
No comments:
Post a Comment