centos X64下安装php5.5.6

前端之家收集整理的这篇文章主要介绍了centos X64下安装php5.5.6前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

一.安装常用命令

yum -y install wget make zip unzippatch

yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers libevent libevent-devel

下载软件

mkdir ~/soft
cd ~/soft

wget -c http://cn2.PHP.net/distributions/PHP-5.5.16.tar.gz
wget -c http://tengine.taobao.org/download/tengine-2.0.3.tar.gz

wget -c http://dev.MysqL.com/get/Downloads/MysqL-5.5/MysqL-5.5.39-linux2.6-x86_64.tar.gz

wget http://www.imagemagick.org/download/ImageMagick-6.8.9-7.tar.gz
wget http://pecl.PHP.net/get/imagick-3.1.2.tgz

wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.13.1.tar.gz
wget http://pecl.PHP.net/get/memcache-2.2.7.tgz
wgetftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.35.tar.gz

yum install libmcrypt libmcrypt-devel mcrypt mhash

或者从下面下载包编译安装

wget "http://downloads.sourceforge.net/mhash/mhash-0.9.9.9.tar.gz?big_mirror=0"
wget "http://downloads.sourceforge.net/mcrypt/libmcrypt-2.5.8.tar.gz?big_mirror=0"
wget "http://downloads.sourceforge.net/mcrypt/mcrypt-2.6.8.tar.gz?big_mirror=0"

一.安装MysqL

cd ~/soft/

groupadd MysqL
useradd -g MysqL -d /usr/local/MysqL -s /sbin/nologin MysqL

需要先安装libaio库

#yum -y install libaio

tar zxvf MysqL-5.5.39-linux2.6-x86_64.tar.gz
mv MysqL-5.5.39-linux2.6-x86_64 /usr/local/MysqL
cd /usr/local/MysqL
chown -R MysqL .
chgrp -R MysqL .

scripts/MysqL_install_db --user=MysqL

chown -R root .
chown -R MysqL data

修改 /etc/my.cnf 文件,将socket文件位置修改如下

socket=/tmp/MysqL.sock

# create MysqL pid work dir
mkdir /var/run/MysqLd/
chown -R MysqL:MysqL /var/run/MysqLd/
bin/MysqLd_safe --user=MysqL &

# Next command is optional

cp support-files/MysqL.server /etc/init.d/MysqL.server

#修改MysqL密码

bin/MysqLadmin -u root password 'new-password'
bin/MysqL -u root -p

注册系统服务

cp support-files/MysqL.server /etc/init.d/MysqLd

#把msql的脚本文件拷到系统的启动目录下

cd /etc/init.d/
chkconfig --add MysqLd #将MysqL加到启动服务列表里
chkconfig MysqLd on #让系统启动时自动打开MysqL服务,如果指定级别,用--level参数

这里为了以后维护的时候,不用输入完整的路径,做了软链接

ln -s /usr/local/MysqL/bin/MysqLdump /usr/sbin/MysqLdump
ln -s /usr/local/MysqL/bin/MysqLd_safe /usr/sbin/MysqLd_safe
ln -s /usr/local/MysqL/bin/MysqLslap /usr/sbin/MysqLslap
ln -s /usr/local/MysqL/bin/MysqL /usr/sbin/MysqL
ln -s /usr/local/MysqL/bin/MysqLadmin /usr/sbin/MysqLadmin

我们这里将sock放在了/tmp目录里.有时候系统会使用默认的/var/lib/MysqL/MysqL.sock文件,为了兼容这个情况可以建立一个链接:

ln -s /tmp/MysqL.sock /var/lib/MysqL/MysqL.sock

二.安装PHP

#cd ~/soft

1.首先安装iconv,否则安装PHP的时候会提示这个错误

cd ~/soft/
tar zxvf libiconv-1.13.1.tar.gz
cd libiconv-1.13.1/
./configure --prefix=/usr/local
make
make install
cd ../

#####################################################################

#yum install libmcrypt libmcrypt-devel mcrypt mhash

或者使用下面源包编译安装

下载地址

http://sourceforge.net/projects/mcrypt/files/Libmcrypt/
http://sourceforge.net/projects/mcrypt/files/MCrypt/
http://sourceforge.net/projects/mhash/files/mhash/

