Forum
Algemeen - php in leopard
Ingediend op donderdag 28 mei 2009 om 23:24 uur door Elmar Otter
<h2><a name="Anchor-Introduction"></a>Introduction</h2>

<p>These installation instructions will compile PHP with a configuration
that closely matches the PHP configuration shipped with OS X,
but with the addition of enabling GD and and PDO support.

<p>This document assumes that the OS X developer tools (XCode 3.0) are installed and you are
running BASH as your default shel...
<h2><a name="Anchor-Introduction"></a>Introduction</h2>

<p>These installation instructions will compile PHP with a configuration
that closely matches the PHP configuration shipped with OS X,
but with the addition of enabling GD and and PDO support.

<p>This document assumes that the OS X developer tools (XCode 3.0) are installed and you are
running BASH as your default shell. It also assumes
you are installing on the client version of OS X 10.5.6 Leopard with
the latest security upgrades.</p>
<p>I have tried to make this document as concise and direct to the point
as possible. It is helpful to
have some knowledge of the basic UNIX commands and permissions, the GNU build system,
and the infamous httpd configuration file (httpd.conf).</p>

<h2><a name="Anchor-Enable"></a>Enable PHP</h2>
<p>If you just need to enable the preinstalled version of PHP, execute the following in terminal
and then skip down to the <a href="#Anchor-Start">Start HTTPD</a> instructions. If you compile PHP,
the build scripts will enable PHP for you.</p>

<p>Launch Terminal and execute the following commands.</p>
<div class="codefrag">
<p><b># Change to the apache configuration directory</b><br />
cd /etc/apache2</p>

<p><b># Edit httpd.conf with your favorite editor</b><br />
sudo nano httpd.conf</p>

<p><b># Find the line .....</b><br />
#LoadModule php5_module libexec/apache2/libphp5.so<br />
<b># and uncomment it by removing the pound sign</b></p>

<p><b># Save and exit the editor</b>

<p><b># Create php.ini (For Development)</b><br />
cd ..<br />
sudo cp php.ini.default php.ini
</p>
</div>


<h2><a name="Anchor-Download"></a>Download the source code and unpack into source directory</h2>
<h3>Download the PHP source code</h3>
<p>Download the Complete Source Code (tar.bz2) from
<a href="http://www.php.net/downloads.php">http://www.php.net/downloads.php</a>
At the time of this writing PHP version 5.2.9 is the latest release.</p>

<h3>Create the source code directory and unpack</h3>
<p>Launch Terminal and execute the following commands where <adminID> is your administrator ID.
If you don't know your administrator id, just use the console command <i>whoami</i> to find out.
That's assuming you are logged in as an administrator.</p>
<div class="codefrag">
<p><b># Create a /usr/local/src directory if it doesn't already exist</b><br />
cd /usr/local<br />
sudo mkdir src<br />
sudo chown <adminID> src <br />
sudo chgrp admin src<br />
chmod 750 src</p>
<p><b># Change to the source directory and unpack</b><br />
cd src<br />
tar -xvjf ~/Downloads/php-5.2.9.tar.bz2</p>
</div>

<a name="Anchor-InstallLib"></a>
<h2>Install the JPEG, PNG and FREETYPE Libraries</h2>
<p>To enable GD support you must install the JPEG and PNG support libraries.
Optionally, you may want to install the FREETYPE library. The easiest way to
compile and install these libraries is to use MacPorts.
If you don't already have MacPorts installed, you can obtain it from
<a href="http://www.macports.org">http://www.macports.org</a>
<div class="codefrag">
<p>
<b># Get the JPEG Library</b><br />
sudo port install jpeg
</p>
<p>
<b># Get the PNG Library</b><br />
sudo port install libpng
</p>
<p>
<b># Get the FREETYPE Library</b><br />
sudo port install freetype
</p>
<p>
<b># If you are forced to use macports through an institutional http proxy,<br />
# execute the following commands.</b><br />
sudo bash<br />
export http_proxy=proxyhostnametongueortnumber <br />
# (e.g. export http_proxy=wwwcache.uni.ac.uk:8080)<br />
export HTTP_PROXY="$http_proxy"<br />
# (you might want to echo $HTTP_PROXY now to check this gives wwwcache...)<br />
port install jpeg<br />
# (etc.)<br />
</p>
</div>


