Linux-CentOS6.9安装PHP5.6

Linux-CentOS6.9安装PHP5.6

sudo -s
安装依赖
yum install libxml2-devel curl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel net-snmp net-snmp-devel libXpm*

安装依赖 libiconv 选其中一个版本安装

libiconv-1.15

cd /data0/software
wget https://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.15.tar.gz
tar zxvf libiconv-1.15.tar.gz
cd libiconv-1.15
./configure --prefix=/usr/local/libiconv
make
make install
ldconfig
cd ../

libiconv-1.14

cd /data0/software
wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz
tar zxvf libiconv-1.14.tar.gz
cd libiconv-1.14
./configure --prefix=/usr/local/libiconv
make
make install
cd ../

安装依赖 libmcrypt

cd /data0/software
wget http://nchc.dl.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz
tar zxvf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8
./configure
make && make install

/sbin/ldconfig
cd libltdl/
./configure --enable-ltdl-install
make
make install
cd ../../

安装依赖 mhash

cd /data0/software
wget http://nchc.dl.sourceforge.net/project/mhash/mhash/0.9.9.9/mhash-0.9.9.9.tar.gz
tar zxvf mhash-0.9.9.9.tar.gz
cd mhash-0.9.9.9/
./configure
make
make install
cd ../

创建软链接

ln -s /usr/local/lib/libmcrypt.la /usr/lib/libmcrypt.la
ln -s /usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.so
ln -s /usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4
ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib/libmcrypt.so.4.4.8
ln -s /usr/local/lib/libmhash.a /usr/lib/libmhash.a
ln -s /usr/local/lib/libmhash.la /usr/lib/libmhash.la
ln -s /usr/local/lib/libmhash.so /usr/lib/libmhash.so
ln -s /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2
ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib/libmhash.so.2.0.1
ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config

安装依赖 mcrypt

cd /data0/software
wget http://nchc.dl.sourceforge.net/project/mcrypt/MCrypt/2.6.8/mcrypt-2.6.8.tar.gz
tar zxvf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8/
/sbin/ldconfig
./configure
make
make install
cd ../
安装PHP-5.6.35

官网手动下载 php-5.6.35.tar.gz

cd /data0/software

# 解压
tar zxvf php-5.6.35.tar.gz
cd php-5.6.35/

./configure \
--prefix=/usr/local/php56 \
--with-config-file-path=/usr/local/php56/etc \
--with-mysql=mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-iconv-dir=/usr/local/libiconv \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--with-libxml-dir=/usr \
--enable-xml \
--disable-rpath \
--enable-discard-path \
--enable-safe-mode \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-inline-optimization \
--with-curl \
--with-curlwrappers \
--enable-mbregex \
--enable-fastcgi \
--enable-fpm \
--enable-force-cgi-redirect \
--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 \
--with-libdir=lib64

# --with-libdir=lib64         # 64位系统需指定 lib64 32位系统去掉此项

make
make install

cp php.ini-development /usr/local/php56/etc/php.ini
cd ../

修改php.ini配置

vim /usr/local/php56/etc/php.ini

# 找到 ;cgi.fix_pathinfo=1 修改为
cgi.fix_pathinfo=0

# 找到 ;date.timezone = 修改为
date.timezone = PRC

安装成功 查看版本

/usr/local/php56/bin/php -v                 # 查看PHP版本

PHP 5.6.35 (cli) ...

/usr/local/php56/bin/php -r "phpinfo();"    # 打印phpinfo
配置php-fpm

修改php-fpm配置文件

cp /usr/local/php56/etc/php-fpm.conf.default /usr/local/php56/etc/php-fpm.conf

vi /usr/local/php56/etc/php-fpm.conf

user = www
group = www

# 找到 ;pid = run/php-fpm.pid 修改为
pid = /usr/local/php56/var/run/php-fpm.pid

# 找到 listen = 127.0.0.1:9000 如果启了多个php-fpm 9000端口被占用的话 换一个端口
listen = 127.0.0.1:9000

启动 php-fpm

/usr/local/php56/sbin/php-fpm                            # 启动

kill -INT `cat /usr/local/php56/var/run/php-fpm.pid`     # 关闭

kill -USR2 `cat /usr/local/php56/var/run/php-fpm.pid`    # 重启 或者关闭在启动

查看是否启动

ps -ef |grep php-fpm         # 能看到类似如下信息 启动成功

root      1805     1  0 09:48 ?        00:00:00 php-fpm: master process (/usr/local/php56/etc/php-fpm.conf)

配置 php-fpm 启动脚本 注册为系统服务 设置开机启动

cp /data0/software/php-5.6.35/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm

授予可执行权限

chmod +x /etc/init.d/php-fpm

添加php-fpm至服务列表并设置开机自启

chkconfig --add php-fpm
chkconfig --list php-fpm
chkconfig php-fpm on

php-fpm 几个参数 start|stop|force-quit|restart|reload|status

service php-fpm start       # 启动服务
service php-fpm stop        # 停止服务
service php-fpm restart     # 重启服务
service php-fpm reload      # 平滑重启服务
service php-fpm force-quit  # 强制退出服务
service php-fpm status      # 查看服务状态
Nginx新建server

新建网站目录

mkdir -p /data0/vhosts/php56
chmod +w /data0/vhosts/php56
chown -R www:www /data0/vhosts/php56

修改nginx.conf配置 新增server

vi nginx.conf

server
{
    listen       80;
    server_name  dev.php56.gocuber.com;
    index index.html index.htm index.php;
    root  /data0/vhosts/php56;

    location ~* \.php$ {
        fastcgi_index   index.php;
        fastcgi_pass    127.0.0.1:9000;
        include         fastcgi_params;
        fastcgi_param   SCRIPT_FILENAME    $document_root$fastcgi_script_name;
        fastcgi_param   SCRIPT_NAME        $fastcgi_script_name;
    }

    access_log  /data0/logs/wwwlogs.log  wwwlogs;
}

检查nginx配置 平滑重启nginx

/usr/local/nginx/sbin/nginx -t
/usr/local/nginx/sbin/nginx -s reload

/data0/vhosts/php56新建phpinfo.php index.php

phpinfo();

访问
http://dev.php56.gocuber.com/phpinfo.php

安装常见问题及解决方法

如果64位系统报类似如下错误

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

首先检查configure配置项

--with-libdir=lib64     # 64位系统需指定lib64 32位系统去掉此项

或执行以下命令

cp -frp /usr/lib64/libldap* /usr/lib/
cp -frp /usr/lib64/libltdl.so* /usr/lib/
cp -frp /usr/lib64/libXpm.so* /usr/lib/
已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页