Now, we have compiled and installed all the libraries needed to run a full Typo3 installation. But we've got to recompile PHP for those changes to take effect, since Typo3 uses most of the libraries through the PHP API. Apple provides a basic PHP installation with OS X, so we are going to make an other one, more appropriate to a web server's needs. We'll let the Apple installation in place, to avoid having problems when updating the OS. We'll just deactivate it, and put our new one in another location.
1. Getting the sources
PHP can be downloaded from: http://www.php.net/downloads.php. Get the complete source code of the latest stable release of PHP 4 (probably PHP 4.3.8), uncompress it, and cd to the directory as root.
Although the new version of the PHP scripting language (5.0.0) compiles without problem on Mac OS X, we are not going to use it. It also works with Typo3, but at the time, it's too early in my opinion to use it, as we don't have many feedback about that specific version.
2. Compiling
Before starting the compilation process, we are going to backup the old PHP Apache module. To do this, type the following command:
sudo mv /usr/libexec/httpd/libphp4.so /usr/libexec/httpd/libphp4.so.save
To correctly compile PHP, we can't just type ./configure, since we are going use specific parameters. So here's the configure command we'll use:
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php --with-apxs --with-ldap=/usr --with-kerberos=/usr --enable-cli --with-zlib-dir=/usr --enable-trans-sid --with-xml --enable-exif --enable-ftp --enable-mbstring --enable-dbx --enable-sockets --with-iodbc=/usr --with-curl=/usr --with-tiff-dir=/usr/local --with-gd --with-png-dir=/usr/local --with-jpeg-dir=/usr/local --with-freetype-dir=/usr/local --enable-gd-native-ttf --enable-gd-imgstrttf
It's the same configuration command as the Apple installation, but with the support of all the libraries we just installed, and a new install location. When the configure command is done, you should get a output like this:
+--------------------------------------------------------------------+
| License: |
| This software is subject to the PHP License, available in this |
| distribution in the file LICENSE. By continuing this installation |
| process, you are bound by the terms of this license agreement. |
| If you do not agree with the terms of this license, you must abort |
| the installation process at this point. |
+--------------------------------------------------------------------+
| *** NOTE *** |
| The default for register_globals is now OFF! |
| |
| If your application relies on register_globals being ON, you |
| should explicitly set it to on in your php.ini file. |
| Note that you are strongly encouraged to read |
| http://www.php.net/manual/en/security.registerglobals.php |
| about the implications of having register_globals set to on, and |
| avoid using it if possible. |
+--------------------------------------------------------------------+
Thank you for using PHP.
Then you can launch make, and make install. It will take a lot of time, so be patient. Our new version will be installed in /usr/local/php/, and the Apache module in /usr/libexec/httpd/.
The last step is to copy the PHP configuration file, which comes with the source, into the installation directory. To do that, always as root in the source directory, type:
cp php.ini-* /usr/local/php/
Now let's configure our new installation. We have just copied two files in the PHP directory: php.ini-dist and php.ini-recommended. Those files are examples of PHP configuration. The first one contains a basic PHP configuration, and the second one the recommended configuration. So we are going to take the recommended one, and optimize it a bit more for Typo3. Let's copy it:
sudo cp /usr/local/php/php.ini-recommended /usr/local/php.ini
Now open that file with your favorite text editor and take a look at it. At line 89, you will see this:
short_open_tag = On
It's not required to turn that directive to «Off», but it's recommended. It will affect the way you declare a PHP script. If you deactivate this directive, you won't be able to use short tags anymore (<? ?>).
Next, at line 167:
allow_call_time_pass_reference = Off
With that directive turned to «Off», it's not possible to force a variable to be passed by reference when you call a function. That is correct for Typo3, and you should not activate that feature.
Now, a very important directive, at line 208:
;open_basedir =
That directive is commented (with the ; sign), so it's inactive. It controls the paths to which PHP can have access. Without that directive, PHP can access the whole disk, so you should uncomment it, and add some paths, as in the example below (each path must be separated by the : sign):
open_basedir = /Library/Servers/:/usr/bin/:/usr/sbin/:/usr/local/bin/:/var/tmp/
Now, at line 240:
;;;;;;;;;;;;;;;;;;;
; Resource Limits ;
;;;;;;;;;;;;;;;;;;;
max_execution_time = 30 ; Maximum execution time of each script, in seconds
max_input_time = 60 ; Maximum amount of time each script may spend parsing request data
memory_limit = 8M ; Maximum amount of memory a script may consume (8MB)
Those lines control the resources PHP can use. For Typo3, you must increase the memory limit to at least 16M. You should also increase the maximum execution time to 60.
Next, at line 285:
error_reporting = E_ALL
This controls the PHP errors which will be outputted. You should deactivate the notices:
error_reporting = E_ALL & ~E_NOTICE
So you won't be annoyed with that kind of «errors», which can be intentional.
You should also activate the display of the PHP errors, to know when you have a bug in a script. This is done at line 292, by putting «On» instead of «Off»:
display_errors = Off
Then, at line 369:
variables_order = "GPCS"
This is also important. The environment variables are not hashed into the $HTTP_ENV_VARS[] array, for performance purposes. That setting is the correct one, and it should never be changed.
At line 380:
register_globals = Off
This is also correct. Never use the register_globals functionalities in your PHP scripts. It improves both security and performance.
Same at line 397:
register_argc_argv = Off
Finally, at line 397 and 400:
magic_quotes_gpc = Off
magic_quotes_runtime = Off
It's also important for Typo3 to have those directive turned to «Off».
You may also want to increase the maximum size of the uploaded files. This is done at line 501:
upload_max_filesize = 2M
Now your brand-new installation of PHP is configured. You need to restart Apache for the changes to take effects.
To get additional documentation about the PHP programming language, you can get the complete manual on the PHP group website (http://www.php.net/manual/).