Contents
  1. 1. 下载PHP源码
  2. 2. 安装依赖的软件包
  3. 3. 编译安装
    1. 3.1. 作为apache运行模块编译安装
    2. 3.2. 安装成PHP-FPM

本文介绍在Arch Linux上编译安装PHP 5.4.39。

下载PHP源码

从官网http://www.php.net/downloads.php选择要下载的源码,推荐从国内镜像http://cn2.php.net/get/php-5.4.39.tar.bz2/from/this/mirror下载。

安装依赖的软件包

本次编译有安装mcrypt扩展,而mcrypt需要依赖libmcrypt,故需要安装相应软件包

1
pacman -S libmcrypt

编译安装

作为apache运行模块编译安装

在root帐号下执行如下命令:

1
2
3
4
5
tar xvf php-5.4.39.tar.bz2
cd php-5.4.39
./configure --prefix=/usr/local/php-5.4.39 --with-layout=GNU --with-config-file-path=/usr/local/php-5.4.39/etc/ --with-config-file-scan-dir=/usr/local/php-5.4.39/etc/conf.d --disable-rpath --mandir=/usr/local/php-5.4.39/man --with-apxs2 --enable-bcmath=shared --enable-calendar=shared --enable-ftp=shared --enable-gd-native-ttf --enable-intl=shared --enable-mbstring --enable-soap=shared --enable-sockets=shared --enable-zip=shared --with-bz2=shared --with-curl --with-freetype-dir=/usr --with-gd --with-jpeg-dir=/usr --with-mcrypt=shared --with-mysql-sock=/var/run/mysqld/mysqld.sock --with-mysql=shared,mysqlnd --with-mysqli=shared,mysqlnd --with-openssl=shared --with-pdo-mysql=shared,mysqlnd --with-png-dir=/usr --with-zlib --with-readline --with-curl=shared --with-iconv=shared --with-gettext=shared
make
make install

编译安装程序会自动往httpd的modules目录(Arch Linux下是/usr/lib/httpd/modules)拷贝进文件libphp5.so,并往httpd配置文件(/etc/httpd/httpd/conf)写入一行: LoadModule php5_module modules/libphp5.so

安装成PHP-FPM

1
2
3
4
5
tar xvf php-5.4.39.tar.bz2
cd php-5.4.39
./configure --prefix=/usr/local/php-5.4.39_fpm --with-layout=GNU --with-config-file-path=/usr/local/php-5.4.39_fpm/etc/ --with-config-file-scan-dir=/usr/local/php-5.4.39_fpm/etc/conf.d --disable-rpath --mandir=/usr/local/php-5.4.39_fpm/man --enable-bcmath=shared --enable-calendar=shared --enable-ftp=shared --enable-gd-native-ttf --enable-intl=shared --enable-mbstring --enable-soap=shared --enable-sockets=shared --enable-zip=shared --with-bz2=shared --with-curl --with-freetype-dir=/usr --with-gd --with-jpeg-dir=/usr --with-mcrypt=shared --with-mysql-sock=/var/run/mysqld/mysqld.sock --with-mysql=shared,mysqlnd --with-mysqli=shared,mysqlnd --with-openssl=shared --with-pdo-mysql=shared,mysqlnd --with-png-dir=/usr --with-zlib --with-readline --with-curl=shared --with-iconv=shared --with-gettext=shared --enable-fpm
make
make install
Contents
  1. 1. 下载PHP源码
  2. 2. 安装依赖的软件包
  3. 3. 编译安装
    1. 3.1. 作为apache运行模块编译安装
    2. 3.2. 安装成PHP-FPM