对于线上环境,一般使用linux,这里讲述如何在linux下面安装php 5.4
1.yum 安装基础 yum install ntp vim-enhanced gcc gcc-c++ gcc-g77 flex bison autoconf automake glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel libtool* zlib-devel libxml2-devel libjpeg-devel libpng-devel libtiff-devel fontconfig-devel freetype-devel libXpm-devel gettext-devel curl curl-devel pam-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers gzip make bzip2bzip2-devel pcre-devel wget ncurses-devel cmake make perl
yum -y install gcc automake autoconf libtool make gcc-c++ glibc libmcrypt-devel mhash-devel libxslt-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel lib 2.安装libmcrypt
libmcrypt下载地址:http://download.csdn.net/detail/terry_water/6974153
当然,您可以自己去官网下载
安装:libmcrypt
tar -zxvf libmcrypt-2.5.7.tar.gz
cd libmcrypt-2.5.7
./configure
make
make install
下载完成后,按照上面的步骤安装完libmcrypt,就可以安装php了
3.安装php
wget http://cn2.php.net/distributions/php-5.4.34.tar.gz
tar zvxf php-5.4.34.tar.gz
cd php-5.4.34
./configure --prefix=/usr/local/php --disable-fileinfo --enable-fpm --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-openssl --with-zlib --with-curl --enable-ftp --with-gd --with-xmlrpc --with-jpeg-dir --with-png-dir --with-freetype-dir --enable-gd-native-ttf --enable-mbstring --with-mcrypt=/usr/local/libmcrypt --enable-zip --with-mysql=/usr/local/mysql --without-pear --enable-bcmath
make
make install
如果上面的下载地址不能下载,自行 去官网下载
复制php.ini到配置路径,上面我们配置的是/etc路径
cp php.ini-development /etc/php.ini 4.设置用户 php-fpm
cd /usr/local/php
cp etc/php-fpm.conf.default etc/php-fpm.conf
vi etc/php-fpm.conf
搜索nobody ,修改成如下
user = www-data
group = www-data
添加www-data用户:
groupadd www-data
useradd -g www-data www-data
5.配置php-fpm
cp -f /tools/php-5.4.34/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm 6.设置启动,开机启动
chmod 755 /etc/init.d/php-fpm
/etc/init.d/php-fpm start
/sbin/chkconfig --add php-fpm (添加到开机服务列表)
/sbin/chkconfig php-fpm on
php-fpm的启动、停止和重启:
/etc/init.d/php-fpm start
/etc/init.d/php-fpm stop
/etc/init.d/php-fpm reload
7.到此php的安装就完成了,当然,后续需要安装一些php的扩展。
执行
which php ,查看你的环境中是否已经有php,有的话删除掉,直到找不到php。
然后把当前安装的php设置为php命令:
ln -s /usr/local/php/bin/php /usr/bin/php 这样命令行里面的 php -m ,执行的就是 /usr/local/php/bin/php