先安装Libmcrypt,再安装mhash,再安装mcrypt

2 .先安装Libmcrypt

tar -zxvf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8
./configure
#make
#make install 说明:libmcript默认安装在/usr/local
#cd ../

3.安装mhash

tar -zxvf mhash-0.9.9.9.tar.gz
cd mhash-0.9.9.9
./configure
make
make install
cd ../

4.安装mcrypt

tar -zxvf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8
LD_LIBRARY_PATH=/usr/local/lib ./configure
make
make install
cd ../

最后,还是检查下,是否安装成功

如果configure mcrypt时提示找不到libmcrypt的库,给个参考的解决方法

export LD_LIBRARY_PATH=/usr/local/lib: LD_LIBRARY_PATH

######################################################################

tar zxvf PHP-5.5.16.tar.gz
cd PHP-5.5.16
./configure --prefix=/usr/local/PHP --with-config-file-path=/usr/local/PHP/etc --with-MysqL=/usr/local/MysqL --with-MysqLi=/usr/local/MysqL/bin/MysqL_config --with-iconv-dir=/usr/local --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-fpm --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-ldap --with-ldap-sasl --with-xmlrpc --enable-zip --enable-soap --without-pear

make ZEND_EXTRA_LIBS='-liconv'
make install
cp PHP.ini-production /usr/local/PHP/etc/PHP.ini
cd ../

在configure过程中如果出现以下错误:

configure: error: Cannot find ldap libraries in /usr/lib.

解决办法:

cp -frp /usr/lib64/libldap* /usr/lib

如果出现“configure: error: Don't know how to define struct flock on this system,set --enable-opcache=no”之类的错误
解决办法:
sudo ln -s /usr/local/MysqL/lib/libMysqLclient.so /usr/lib/
sudo ln -s /usr/local/MysqL/lib/libMysqLclient.so.18 /usr/lib/libMysqLclient.so.18

在/etc/ld.so.conf.d中添加local.conf文件

#echo "/usr/local/lib">> /etc/ld.so.conf.d/local.conf

更新动态库:

#ldconfig -v

如果在make的过程中出现以下错误:

/root/dev/PHP-5.*.*/sapi/cli/PHP: error while loading shared libraries: libMysqLclient.so.18: cannot open shared object file: No such file or directory
make: *** [ext/phar/phar.PHP] Error 127