<h2><a name="Anchor-Backup">Backup the existing PHP installation</a></h2>
<p>These directions will overwrite the PHP apache module included
with Leopard, so you will first need to back up the existing module.</p>
<div class="codefrag">
<b># Backup the main PHP Apache HTTPD module</b><br />
cd /usr/libexec/apache2<br />
sudo cp libphp5.so libphp5.2.6-apple.so<br />
<!--
<br />
<b># Backup the Command Line Interface (CLI) and utilities</b><br />
cd /usr/bin<br />
sudo cp php php5.2.9-apple<br />
sudo cp phpize phpize5.2.9-apple<br />
sudo cp php-config php-config5.2.9-apple<br />
<br />
<b># Backup the include files and libraries</b><br />
cd /usr/include<br />
sudo cp -R php php5.2.9-apple<br />
cd /usr/lib/php<br />
sudo cp -R build build5.2.9-apple<br />
-->
</div>


<h2><a name="Anchor-Lipo">Run Apache HTTPD Server 32-Bit</a></h2>
<p>The HTTPD server the ships with Leopard is compiled as a 4-way universal
binary and will run 64-bit on 64-bit boxes (G5, Core 2 Duo, Xeon). If you
run HTTPD 64-bit, it's modules must also be 64-bit. The trouble is that
even though PHP can be compiled 64-bit, a number of external libraries
have not been converted to 64-bit, especially on MacPorts. At best, you
will have to download and manually compile each library you need. In a development
environment it's really best to run 32-bit, and even in a production environment it's
debatable whether compiling in 64-bit support is worth the trouble. In many
applications there is not going to be a significant difference in performance
and running 32-bit might be a little faster.
</p>
<div class="codefrag">
<p><b># Create a /usr/local/sbin directory if it doesn't exist</b><br />
sudo mkdir /usr/local/sbin
</p>
<p><b># List httpd's architecture types</b><br />
cd /usr/sbin<br />
file httpd
</p>
<p><b># Strip out the 64-bit support</b><br />
sudo lipo httpd -thin ppc7400 -output httpd.ppc <b># PowerPC</b><br />
sudo lipo httpd -thin i386 -output httpd.i386 <b># Intel</b>
</p>
<p><b># Stitch them together into a single 2-way 32-bit binary</b><br />
sudo lipo httpd.ppc httpd.i386 -create -output /usr/local/sbin/httpd
</p>
<p><b># Edit org.apache.httpd startup plist</b><br />
cd /System/Library/LaunchDaemons<br />
sudo nano org.apache.httpd.plist<br />
<br />
<b># Change the linelips sealedlt;/b><br />
<string>/usr/sbin/httpd</string><br />
<b>to ..</b><br />
<string>/usr/local/sbin/httpd</string><br />
</p>
</div>

<h2><a name="Anchor-Build">Build and Install PHP (32-bit)</a></h2>
<p>Use the ./configure --help command to get a complete list of build time options.</p>
<p>Your MySQL libraries must be of the same architecture type as the architecture
type you are building PHP for. For example, don't try to build a 32-bit PHP with
64-bit MySQL libraries.</p><p> These directions assume you have installed MySQL
in the default MySQL directory
/usr/local/mysql. They also assume that the mysql libraries are located at
/usr/local/mysql/lib/mysql. If you have installed the packaged version of MySQL
you will have to symlink the libraries.</p>
<p>Execute the following commands in Terminal if using the packaged version of MySQLlips sealedlt;/p>
<div class="codefrag">
<p><b># Change to the mysql libraries directory</b><br />
cd /usr/local/mysql/lib</p>
<p><b># Create /usr/mysql/lib/mysql subdirectory</b><br />
sudo mkdir mysql
</p>
<p>
<p><b># Symlink the libraries</b><br />
sudo ln -s /usr/local/mysql/lib/lib* mysql
</p>
</div>

