Richard
To install PHP on Mac OS X Leopard there are, just as with Apache, several options one could use. I’ve chosen the most simple setup that will get most PHP based applications running that we need for the mailserver and such. Please remember that this is the 64 bit mode installation which requires a 64 bit MySQL installation otherwise you will get compiler errors.
You can start by downloading the latest source archive from www.php.net. Extract the source archive into a directory and use the Terminal to execute the following commands.
For Intel use:
CFLAGS="-arch x86_64" \
CXXFLAGS="-arch x86_64" \
./configure --prefix=/usr/local/php5 \
--mandir=/usr/share/man \
--infodir=/usr/share/info \
--sysconfdir=/etc \
--with-config-file-path=/etc \
--with-zlib \
--with-zlib-dir=/usr \
--with-openssl \
--without-iconv \
--enable-exif \
--enable-ftp \
--enable-mbstring \
--enable-mbregex \
--enable-sockets \
--with-mysql=/usr/local/mysql \
--with-pdo-mysql=/usr/local/mysql \
--with-mysqli=/usr/local/mysql/bin/mysql_config \
--with-apxs2=/usr/local/apache2/bin/apxs
For PowerPC use
CFLAGS="-arch ppc64" \
CXXFLAGS="-arch ppc64" \
./configure --prefix=/usr/local/php5 \
--mandir=/usr/share/man \
--infodir=/usr/share/info \
--sysconfdir=/etc \
--with-config-file-path=/etc \
--with-zlib \
--with-zlib-dir=/usr \
--with-openssl \
--without-iconv \
--enable-exif \
--enable-ftp \
--enable-mbstring \
--enable-mbregex \
--enable-sockets \
--with-mysql=/usr/local/mysql \
--with-pdo-mysql=/usr/local/mysql \
--with-mysqli=/usr/local/mysql/bin/mysql_config \
--with-apxs2=/usr/local/apache2/bin/apxs
Follow for both with:
sudo make install
If the install fails because of a PEAR error like:
[PEAR] Console_Getopt: upgrade to a newer version (1.2 is not newer than 1.2)
warning: pear/PEAR dependency package “pear/Archive_Tar” installed version 1.1 is not the recommended version 1.3.1
[PEAR] PEAR: commit failed
You’ll need to upgrade the PEAR package on your machine. Save the script at http://pear.php.net/go-pear to your desktop as go-pear.php and execute ‘sudo php go-pear.php’. Just answer the questions when needed, most can be answered by just pressing the enter button. The most important one is to change the installation prefix from ‘/usr‘ to ‘/usr/local/php5‘ and that is it. Try to rerun the ‘sudo make install’ in the PHP source directory and it should work.
After installation, please check if the your ‘httpd.conf’ has been updated for the PHP extension and if the module is being loaded. Your ‘httpd.conf’ file should have the following lines:
AddType application/x-httpd-php .php .phtml
AddType application/x-httpd-php-source .phps
Restart Apache and your ready to go.
As you might have seen from the ‘./configure‘ settings, your ‘php.ini‘ file will be located in ‘/etc‘.
Next step: Installing the Mailserver



