version: 5.2.x
source: php.net
installer: PHP
parallel: may be errors in a clean configuration
The PHP provided by Apple is sufficiently up to date for most uses. The main issue is that it is a dynamically loaded Apache module (DSO). MapServer, the focus of my PHP, still has possible threading issues in high-volume MapServer use with the DSO PHP. These instructions build PHP as a CGI, with with as many features as possible with what is available in my other build instructions and the system. If a module is not configured here (either explicitly or by default), you're on your own.
In the php source:
export MACOSX_DEPLOYMENT_TARGET=10.6 export CFLAGS="-Os -fnested-functions -arch i386 -arch x86_64" ./configure --prefix=/usr/local/php5cgi --with-zlib --with-bz2 \ --with-gd=/usr/local --enable-gd-jis-conv --enable-gd-native-ttf \ --with-png-dir=/usr/local --with-jpeg-dir=/usr/local --with-freetype-dir=/usr/local \ --enable-exif --with-libxml-dir=/usr --enable-wddx --enable-ftp \ --enable-mbstring --enable-mbregex --with-openssl --with-iconv=/usr \ --enable-force-cgi-redirect --enable-dbase --with-curl --enable-zend-multibyte \ --with-ldap --with-kerberos --enable-sockets --with-xmlrpc --with-xsl \ --enable-calendar --with-libedit --with-pgsql=/usr/local/pgsql \ --with-mysql=/usr/local/mysql --with-mysqli=/Users/Shared/unix/mysql-snow/bin/mysql_config \ --without-sqlite --with-iodbc --enable-pdo --with-pdo-pgsql=/usr/local/pgsql \ --with-pdo-mysql=/Users/Shared/unix/mysql-snow \ --with-pdo-sqlite=/usr --with-regex=system --enable-fastcgi
Add at the end of each file (make sure it's before the last #endif line in the tiffconf.h file):
#undef SIZEOF_LONG #ifdef __LP64__ #define SIZEOF_LONG 8 #else #define SIZEOF_LONG 4 #endif #undef SIZEOF_SIZE_T #ifdef __LP64__ #define SIZEOF_SIZE_T 8 #else #define SIZEOF_SIZE_T 4 #endif #undef SIZEOF_SSIZE_T #ifdef __LP64__ #define SIZEOF_SSIZE_T 8 #else #define SIZEOF_SSIZE_T 4 #endif #undef SIZEOF_PTRDIFF_T #ifdef __LP64__ #define SIZEOF_PTRDIFF_T 8 #else #define SIZEOF_PTRDIFF_T 4 #endif #undef HAVE_TTYNAME_R #ifdef __LP64__ #define HAVE_TTYNAME_R 1 #endif #undef HAVE_PACKED_OBJECT_VALUE #ifdef __LP64__ #define HAVE_PACKED_OBJECT_VALUE 0 #else #define HAVE_PACKED_OBJECT_VALUE 1 #endif #undef ZEND_MM_ALIGNMENT #ifdef __LP64__ #define ZEND_MM_ALIGNMENT 8 #else #define ZEND_MM_ALIGNMENT 4 #endif #undef ZEND_MM_ALIGNMENT_LOG2 #ifdef __LP64__ #define ZEND_MM_ALIGNMENT_LOG2 3 #else #define ZEND_MM_ALIGNMENT_LOG2 2 #endif
make sudo make install
Note that there will be a lot of redefine warnings, these are harmless.
In the php source:
export MACOSX_DEPLOYMENT_TARGET=10.5 export CFLAGS="-Os -fnested-functions -arch ppc -arch ppc64 -arch i386 -arch x86_64" ./configure --prefix=/usr/local/php5cgi --with-zlib --with-bz2 \ --with-gd=/usr/local --enable-gd-jis-conv --enable-gd-native-ttf \ --with-png-dir=/usr/local --with-jpeg-dir=/usr/local --with-freetype-dir=/usr/local \ --enable-exif --with-libxml-dir=/usr --enable-wddx --enable-ftp \ --enable-mbstring --enable-mbregex --with-openssl --with-iconv=/usr \ --enable-force-cgi-redirect --enable-dbase --with-curl --enable-zend-multibyte \ --with-ldap --with-kerberos --enable-sockets --with-xmlrpc --with-xsl \ --enable-calendar --with-libedit --with-pgsql=/usr/local/pgsql \ --with-mysql=/usr/local/mysql --with-mysqli=/Users/Shared/unix/mysql-snow/bin/mysql_config \ --without-sqlite --with-iodbc --enable-pdo --with-pdo-pgsql=/usr/local/pgsql \ --with-pdo-mysql=/Users/Shared/unix/mysql-snow \ --with-pdo-sqlite=/usr --with-regex=system --enable-fastcgi
Add at the end of each file (make sure it's before the last #endif line in the tiffconf.h file):
#undef SIZEOF_LONG #ifdef __LP64__ #define SIZEOF_LONG 8 #else #define SIZEOF_LONG 4 #endif #undef SIZEOF_SIZE_T #ifdef __LP64__ #define SIZEOF_SIZE_T 8 #else #define SIZEOF_SIZE_T 4 #endif #undef SIZEOF_SSIZE_T #ifdef __LP64__ #define SIZEOF_SSIZE_T 8 #else #define SIZEOF_SSIZE_T 4 #endif #undef SIZEOF_PTRDIFF_T #ifdef __LP64__ #define SIZEOF_PTRDIFF_T 8 #else #define SIZEOF_PTRDIFF_T 4 #endif #undef HAVE_TTYNAME_R #ifdef __LP64__ #define HAVE_TTYNAME_R 1 #endif #undef HAVE_PACKED_OBJECT_VALUE #ifdef __LP64__ #define HAVE_PACKED_OBJECT_VALUE 0 #else #define HAVE_PACKED_OBJECT_VALUE 1 #endif #undef ZEND_MM_ALIGNMENT #ifdef __LP64__ #define ZEND_MM_ALIGNMENT 8 #else #define ZEND_MM_ALIGNMENT 4 #endif #undef ZEND_MM_ALIGNMENT_LOG2 #ifdef __LP64__ #define ZEND_MM_ALIGNMENT_LOG2 3 #else #define ZEND_MM_ALIGNMENT_LOG2 2 #endif
make sudo make install
Note that there will be a lot of redefine warnings, these are harmless.
In the php source:
export MACOSX_DEPLOYMENT_TARGET=10.4 export CFLAGS="-Os -fnested-functions -arch ppc -arch i386 -isysroot /Developer/SDKs/MacOSX10.5.sdk" ./configure --prefix=/usr/local/php5cgi --with-zlib --with-bz2 \ --with-gd=/usr/local --enable-gd-jis-conv --enable-gd-native-ttf \ --with-png-dir=/usr/local --with-jpeg-dir=/usr/local --with-freetype-dir=/usr/local \ --enable-exif --with-libxml-dir=/usr --enable-wddx --enable-ftp \ --enable-mbstring --enable-mbregex --with-openssl --with-iconv=/usr \ --enable-force-cgi-redirect --enable-dbase --with-curl --enable-zend-multibyte \ --with-ldap --with-kerberos --enable-sockets --with-xmlrpc --with-xsl \ --enable-calendar --with-libedit --with-pgsql=/usr/local/pgsql \ --with-mysql=/usr/local/mysql --with-mysqli=/Users/Shared/unix/mysql-snow/bin/mysql_config \ --without-sqlite --with-iodbc --enable-pdo --with-pdo-pgsql=/usr/local/pgsql \ --with-pdo-mysql=/Users/Shared/unix/mysql-snow \ --with-pdo-sqlite=/usr --with-regex=system --enable-fastcgi make sudo make install
Some extensions need to be built as external extensions, either they are not in the PHP source, or there is a newer version. Some examples:
You don't need the PHP source to compile extensions, just the extension source. The general process is, in the module source:
/usr/local/php5cgi/bin/phpize ./configure --with-php-config=/usr/local/php5cgi/bin/php-config \ --with-somelibrary=/usr/local \ CFLAGS="-Os -arch i386 -arch x86_64" sudo cp -f modules/yourmodule.so /usr/local/php5cgi/lib/php/extensions/no-debug-non-zts-20060613/
'somelibrary' is the library configuration option or options that the module needs. Check available options with ./configure –help.
The extension will be compiled into the modules folder in the source, fill in the name for yourmodule.so above.
The above extensions subfolder name is for PHP 5.2. For 5.3 it is no-debug-non-zts-20090626.
PHP as a CGI needs a bit of setup to get it running with the Apache web server.
Edit /etc/apache2/httpd.conf. Make sure that the LoadModule and AddModule lines for php5 are commented (# at beginning of line).
Now add a file /etc/apache2/other/php5cgi.conf with the contents:
DirectoryIndex index.html index.php Action php-script /cgi-bin/php5 AddHandler php-script php AddHandler php-script phtml
Huh, OS X Server needs the change the old way, still in the httpd.conf file. Find the line (it may be commented):
AddHandler cgi-script cgi
and add after it:
Action php-script /cgi-bin/php5 AddHandler php-script php AddHandler php-script phtml
Edit /etc/httpd/httpd.conf. First, make sure that the LoadModule and AddModule lines for php5 are commented (# at beginning of line).
Now look for the section <IfModule mod_mime.c>. Within that if block there are a bunch of AddHandlers commented out, it doesn't really matter where in the mod_mime block you put it, but I like to add these after the commented cgi line. If there are any AddType or AddHandler lines for php already there, comment them (unless they're exactly what we want). Add these two lines:
Action php-script /cgi-bin/php AddHandler php-script .php .phtml
Then start up the web server: System Preferences → Sharing → Services and check Personal Web Sharing.
If you are updating PHP, turn Web Sharing off and back on.
Now a quick test. In your web root (/Library/WebServer/Documents) or your home Sites, create a text file named phptest.php with this line:
<?php phpinfo (); ?>
Then open up Safari and go to this URL: localhost/testphp.php (or localhost/~you/testphp.php). You should see a long page of the gorey details of your PHP installation. Make sure that the Server API line corresponds to how you installed it above. If not, there's something wrong in httpd.conf. One last thing to do now to tune PHP - look at the line on this info page for Configuration File Path. It should be /usr/local/php5cgi/lib. You need to copy a file there (assuming you're still in the PHP source folder in the Terminal):
sudo cp php.ini-recommended /usr/local/php5cgi/lib/php.ini
Note that you are renaming the file in the process. Edit this file now. First, find the line that sets extension_dir, add a semicolon at the beginning to comment it.
With php-mapscript you may have complex maps that take a while to draw, or you may have a slow Mac, so it would be a good idea to increase the timeout: find the variable max_execution_time and increase it to 60 seconds or more. If you find maps that take longer (and you can't speed them up), just increase this again. (Try to speed them up, tho - you don't want to frustrate your viewers
)
Reload the php test page and see the changes. You're all set. Note that this 'recommended' php.ini turns off display errors and instead logs them. If you need to debug your php you must look at the web server logs or temporarily turn on display errors in your php (ini_set("display_errors","1");).