<p>Execute the following commands in Terminal to build PHPlips sealedlt;/p>
<p class="note">The OS X developer tools must be installed.</p>
<div class="codefrag">
<p><b># Change to the PHP source directory</b><br />
cd /usr/local/src/php-5.2.9
</p>
<p><b># You may need to create or symlink gawk<br />
# On my machine, gawk mysteriously disappeared and configure depends on it</b><br />
sudo ln -s /usr/bin/awk gawk
</p>
<p><b># Issue the configure command to build the make file</b><br />
./configure <br />
--prefix=/usr/local <br />
--with-apxs2=/usr/sbin/apxs <br />
--with-ldap=/usr <br />
--with-kerberos=/usr <br />
--enable-cli <br />
--with-zlib-dir=/usr <br />
--enable-exif <br />
--enable-ftp <br />
--enable-mbstring <br />
--enable-mbregex <br />
--enable-sockets <br />
--with-iodbc=/usr <br />
--with-curl=/usr <br />
--with-config-file-path=/etc <br />
--sysconfdir=/private/etc <br />
--with-mysql-sock=/var/mysql <br />
--with-mysqli=/usr/local/mysql/bin/mysql_config <br />
--with-mysql=/usr/local/mysql <br />
--with-openssl=/usr <br />
--with-xmlrpc <br />
--with-xsl=/usr <br />
--without-pear <br />
--with-libxml-dir=/usr <br />
--with-iconv=/usr <br />
--with-pdo-mysql=/usr/local/mysql/bin/mysql_config <br />
--with-gd <br />
--with-jpeg-dir=/opt/local <br />
--with-png-dir=/opt/local <br />
--with-freetype-dir=/opt/local
</p>
<p><b># Build the executables</b><br />
make
</p>
<p>
If you receive the errorlips sealedlt;br />
Undefined symbolslips sealedlt;br />
"_EVP_CIPHER_CTX_block_size", referenced fromlips sealedlt;br />
_zif_openssl_seal in openssl.o<br />
ld: symbol(s) not found<br />
after compiling and linking PHP, it indicates a conflict with other MacPorts libraries.
When you link php with a MacPorts library, it starts searching for all libraries in
MacPorts, some of which may conflict with other libraries on your system. You may
have to isolate the MacPorts libraries that you need to compile php from any other
MacPorts libraries or applications that you may have already installed with MacPorts.
One way to do this is to move your old MacPorts directory (usually /opt) to a new directory,
reinstall macports and rerun the port installs.
</p>
<p><b># Copy the installation to the OS X PHP directories</b><br />
sudo make install
</p>
<p><b># Copy the configuration file php.ini to /etc</b><br />
sudo cp php.ini-dist /etc/php.ini <b># For a development environment</b><br />
sudo cp php.ini-recommended /etc/php.ini <b># For a production environment</b>
</p>
<p><b># Rename the module and edit httpd.conf</b><br />
cd /usr/libexec/apache2<br />
sudo mv libphp5.so libphp5.2.9-pdogd.so <b># Rename</b><br />
cd /etc/apache2<br />
sudo nano httpd.conf<br />
<br />
change the linelips sealedlt;br />
LoadModule php5_module libexec/apache2/libphp5.so<br />
to ..<br />
LoadModule php5_module libexec/apache2/libphp5.2.9-pdogd.so<br />
</p>
<p><b># The newly compiled php Command Line Interface (CLI), utilities, includes,
as well as the man pages are installed in /usr/local.</b><br /><br />
<b># Add /usr/local/bin to your PATH in .profile.</b><br />
nano ~/.profile<br /><br />
<b># Your PATH should look something likelips sealedlt;/b><br />
export PATH=/usr/local/bin:$PATH:/Developer/Tools:/usr/local/mysql/binlips sealedlt;br />/opt/local/bin:/opt/local/sbin
</p>
<p>
If you are searching for the original Apple installed PHP files, they are herelips sealedlt;br />
The command line interface and utilities are located in /usr/bin.<br />
The headers are located in /usr/include/php and the libraries are in /usr/lib/php.<br />
The man pages are located in /usr/share/man/man1.
</p>
</div>