解决办法 (http://blog.haohtml.com/archives/12479)

ln -s /usr/local/MysqL/lib/libMysqLclient.so.18 /usr/lib64/

如果按上面的操作,再次执行 make ZEND_EXTRA_LIBS='-liconv' 后提示以下错误:

"chmod: cannot access `ext/phar/phar.phar': No such file or directory"

只需要重装执行上面的configure命令即可.只需要在./configure的后面加上--without-pear即可解决办法:http://blog.haohtml.com/archives/12482

如果在make install的时候还提示上面类似的错误,只需要重新从./configure开始再执行一下就可以了.

其它错误参考:http://hi.baidu.com/cfanbo/item/8ff7d41f4fde6c001994ec43

三.安装PHP扩展

tar zxvf memcache-2.2.7.tgz
cd memcache-2.2.7/
/usr/local/PHP/bin/PHPize
./configure --with-PHP-config=/usr/local/PHP/bin/PHP-config
make
make install
cd ../

########################################

tar zxvf ImageMagick-6.8.9-7.tar.gz
cd ImageMagick-6.8.9-7/
./configure
make
make install
cd ../

tar zxvf imagick-3.1.2.tgz
cd imagick-3.1.2/
/usr/local/PHP/bin/PHPize
./configure --with-PHP-config=/usr/local/PHP/bin/PHP-config
make
make install
cd ../

可是出错了一个问题.就是死说找不到MagickWand.h:

checking for MagickWand.h header file... configure: error: Cannot locate header file MagickWand.h

可是我明明正确安装了ImageMagick的呀.GOOGLE了半天,也解决不了这个问题.后面对照另一个服务器上的ImageMagick才发现,原来ImageMagick 6.8这个版后的目录结构变了,旧版本头文件是放在/usr/local/include/ImageMagick目录的,而ImageMagick 6.8则是放在/usr/local/include/ImageMagick-6

添加软连接,命令如下:

ln -s /usr/local/include/ImageMagick-6 /usr/local/include/ImageMagick
make && make && install

编译通过!

#############################################

安装pdo_MysqL扩展

cd ~/soft/PHP-5.5.16/ext/
cd pdo_MysqL
/usr/local/PHP/bin/PHPize
./configure --with-PHP-config=/usr/local/PHP/bin/PHP-config --with-pdo-MysqL=/usr/local/MysqL
make
make install

#如果这里的方法不行,需要使用独立的安装包来编译了http://pecl.php.net/get/PDO_MYSQL-1.0.2.tgz,这里使用这种方法有问题。

//配置PHP.ini

vi /usr/local/PHP/etc/PHP.ini

找到extension_dir,删除前面的;,在后面指定为下面的目录位置

/usr/local/PHP/lib/PHP/extensions/no-debug-non-zts-20121212/

并在此行后增加以下几行,然后保存:

extension = "memcache.so"
extension = "imagick.so"
extension = "pdo_MysqL.so"

1.再查找output_buffering = Off,修改为 output_buffering = On.

2.为了安装起见,隐藏http头信息里的PHP信息,查找 expose_PHP = on 修改expose_PHP = off

3.再查找; cgi.fix_pathinfo=0,把前面的;注释符号删除,改为cgi.fix_pathinfo=0,预防方法:防止Nginx文件类型错误解析漏洞。

4.找到;date.timezone= 修改date.timezone = PRC,修正PHP中于真实时间相关8小时的问题.

PHP.ini文件最后添加启用opcache功能的选项

zend_extension=opcache.so
[opcache]
opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=4000
opcache.revalidate_freq=60
opcache.fast_shutdown=1
opcache.enable=1
opcache.enable_cli=1

配置PHP-fpm

//创建www用户,PHP-fpm和Nginx统一使用这个

groupadd www
useradd -g www www

cp /usr/local/PHP/etc/PHP-fpm.conf.default /usr/local/PHP/etc/PHP-fpm.conf

vi /usr/local/PHP/etc/PHP-fpm.conf

修改以下两行,并将服务用户名用户所在组(nobody),修改为www

user = www
group = www

启用PHP-fpm

/usr/local/PHP/sbin/PHP-fpm

停止的话,用

killall PHP-fpm

四 安装Nginx

#安装正则表达式库,支持rewite

cd ~/soft
tar zxvf pcre-8.35.tar.gz
cd pcre-8.35/
./configure
make && make install
cd ../

tar zxvftengine-2.0.3.tar.gz
cdtengine-2.0.3/
./configure --user=www --group=www --prefix=/usr/local/Nginx --with-http_stub_status_module --with-http_ssl_module
make && make install
cd ../

vi /usr/local/Nginx/conf/Nginx.conf

修改 /usr/local/Nginx/conf/Nginx.conf,删除user nobody;行前面的注释,并修改为userwww www;
将以下几行前面的注释删除,将修改fastcgi_param后面的路径

location ~ \.PHP$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.PHP;
fastcgi_param SCRIPT_FILENAME /usr/local/Nginx/html$fastcgi_script_name;
include fastcgi_params;
}

测试Nginx.conf配置文件

/usr/local/Nginx/sbin/Nginx -t

启用Nginx

/usr/local/Nginx/sbin/Nginx

重新加载配置文件

/usr/local/Nginx/sbin/Nginx -s reload

五.全局配置

vi /etc/rc.local

按shift+g快捷键,在末尾增加以下内容

ulimit -SHn 65535
/usr/local/PHP/sbin/PHP-fpm
/usr/local/Nginx/sbin/Nginx

测试是否支持PHP

vi /usr/local/Nginx/html/PHPinfo.PHP

输入内容 <?PHP PHPinfo(); ?>

浏览http://ip地址/PHPinfo.PHP,可以看到PHP的相关信息,可以查看扩展是否支持.

以上使用的是Nginx的默认配置,为了充分发挥Nginx性能,实际生产过程中,我们还需要对Nginx进行一些配置优化,请参考:Nginx优化配置(转)

参考文章:http://blog.haohtml.com/archives/6051

参考:http://hi.baidu.com/cfanbo/item/9482bf3ced39f0c11b969681

原文链接:https://www.f2er.com/centos/376560.html

猜你在找的CentOS相关文章