Views
From SCT Knowledge Base
Contents |
PHP Installation On Linux
Login as root.
Erasing An Older Version
All flavor of Linux come bundled with some stable version of PHP. If a full install is the choice when setting up the Linux box, then some version of PHP definitely exists on the Linux flavor in use. Hence prior installing the latest version of PHP, it is prudent to verify the existence of any older version of PHP on the Linux box. This can be done as follows: (Refer to diagram 3.8.1)
<System Prompt> rpm -q php

The above diagram indicates that PHP version 4.3.9-3 exists.
Since this is an older version, erase it as follows: (Refer to diagram 3.8.2)
<System Prompt> rpm -e php

The above diagram shows a list of dependencies, which exist as a support system to the current PHP version. These need to be uninstalled (erased) prior uninstalling (erasing) PHP.
Erase these dependencies as: (Refer to diagram 3.8.3)
<System Prompt> rpm -e php-ldap
<System Prompt> rpm -e php-mysql
<System Prompt> rpm -e php-odbc
<System Prompt> rpm -e php-pgsql
<System Prompt> rpm -e php-devel
<System Prompt> rpm -e php-domxml
<System Prompt> rpm -e php-gd
<System Prompt> rpm -e php-imap
<System Prompt> rpm -e php-mbstring
<System Prompt> rpm -e php-ncurses
<System Prompt> rpm -e php-snmp
<System Prompt> rpm -e php-xmlrpc
<System Prompt> rpm -e squirrelmail
<System Prompt> rpm -e wordtrans-web
<System Prompt> rpm -e php-pear --nodeps
<System Prompt> rpm -e php

If any of the listed dependencies are required then skip the erasing of that particular dependency and erase PHP as follows:
<System Prompt> rpm -e php --nodeps
i.e. two hyphens followed by nodeps
In the above command, --nodeps instructs the rpm package manager to ignore the existence of the dependencies and erase the current version of PHP.
Installing PHP From Its Source File
It is always advisable to install PHP using its source (tarball). This provides access to quicker releases updates instead of waiting for some entity to release an rpm for a particular flavor of Linux.
- Make a directory /php. Copy the downloaded file php-5.1.0RC1.tar.gz here
- Unzip the file as: (Refer to diagram 3.8.4)
<System Prompt> gunzip php-5.1.ORC1.tar.gz

- This will extract php-5.1.0RC1.tar file from the php-5.1.0RC1.tar.gz file
Hint
The php-5.1.0RC1.tar.gz will be replaced by php-5.1.0RC1.tar in the same sub directory.
- The contents of php-5.1.0RC1.tar must be extracted after which the actual install process can begin. To extract the content of php-5.1.0RC1.tar: (Refer to diagram 3.8.4)
<System Prompt> tar -xvf php-5.1.0RC1.tar
- The extraction process creates a directory called php-5.1.0RC1 into which the contents of the tar file are extracted. This is just one level below the /php subdirectory. Change to this sub‑directory: (Refer to diagram 3.8.5)
<System Prompt> cd php-5.1.0RC1

The Configure Command
Make sure that apache is stopped before proceeding with PHP Installation.
Stop the Apache2 HTTPD service and configure the php setup as: (Refer to diagram 3.8.6)
<System Prompt> /usr/local/apache2/bin/apachectl stop
<System Prompt>./configure --prefix=/usr/local/php5 --with-zlib
--with-mysql --with-mysqli
--with-oci8=/u01/app/oracle/product/10.1.0/Db_1
--with-sqlite
--with-pdo-mysql --with-pdo-oci --with-pdo-sqlite
--with-xmlrpc
--with-apxs2=/usr/local/apache2/bin/apxs
In the above command:
- --prefix argument sets the installation path for the PHP 5.0 binaries
- --with-zlib argument enables to transparently read and write gzip .gz compressed files. In this material this is enabled to allow Simple Machines forum run smoothly
- --with-mysql argument activates the regular MySQL extension. In PHP 5.0, this is not active by default (as it is in PHP 4.0) and must be explicitly named in configure to be activated
Warning
To enable the mysql extension, the MySQL Database Engine (at least the client .rpm) installation is a must. The installation steps are available in Chapter 11: MySQL In Action
- --with-mysqli argument activates the new MySQL Improved extension (for MySQL 4.1.2+ only)
- --with-oci8=/u01/app/oracle/product/10.1.0/Db_1 line should point to the location of the database client software i.e. $ORACLE_HOME directory, in Oracle terms. This option actually adds Oracle support to PHP. In short PHP will be built using Oracle support
Warning
To enable the oci8 extension, the Oracle Database Engine (at least the client version) installation is a must. The installation steps are available in Book's accompanied CDROM
- --with-sqlite argument activates the regular SQLite extension. In PHP 5.0, this is not active by default and must be explicitly named in configure to be activated
- --with-xmlrpc argument activates the PEAR (for MySQL 4.1.2+ only). If PEAR is not needed while installing PHP then --without-pear argument has to be given while configuring
- --with-pdo-mysql argument activates the PDO (PHP 5.1 Data Object) extension, which provides a data access abstraction layer for MySQL Db engine
- --with-pdo-oci argument activates the PDO (PHP 5.1 Data Object) extension, which provides a data access abstraction layer for Oracle Db engine
- --with-pdo-sqlite argument activates the PDO (PHP 5.1 Data Object) extension, which provides a data access abstraction layer for SQLite Db engine
- --with-apxs2 argument tells PHP where to find Apache 2.0 and its apxs script (used to handle extensions). This is pointed to /usr/local/apache2/bin/apxs assuming apache web server's apxs script rests here