<h2><a name="Anchor-Start">Start HTTPD and Display the PHP Configuration</a></h2>
<p>Use the System Preferences Sharing panel or the apachectl utility to stop and restart the HTTPD server</p>
<p>Execute the following commands in Terminallips sealedlt;/p>
<div class="codefrag">
<p><b># Stop the HTTPD server if it's already running</b><br />
sudo apachectl graceful-stop<br />
<br />
<b># Start the HTTPD server</b><br />
sudo apachectl start<br />
<br />
<b># Create PHP Configuration Script</b><br />
sudo echo "<?php phpinfo(); ?>" > /Library/WebServer/Documents/PHPInfo.php
</p>
</div>
<p>Go to <a href="http://localhost/PHPInfo.php">http://localhost/PHPInfo.php</a> in
your browser.

<h2><a name="Anchor-Links"></a>Troubleshooting</h2>
<p>If things are not working as expected, first use the console utility or command line to
check the httpd error log at /var/log/apache2/error_log.</p>
<p>Also, check /etc/apache2/httpd.conf for any spelling errors. Look closely at
the line that loads the php module. It should look something like thislips sealedlt;br />
LoadModule php5_module libexec/apache2/libphp5.so</p>
<p>Some have reported problems connecting with MySQL. Depending on whether you
are running a packaged version of MySQL or have compiled it, mysql.sock can get
created in either /var/mysql or /tmp. You may have to set mysql.default_socket = /var/mysql/mysql.sock
in /etc/php.ini or set socket = /var/mysql/mysql.sock in /etc/my.cnf.</p>
<p>Stop and then start the httpd server to force httpd to read httpd.conf. If you use
the apachectl restart command, httpd.conf will not be read.</p>
<h2><a name="Anchor-Links"></a>Useful Links</h2>
<ul class="links">
<li><a href="http://www.php.net">Main PHP Site</a></li>
<li><a href="http://www.malisphoto.com/tips/mysql-on-os-x.html">Compiling and Installing MySQL on OS X Leopard</a></li>
<li><a href="http://www.malisphoto.com/tips/windsurfing">Windsurfing Mayhem</a></li>
</ul>

<h2><a name="Anchor-Feedback"></a>Feedback</h2>
<p>Please let me know if you found this page useful or have any other comments.</p>
<form class="codefrag" method="POST" action="http://www.malisphoto.com/cgi-bin/FormMail.pl">
<p><input type="hidden" name="recipient" value="johns@malisphoto.com">
<input type="hidden" name="subject" value="Email from PHP Tips">
<input type="hidden" name="env_report" value="REMOTE_HOST,HTTP_USER_AGENT">
<input type="hidden" name="redirect" value="http://www.malisphoto.com/tips/phpresponse.html">
</p>
<p>Commentslips sealedlt;br />
<textarea name="Comment" cols=60 rows=10></textarea></p>
<p>Your Email (Optional)lips sealedlt;input type="text" name="email" value="">
<br />Include an email address if you would like a reply.</p>
<!--
<p>Type the following letters in alphabetical order (Z D A B)lips sealedlt;input type="text" name="name" value=""></p>
-->
<p><input type="submit" value="Send Comments"></p>
</form>