Comments
12:46 am
I’d like to add that if you are using the default Leopard layout, then the last line of your configure commands should be “–with-apxs2=/usr/sbin/apxs”
the compile will fail if you don’t do this as /usr/local/apache2/bin/apxs doesn’t exist when using the Leopard layout. I am assuming that this shouldn’t cause a problem?
8:22 am
Jared, you are correct but that was not the purpose of this write-up. Each page is part of a bigger set and they are all interlinked. I’ve blogged about this a while back, perhaps I can put a remark here if more people encounter this problem.
12:16 pm
I have encountered it
5:46 am
After striping out the odd characters in the script above I went and entered it in the terminal.
I received this error:
checking for mysql_set_server_option in -lmysqlclient… no
configure: error: wrong mysql library version or lib not found. Check config.log for more information.
The tail end of my config.log is: (from tail-25 config.log)
tail -25 config.log
configure:58400: checking for specified location of the MySQL UNIX socket
configure:58456: checking for MySQL UNIX socket location
configure:58647: checking for mysql_close in -lmysqlclient
configure:58666: gcc -o conftest -arch x86_64 -gstabs -fvisibility=hidden -no-cpp-precomp -Wl,-rpath,/usr/local/mysql/lib -L/usr/local/mysql/lib conftest.c -lmysqlclient -lssl -lcrypto -lz -lssl -lcrypto -lm -lxml2 -lz -licucore -lm -lxml2 -lz -licucore -lm 1>&5
configure:59607: checking for MySQLi support
configure:59654: checking whether to enable embedded MySQLi support
configure:59808: checking for mysql_set_server_option in -lmysqlclient
configure:59827: gcc -o conftest -arch x86_64 -gstabs -fvisibility=hidden -no-cpp-precomp -Wl,-rpath,/usr/local/mysql/lib/mysql -L/usr/local/mysql/lib/mysql -Wl,-rpath,/usr/local/mysql/lib -L/usr/local/mysql/lib -lmysqlclient -lz -lm conftest.c -lmysqlclient -lmysqlclient -lssl -lcrypto -lz -lssl -lcrypto -lm -lxml2 -lz -licucore -lm -lxml2 -lz -licucore -lm 1>&5
ld warning: in /usr/local/mysql/lib/mysql/libmysqlclient.dylib, file is not of required architecture
Undefined symbols:
“_mysql_set_server_option”, referenced from:
_main in cc5nxJBC.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
configure: failed program was:
#line 59816 “configure”
#include “confdefs.h”
/* Override any gcc2 internal prototype to avoid an error. */
/* We use char because int might match the return type of a gcc2
builtin and then its argument prototype would still apply. */
char mysql_set_server_option();
int main() {
mysql_set_server_option()
; return 0; }
Perhaps the info from mysqld_config would be helpful. Here it is:
sudo ./mysql_config
Password:
Usage: ./mysql_config [OPTIONS]
Options:
–cflags [-I/usr/local/mysql-5.1.36-osx10.5-x86_64/include/mysql -D_P1003_1B_VISIBLE -DSIGNAL_WITH_VIO_CLOSE -DSIGNALS_DONT_BREAK_READ -DIGNORE_SIGHUP_SIGQUIT -DDONT_DECLARE_CXA_PURE_VIRTUAL]
–include [-I/usr/local/mysql-5.1.36-osx10.5-x86_64/include/mysql]
–libs [-L/usr/local/mysql-5.1.36-osx10.5-x86_64/lib/mysql -lmysqlclient -lz -lm]
–libs_r [-L/usr/local/mysql-5.1.36-osx10.5-x86_64/lib/mysql -lmysqlclient_r -lz -lm]
–plugindir [/usr/local/mysql/lib/mysql/plugin]
–socket [/tmp/mysql.sock]
–port [0]
–version [5.1.36]
–libmysqld-libs [-L/usr/local/mysql-5.1.36-osx10.5-x86_64/lib/mysql -lmysqld -ldl -lz -lm]
I thought that this might be a case of mixing 64bit and 32bit architectures, but I followed the directions your site up to this point.
Any ideas how I can either get the correct libmysqlclient.dylib or alter the configure script so it points to the correct library?
Thanks.
3:40 pm
IIf you have a PowerPC Mac (G3, G4 or G5) you’ll need to change
CFLAGS=”-arch x86_64″ \
CXXFLAGS=”-arch x86_64″ \
to
CFLAGS=”-arch ppc64″ \
CXXFLAGS=”-arch ppc64″ \
1:25 pm
Thanks for this excellent documentation.
Some comments about PHP5 installation on Leopard :
– the system comes with php pre-installed, if you want to update Apple installation replace the –prefix option in the configure command with :
–prefix=/usr
– the –sysconfdir=/etc option does not seem to be sufficient for PHP to find the correct ini file path. On my system it was necessary to add the following option to the configure command :
–with-config-file-path=/etc
Finally, it would be nice to add instructions on how to install the op-code cache APC, which brings really high performance gains.
Cheers.
8:12 pm
In Snow Leopard, you need to add `-lresolv´ to the line containing `EXTRA_LIBS´ in the `Makefile´ _after_ you executed the `./configure´-script.
The source where i got that said that this is probably a bug in the PHP 5.3 branch.
Have fun!
4:02 am
I get this when I make my php
Undefined symbols:
“_res_9_dn_expand”, referenced from:
_zif_dns_get_mx in dns.o
“_res_9_search”, referenced from:
_zif_dns_check_record in dns.o
_zif_dns_get_mx in dns.o
“_res_9_dn_skipname”, referenced from:
_zif_dns_get_mx in dns.o
_zif_dns_get_mx in dns.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
make: *** [libs/libphp5.bundle] Error 1
10:09 am
@Jason, are you sure your machine is 64 bits? Are you using 5.3, then try the previous remark from Nico adding -lresolv in the makefile.
4:42 pm
I got this when I tried to do the first make:
ld warning: in /usr/local/apache2/bin/httpd, file is not of required architecture
ld warning: in /usr/local/apache2/lib/libaprutil.dylib, file is not of required architecture
ld warning: in /usr/local/apache2/lib/libapr.dylib, file is not of required architecture
Undefined symbols:
“_ap_server_root_relative”, referenced from:
_php_apache_phpini_set in apache_config.o
“_apr_brigade_flatten”, referenced from:
_php_apache_sapi_read_post in sapi_apache2.o
“_apr_table_unset”, referenced from:
_php_apache_request_ctor in sapi_apache2.o
_php_apache_request_ctor in sapi_apache2.o
_php_apache_request_ctor in sapi_apache2.o
_php_apache_request_ctor in sapi_apache2.o
“_apr_pool_cleanup_null”, referenced from:
_php_apache_server_startup in sapi_apache2.o
_php_apache_server_startup in sapi_apache2.o
_php_handler in sapi_apache2.o
_php_apache_child_init in sapi_apache2.o
_create_php_config in apache_config.o
“_apr_brigade_create”, referenced from:
_php_handler in sapi_apache2.o
“_ap_destroy_sub_req”, referenced from:
_zif_virtual in php_functions.o
_zif_virtual in php_functions.o
_zif_apache_lookup_uri in php_functions.o
_zif_apache_lookup_uri in php_functions.o
“_unixd_config”, referenced from:
_zm_info_apache in php_functions.o
“_apr_brigade_cleanup”, referenced from:
_php_apache_sapi_read_post in sapi_apache2.o
_php_handler in sapi_apache2.o
“_apr_pstrdup”, referenced from:
_php_apache_sapi_send_headers in sapi_apache2.o
_php_apache_sapi_send_headers in sapi_apache2.o
_php_apache_request_ctor in sapi_apache2.o
_php_apache_request_ctor in sapi_apache2.o
_php_apache_request_ctor in sapi_apache2.o
_php_apache_request_ctor in sapi_apache2.o
_real_value_hnd in apache_config.o
“_ap_add_common_vars”, referenced from:
_php_handler in sapi_apache2.o
“_apr_table_add”, referenced from:
_php_apache_sapi_header_handler in sapi_apache2.o
“_apr_pool_cleanup_run”, referenced from:
_php_apache_ini_dtor in sapi_apache2.o
“_apr_table_get”, referenced from:
_php_apache_sapi_read_cookies in sapi_apache2.o
_php_apache_sapi_getenv in sapi_apache2.o
_php_apache_request_ctor in sapi_apache2.o
_php_apache_request_ctor in sapi_apache2.o
_php_apache_request_ctor in sapi_apache2.o
_zif_apache_note in php_functions.o
_zif_apache_getenv in php_functions.o
“_apr_table_set”, referenced from:
_php_apache_sapi_header_handler in sapi_apache2.o
_php_apache_sapi_send_headers in sapi_apache2.o
_php_handler in sapi_apache2.o
_zif_apache_note in php_functions.o
_zif_apache_setenv in php_functions.o
“_ap_set_content_type”, referenced from:
_php_apache_sapi_send_headers in sapi_apache2.o
“_ap_hook_pre_config”, referenced from:
_php_ap2_register_hook in sapi_apache2.o
“_ap_add_version_component”, referenced from:
_php_apache_server_startup in sapi_apache2.o
“_ap_rflush”, referenced from:
_php_apache_sapi_flush in sapi_apache2.o
_zif_virtual in php_functions.o
“_ap_auth_type”, referenced from:
_php_apache_request_ctor in sapi_apache2.o
“_ap_hook_handler”, referenced from:
_php_ap2_register_hook in sapi_apache2.o
“_apr_psprintf”, referenced from:
_php_handler in sapi_apache2.o
“_apr_bucket_eos_create”, referenced from:
_php_handler in sapi_apache2.o
“_ap_get_server_version”, referenced from:
_php_apache_get_version in php_functions.o
“_ap_update_mtime”, referenced from:
_php_handler in sapi_apache2.o
“_ap_log_rerror”, referenced from:
_php_apache_sapi_log_message in sapi_apache2.o
_php_apache_sapi_log_message_ex in sapi_apache2.o
“_ap_loaded_modules”, referenced from:
_zif_apache_get_modules in php_functions.o
_zm_info_apache in php_functions.o
_zm_info_apache in php_functions.o
“_environ”, referenced from:
_zif_putenv in basic_functions.o
_php_print_info in info.o
__php_import_environment_variables in php_variables.o
“_ap_get_brigade”, referenced from:
_php_apache_sapi_read_post in sapi_apache2.o
“_ap_pass_brigade”, referenced from:
_php_handler in sapi_apache2.o
“_ap_hook_child_init”, referenced from:
_php_ap2_register_hook in sapi_apache2.o
“_ap_server_root”, referenced from:
_zm_info_apache in php_functions.o
“_ap_log_error”, referenced from:
_php_apache_sapi_log_message in sapi_apache2.o
_php_pre_config in sapi_apache2.o
“_apr_pool_cleanup_register”, referenced from:
_php_apache_server_startup in sapi_apache2.o
_php_handler in sapi_apache2.o
_php_apache_child_init in sapi_apache2.o
_create_php_config in apache_config.o
“_apr_snprintf”, referenced from:
_zm_info_apache in php_functions.o
“_ap_rwrite”, referenced from:
_php_apache_sapi_ub_write in sapi_apache2.o
“_apr_pool_userdata_get”, referenced from:
_php_apache_server_startup in sapi_apache2.o
“_apr_pool_userdata_set”, referenced from:
_php_apache_server_startup in sapi_apache2.o
“_ap_add_cgi_vars”, referenced from:
_php_handler in sapi_apache2.o
“_ap_sub_req_lookup_uri”, referenced from:
_php_apache_lookup_uri in php_functions.o
“_apr_table_elts”, referenced from:
_php_apache_sapi_register_variables in sapi_apache2.o
_zif_apache_request_headers in php_functions.o
_zif_apache_response_headers in php_functions.o
_zm_info_apache in php_functions.o
_zm_info_apache in php_functions.o
_zm_info_apache in php_functions.o
“_apr_palloc”, referenced from:
_php_handler in sapi_apache2.o
_create_php_config in apache_config.o
“_ap_mpm_query”, referenced from:
_php_pre_config in sapi_apache2.o
_zm_info_apache in php_functions.o
“_ap_hook_post_config”, referenced from:
_php_ap2_register_hook in sapi_apache2.o
“_ap_set_last_modified”, referenced from:
_php_handler in sapi_apache2.o
“_ap_run_sub_req”, referenced from:
_zif_virtual in php_functions.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
make: *** [libs/libphp5.bundle] Error 1
Not sure whats wrong?
10:31 am
@Matthew, you are combining 64 bits and 32 bits components. Somewhere you made a mistake with the compiler options.
7:15 pm
Hi,
I started compiling and installing my own mysql and apache2 following your directions.
When I install php5 – I can’t view the simple “It works”-HTML – I just get a blank page. When I uncomment the php5 module – it works.
Any ideas? Thanks a lot.
/var/log/httpd/error_log:
[Thu Jan 07 19:09:13 2010] [notice] Apache/2.2.14 (Unix) mod_ssl/2.2.14 OpenSSL/0.9.8k DAV/2 PHP/5.2.12 configured — resuming normal operations
[Thu Jan 07 19:09:17 2010] [notice] child pid 81240 exit signal Segmentation fault (11)
7:52 pm
Arlo, are you sure you compiled it all for the correct architecture (32 vs 64 bits)
8:23 pm
Hey Richard,
wow, fast reply. After compiling it a few times it somehow works now. I also noticed that there actually is a guide for Snow Leopard.
You should consider linking the Snow Leopard articles from http://diymacserver.com/installing-php/.
Thanks for your help and keep up the good work.
9:50 pm
Arlo, good that you got it working, thanks for the remark I will see what I can do about it.
10:11 pm
Hoping someone may be able to help me. I have successfully installed, from source, MySQL5, PgSQL8 (I have connected to both, they are running), and Apache2. I am now attempting to install PHP5, following these instructions. I have added the options for PgSQL from the ./configure –help menu for pgsql, and specified my installation locations. However, during ./configure I get the following error:
checking for PostgreSQL support for PDO… yes
checking for pg_config… not found
configure: error: Cannot find libpq-fe.h. Please specify correct PostgreSQL installation path
The path I gave it was /Library/PgSQL8, which /is/ where my installation is, and it does have pg_config in ./bin there, and the libpq-fe.h in ./include there. But it refuses to believe me. I’ve set the directory and contents 777 in case that was the issue, and no joy. It refuses to accept that I have PgSQL installed there.
Any ideas what I should try next here?
10:37 pm
@DavidM, sorry no experience with pPostgreSQL.
8:37 pm
@DavidM
Did you ever find the answer to this?
I am trying to install PostgreSQL on OSX 10.6 and having the same issue.