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.
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.
--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
To compile and install:
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
5:52 pm
I get this message:
checking for MySQL support… yes
checking for specified location of the MySQL UNIX socket… no
checking for MySQL UNIX socket location… no
checking for mysql_close in -lmysqlclient… no
checking for mysql_error in -lmysqlclient… no
configure: error: mysql configure failed. Please check config.log for more information.
so make won’t work. Any thoughts? I did the standard MySQL install for Mac OS, no errors reported.
7:23 pm
Andy, did you also compile MySQL from source ? I hope you used version 5.0.x for MySQL as well.
8:29 pm
I sort of inherited this server with what is already here. Any advice or a page I could read that would tell me how to overwrite what I have with the version you know works?
8:47 pm
No problem. You can read all in the Docs section on MySQL and what to do. If you still have questions you canemail me or try the forum.
10:20 pm
I’m having trouble with this step for some reason. I’ve tried twice and have the same result. During the make process, I get numerous compiler warnings saying “…pointer targets in assignment differ in signedness”. This results in the Apache module(s) not being compiled and installed, which results in PHP not working, though Apache works fine. I am installing on a OS 10.5.6 Mac Mini, following your instructions to the letter. Any ideas?
12:22 am
Default Leopard apxs location: /usr/sbin/apxs
Therefore configure worked with minor edit: –with-apxs2=/usr/sbin/apxs
7:28 am
Samantha, your comment is incorrect. If you’ve compiled Apache the apsx location is in /usr/local/apache2/bin/apxs
If you want to compile PHP for the default apache installation you are corect but that is described here.
6:58 pm
This worked great for me, albeit with a couple tweaks. I needed to use PHP’s soap library, and so compiled with –enable-soap. Worked great! Thanks! Also, I used the apache web server provided with Apple, and had to remove –with-apxs.
4:30 am
I’ve used the instructions here and installed new Apache2 and PHP5 on Leopard. My php is getting reading php.ini from /usr/local/php5/lib even though –sysconfdir=/etc is set in the ./configure
Any idea how to fix it so that it will read the ini file from etc?
7:59 pm
@David, you where correct, somehow I missed that change. There is another configure option to do this. I’ve added it to the configure statement and it should work now.
8:27 pm
I’ve followed your instructions for building Apache (httpd-2.2.14) and PHP (php-5.2.11), and restarted several times, but my Apache install won’t compile and run any php files, Firefox just displays the PHP code as if it were a text file when I navigate to localhost://dir/foo.php
I’ve also noticed that there is no /etc/php.ini file created after following these instructions, I’m not sure what went wrong…
8:37 pm
@Theodore, the php.ini you sill have to put there yourself. The problem is presumably caused by not adding the required lines to the httpd.conf.
10:07 pm
Thanks, that was the problem, sorry for not following the instructions more carefully…made the mistake of thinking that if the LoadModule line had been added (it was added automatically), the AddType lines would have been added in the correct locations as well, but they hadn’t been. Adding them in manually just after the LoadModule line makes everything work correctly.
8:46 pm
Hi, thanks for your site, it is a great resource.
I keep getting this error on Make on an Intel Mac Mini using 10.5.8
/usr/include/arpa/nameser8_compat.h:304: error: conflicting types for ‘HEADER’
/usr/include/arpa/nameser_compat.h:99: error: previous declaration of ‘HEADER’ was here
make: *** [ext/standard/dns.lo] Error 1
any ideas?
9:47 pm
for above post Compiling PHP 5.2.12 32 bit on OS X 10.5.8 Intel. 32 bit throughout.
10:04 pm
Try using the solution of editing the Makefile described here: http://diymacserver.com/installing-php/compiling-php-in-32-bits-mode-on-snow-leopard/
10:26 pm
Thanks for getting back so soon
tried editing the makefile, got the same error.
Apache source is 2.2.14
My SQL source is 5.1.44
3:47 pm
Ran into problems with new install of DIYMacServer with php5.3.2. on G4 mac (10.5.8) . A test page of phpinfo() revealed that date.timezone function wasn’t properly configured. Tried setting date.timezone in /etc/php.ini, but that didn’t correct the warning. Further examination of of phpinfo() output revealed that PHP’s Apache module was looking for php.ini at this path: /usr/local/php5/lib. Simply copying php.ini from /etc to /usr/local/php5/lib fixed the warning.
See marc_zampetti comments at this page: (http://us4.php.net/en/configuration) that pointed me in right direction.
Hi Richard. Long time. How’s things on your side of pond?
JStubbs
7:19 pm
@Jeff, as far as my tests went some time ago the option ` –with-config-file-path=/etc \` should have taken care off this properly.
Yes, all is fine on this end, bit hot at the moment though…