PHP5.6
- 1 下载安装包
#wget http://mirrors.sohu.com/php/php-5.6.2.tar.gz
#tar -zxf php-5.6.2
- 2 安装php依赖
#yum install gcc gcc-c++ libxml2 libxml2-devel libjpeg-devel libpng-devel freetype-devel openssl-devel libcurl-devel libmcrypt-devel
- 3 安装 (-prefix是安装目录,-with-mysql是mysql的安装目录)
#./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --enable-pcntl --enable-mysqlnd --enable-opcache --enable-sockets --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-shmop --enable-zip --enable-ftp --enable-soap --enable-xml --enable-mbstring --disable-rpath --disable-debug --disable-fileinfo --with-mysql --with-mysqli --with-pdo-mysql --with-pcre-regex --with-iconv --with-zlib --with-mcrypt --with-gd --with-openssl --with-mhash --with-xmlrpc --with-curl --with-imap-ssl
#make
#make install
- 4 若上几步都没报错的话就安装成功,有报错估计是少了点什么,用百度查查后yum一下吧。
#cp php.ini-production /usr/local/php/etc/php.ini
- 5 当我们使用nginx还要把php-fpm.conf放到/usr/local/php/etc/里
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
- 6 接下来我们还可能需要将php-fpm作为server服务
#cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
- 7 设置权限,并添加服务
#chmod +x /etc/init.d/php-fpm
#chkconfig --add php-fpm
- 8 以后可以使用如下命令管理php-fpm了
#service php-fpm start
#service php-fpm stop
#service php-fpm restart
#service php-fpm reload
Nginx
- 1 安装依赖
yum -y install pcre* openssl*
- 2下载源码包
wget http://nginx.org/download/nginx-1.9.7.tar.gz
- 3 安装
tar -zxvf nginx-1.9.7.tar.gz
cd nginx-1.9.7
./configure --user=www --group=www --prefix=/usr/local/nginx-1.9.7 --with-http_stub_status_module
make;
make install
- 3 Nginx整合PHP
vi /usr/local/nginx/conf/nginx.conf
...
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
PHP安装错误:
undefined reference to `libiconv_open'
make ZEND_EXTRA_LIBS='-liconv'
ln -s /usr/local/lib/libiconv.so.2 /usr/lib64/
configure: error: mcrypt.h not found. Please reinstall libmcrypt.
wget http://jaist.dl.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz
tar -zxvf libmcrypt-2.5.8.tar.gz
./configure
make
make install
Don't know how to define struct flock on this system, set --enable-opcache=no
vim /etc/ld.so.conf.d/local.conf # 编辑库文件
/usr/local/lib # 添加该行
:wq # 保存退出
ldconfig -v # 使之生效
环境变量设置
方法一:
直接运行命令export PATH=$PATH:/usr/local/php/bin,只会对当前会话临时生效。
方法二:
执行 vi ~/.bash_profile
修改文件中PATH一行,将/usr/local/php/bin加入到PATH=$PATH:$HOME/.local/bin:$HOME/bin一行之后
这种方法只对当前登录用户生效
方法三:
修改/etc/profile文件使其永久性生效,并对所有系统用户生效,在文件末尾加上如下两行代码:
PATH=$PATH:/usr/local/php/bin
export PATH
最后:执行 命令source /etc/profile生效,执行完可通过echo $PATH命令查看是否添加成功。