I installed PHP 5.3.8 from source code on CentOS 5.7, so here are the steps for reference.
First, before installing PHP from source code, we need to uninstall the PHP that comes installed by default on CentOS.
# php -v
PHP 5.1.6 (cli) (built: Nov 29 2010 16:47:46)
Copyright (c) 1997-2006 The PHP Group
Zend Engine v2.1.0, Copyright (c) 1998-2006 Zend Technologies
# yum remove php-*
# php -v
-bash: /usr/bin/php: No such file or directory
・Download site:PHP: Downloads
# cd /usr/local/src
# wget http://jp.php.net/get/php-5.3.8.tar.gz/from/this/mirror
# tar zxvf php-5.3.8.tar.gz
# cd php-5.3.8
./configure \\
--enable-mbstring \\
--with-apxs2=/usr/local/apache2/bin/apxs \\
--with-mysql=/usr/local/mysql \\
--enable-pdo \\
--with-pdo-mysql=/usr/local/mysql \\
--enable-xml
■ Error
configure: error: xml2-config not found. Please check your libxml2 installation.
This was resolved by installing libxml2 (main package) and libxml2-devel (development tools).
yum install -y libxml2
yum install -y libxml2-devel
Verify that PHP is properly installed.
# /usr/local/bin/php -v
PHP 5.3.8 (cli) (built: Nov 2 2011 20:24:31)
Copyright (c) 1997-2011 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2011 Zend Technologies
# vi ~/.bashrc
PATH="$PATH":/usr/local/bin/php
# source ~/.bashrc
# php -v
PHP 5.3.8 (cli) (built: Nov 2 2011 20:24:31)
Copyright (c) 1997-2011 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2011 Zend Technologies
・ITmedia エンタープライズ : Linux Tips「パスを追加したい~.bashrc編~」
■ Copying php.ini
# cp -p /usr/local/src/php-5.3.8/php.ini-development /usr/local/lib/php.ini
*Note: The destination is /usr/local/lib/php.ini, not /usr/local/lib/php/php.ini
■ Editing php.ini
# vi /usr/local/lib/php/php.ini
[PHP]
output_handler = mb_output_handler
expose_php = On
default_charset = "UTF-8"
[Date]
date.timezone = Asia/Tokyo
[mbstring]
mbstring.language = Japanese
mbstring.internal_encoding = UTF-8
mbstring.http_input = auto
mbstring.http_output = UTF-8
mbstring.encoding_translation = On
mbstring.detect_order = auto
mbstring.substitute_character = none;
【References】
・PHP: INIファイル の扱いに関する変更 - Manual
・CentOS 再構築記録13th php.ini 設定を見直す(´・ω・) ス|WEB系技術電脳日記
・PHPの日付関数でWarningエラー - ema725の日記
・自宅サーバー(Windows+Apache)へのPHPインストール
First, add the following content to the
# vi /usr/local/apache2/conf/httpd.conf
# ...
# php conf
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
Next, add index.php to the DirectoryIndex line.
DirectoryIndex index.html index.php
After editing httpd.conf, restart Apache.
# service httpd restart
Create a test PHP file in Apache’s document root and enter content that simply calls the phpinfo method.
# vi /usr/local/apache2/htdocs/phpinfo.php
Check the IP address using the ifconfig command to verify from a browser.
# ifconfig
eth0 Link encap:Ethernet HWaddr D2:9B:E2:9A:9D:14
inet addr:192.168.16.130 Bcast:192.168.128.255 Mask:255.255.255.0
...
Access http://192.168.16.130/phpinfo.php from a browser to verify that PHP works on Apache.
If you see a screen with the heading “PHP Version 5.3.8”, everything is working properly.
Edit Apache’s httpd.conf to change the root when accessing the server to var/www.
# vi /usr/local/apache2/conf/httpd.conf
DocumentRoot "/usr/local/apache2/htdocs"
↓(Change to)
DocumentRoot "/var/www/html"
Also, change “/usr/local/apache2/” to “/var/www/” in other places.
That’s all.
・古い php のアンインストールと php 5.3 のインストール - Debian GNU/Linux 3.1 on PowerMac G4
That’s all from the Gemba.