Reminder
If an error is generated which indicates that the apxs script cannot be found, look for it on the system (i.e. use Find Files) and if found, note down the path to the file. Then provide the full path such as: --with-apxs2=/path-to-apxs
Make sure to specify the version of apxs that is actually installed on the system and NOT the one that is in the apache source tarball.
If an error appears about apxs and the help screen from apxs is displayed, then recompile Apache and ensure that --enable-module=so is specified to the configure command.
The Make Command
The configuration routine commences. The time taken depends upon the amount of free memory available and the processor speed. After the configuration runs successfully execute the command make: (Refer to diagram 3.8.7)
<System Prompt> make

The Make Install Command
Next run the command make install: (Refer to diagram 3.8.8)
<System Prompt> make install
| | |
The next step is to set up a valid configuration file for PHP i.e. php.ini. There are two ini files distributed in the source file (.tar.gz) as shown in diagram 3.8.10 i.e. php.ini-dist and php.ini-recommended. Use the file php.ini-recommended.
<System Prompt> cp php.ini-recommended /usr/local/php5/lib/php.ini
This will create a local copy of the PHP configuration file.
The php.ini-recommended file has a simpler layout, contains fewer settings and allows PHP to run faster. This completes the installation of PHP on Linux.
Binding The PHP Installation With Apache2
Apache does not know that PHP is just installed. Therefore Apache needs to be informed about PHP especially where to find it.
This is done via Apache's httpd.conf file. Apache reads this file and understands what modules need to be loaded and where these modules are located.
Reminder
It is not mandatory to have Apache web server installed in order to test .php scripts. These scripts can simply be run using the interpreter php.exe. This can be accomplished by appending the .php script file as a command line argument to php.exe interpreter.
There are two ways to configure Apache to use PHP 5.
One is to configure it to load the PHP interpreter as an Apache module.
The other is to configure it to run the PHP interpreter as a CGI binary.
Hint
It is recommended that PHP is loaded as a module in Apache, since it runs more efficiently that way, unless there is a specific reason for running PHP as a CGI binary.
Edit Apache's httpd.conf file. Make sure the PHP mime type is specified and uncommented. The line should look like this: (Refer to diagram 3.9.1 and diagram 3.9.2)
AddType application/x-httpd-php .php
This line means that every file that ends with .php will be processed as a PHP file.
Hint
If need arises to support other file types, like .php3, .html, .asp and .phtml, simply add them to the list, like this:
AddType application/x-httpd-php .php3
AddType application/x-httpd-php .phtml
AddType application/x-httpd-php .html
AddType application/x-httpd-php .asp
Reminder
The httpd.conf file is usually available under C:\Program Files\Apache Group\Apache2\conf on Windows and under /usr/local/apache2/conf on Linux.
Ensure that the PHP module is loaded by adding the following line in the httpd.conf file
On Windows: Refer to diagram 3.9.1.
LoadModule php5_module "c:/php/php5apache2.dll"
On Linux: Refer to diagram 3.9.2.
LoadModule php5_modulemodules/libphp5.so
This line tells Apache from where to load the .dll file in case of Windows or the .so file in case of Linux which is required to execute PHP. This line enables loading the PHP module dynamically into Apache. Usually in Linux the PHP source installer automatically inserts this line. If this line does not exist then insert it manually in the httpd.conf file.
Reminder
In the Apache 1.3.X, AddModule directive was used instead of LoadModule.
In case of Apache 1.3.X, search for the block AddModule statement. Add the following line after the last AddModule statement:
AddModule mod_php5.c
mod_php5.c file is not available anywhere in the file system. It only specifies the order in which the Apache Web server enables the various modules.
If Apache 2.X is used, then do not insert the AddModule directive. It's no longer needed in that version. Apache 2.X has its own internal method of determining the correct order of loading the modules.
| | |
Restart Apache server. PHP files should be able to be served up now.
