|
Linux/Unix InstallationThese instructions take you through installing PHP from source, using an Apache web server. You should become the root user to perform the installation by issuing the su command and entering the superuser password. Compiling Apache from SourceIf you already have installed an Apache web server that supports dynamic shared objects (DSO), you can skip this section. To check whether your web server includes this feature, run the following command: $ httpd l If the output includes mod_so.c, then DSO support is included. Note that you may have to supply the full path to httpd (for instance, /usr/local/apache/bin/httpd). You begin by downloading the latest Apache source code from http://httpd.apache.org. At the time of this writing, the latest version is 2.0.52, so the file to download is called httpd-2.0.52.tar.bz2. If a later version is available, you should be sure to substitute the appropriate version number wherever it appears in a filename. You need to save this file to your filesystem in /usr/local/src or some other place where you keep source code. Uncompress the archive using bunzip2, as follows: # bunzip2 httpd-2.0.52.tar.bz2 When the file has been uncompressed, it loses the .bz2 file extension. You extract this archive file by using tar: # tar xvf httpd-2.0.52.tar Files are extracted to a directory called httpd-2.0.52. You should change to this new directory before continuing: # cd httpd-2.0.52 Next, you should issue the configure command with any configuration switches that are appropriate. For instance, to change the base installation directory, you should use the --prefix switch, followed by the desired location. You can enter configure --help to see a list of the possible configure switches. You need to include at least the --enable-module=so switch to ensure that DSO support is available for loading the PHP module later on. You should enter the following command, adding any other configuration switches that you need to include: # ./configure --enable-module=so The configure command produces several screens full of output as it tries to detect the best compilation settings for your system. When it is done, you are returned to a shell prompt and can continue the installation. To begin compiling, you issue the make command: # make Again, a lot of output is produced, and the time required for compilation depends on the speed of your system. When the build is done, you see the following line and are returned to a shell prompt: make[1]: Leaving directory `/usr/local/src/httpd-2.0.52' The final step is to install the newly built software. To do this, you simply enter make install, and the files are automatically copied to their correct system locations: # make install You issue the apachectl start command to start the Apache web server and enter your server's IP address in a web browser to test that the installation is successful. You use the following command if you have not changed the default installation location: # /usr/local/apache/bin/apachectl start Compiling and Installing PHPYou can download the latest version of PHP from www.php.net/downloads.php. At the time of this writing, the latest version is 5.0.3, so the file to download is called php-5.0.3.tar.bz2. If a later version is available, you should be sure to substitute the appropriate version number wherever it appears in a filename. You need to save this file to your filesystem in /usr/local/src or some other place where you keep source code. You uncompress the archive by using bunzip2, as follows: # bunzip2 php-5.0.3.tar.bz2
When the file has been uncompressed, it loses the .bz2 file extension. Extract this uncompressed archive file by using tar: # tar xvf php-5.0.3.tar Files are extracted to a directory called php-5.0.3. You should change to this new directory before continuing: # cd php-5.0.3 Next, you should issue the configure command with any configuration switches that are appropriate. For example, to include database support through the MySQLi extension, you would use the --with-mysqli switch, followed by the path to the mysql_config utility. To see the full list of configure switches, you can run configure --help. You need to include either the --with-apxs or --with-apxs2 switchthe latter is for Apache 2.0followed by the location of the apxs utility on your system. You would use one of the following statements with a default Apache installation: # ./configure --with-apxs2=/usr/local/apache2/bin/apxs # ./configure --with-apxs2=/usr/local/apache/bin/apxs The configure command produces several screens full of output as it tries to detect the best compilation settings for your system. When it is done, you are returned to a shell prompt and can continue the installation. To begin compiling, you issue the make command: # make Again, a lot of output is produced, and the time required for compilation depends on the speed of your system. When the build is done, you see the following text and are returned to a shell prompt: Build complete. (It is safe to ignore warnings about tempnam and tmpnam). The final step is to install the newly built PHP module into your web server. To do this, you enter make install, and the files are automatically copied to their correct system locations: # make install To complete the installation, you need to make a change to the web server configuration file to tell it that .php files should be passed to the PHP module. You should edit the httpd.conf file to add the following line: AddType application/x-httpd-php .php You can include other file extensions besides .php if you want. When you next restart your web server by using the apachectl restart command, the PHP extension will be loaded. To test PHP, you can create a simple script, /usr/local/apache2/htdocs/index.php, that looks like this: <?php phpinfo(); ?> In your web browser, you can visit index.php on the IP address of your web server, and you should see a page that gives lots of information about the PHP configuration. |
|