系统相关
首页 > 系统相关> > linux安装php5.6

linux安装php5.6

作者:互联网

引用:https://blog.csdn.net/baidu_37895884/article/details/78125932

 

 系统环境:

下载 PHP 源码包

  1.   wget http://cn2.php.net/distributions/php-5.6.0.tar.xz
  2.   xz -d php-5.6.0.tar.xz
  3.   tar xf php-5.6.0.tar -C /usr/local/src/

添加 epel 源

rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

安装依赖

apt-get install libxml2-dev libssl-dev libbz2-dev libcurl3-dev libdb5.1-dev libjpeg-dev libpng-dev libXpm-dev libfreetype6-dev libt1-dev libgmp3-dev libc-client-dev libldap2-dev libmcrypt-dev libmhash-dev freetds-dev libz-dev libmysqlclient15-dev ncurses-dev libpcre3-dev unixODBC-dev postgresql-server-dev-9.1 libsqlite-dev libaspell-dev libreadline6-dev librecode-dev libsnmp-dev libtidy-dev libxslt-dev libt1-dev
yum install gcc bison bison-devel zlib-devel libmcrypt-devel mcrypt mhash-devel openssl-devel libxml2-devel libcurl-devel bzip2-devel readline-devel libedit-devel sqlite-devel jemalloc jemalloc-devel
./configure --with-php-config=/usr/local/php/bin/php-config --enable-jemalloc

注:如果你使用的 epel 7 的源,可能会没有 mcrypt mhash mhash-devel 几个包,在 http://dl.fedoraproject.org/pub/epel/6/x86_64/ 中下载,使用 yum localinstall xxx.rpm 或 rpm -Uvh xxx.rpm 手动安装即可。

创建 www 用户

  1.   groupadd www
  2.   useradd -g www -s /sbin/nologin -M www

编译安装

  1.   cd /usr/local/src/php-5.6.0/
  2.    
  3.   ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-inline-optimization --disable-debug --disable-rpath --enable-shared --enable-opcache --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-gettext --enable-mbstring --with-iconv --with-mcrypt --with-mhash --with-openssl --enable-bcmath --enable-soap --with-libxml-dir --enable-pcntl --enable-shmop --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-sockets --with-curl --with-zlib --enable-zip --with-bz2 --with-readline

参数说明:

  1.   """ 安装路径 """
  2.   --prefix=/usr/local/php56 \
  3.   """ php.ini 配置文件路径 """
  4.   --with-config-file-path=/usr/local/php56/etc \
  5.   """ 优化选项 """
  6.   --enable-inline-optimization \
  7.   --disable-debug \
  8.   --disable-rpath \
  9.   --enable-shared \
  10.   """ 启用 opcache,默认为 ZendOptimizer+(ZendOpcache) """
  11.   --enable-opcache \
  12.   """ FPM """
  13.   --enable-fpm \
  14.   --with-fpm-user=www \
  15.   --with-fpm-group=www \
  16.   """ MySQL """
  17.   --with-mysql=mysqlnd \
  18.   --with-mysqli=mysqlnd \
  19.   --with-pdo-mysql=mysqlnd \
  20.   """ 国际化与字符编码支持 """
  21.   --with-gettext \
  22.   --enable-mbstring \
  23.   --with-iconv \
  24.   """ 加密扩展 """
  25.   --with-mcrypt \
  26.   --with-mhash \
  27.   --with-openssl \
  28.   """ 数学扩展 """
  29.   --enable-bcmath \
  30.   """ Web 服务,soap 依赖 libxml """
  31.   --enable-soap \
  32.   --with-libxml-dir \
  33.   """ 进程,信号及内存 """
  34.   --enable-pcntl \
  35.   --enable-shmop \
  36.   --enable-sysvmsg \
  37.   --enable-sysvsem \
  38.   --enable-sysvshm \
  39.   """ socket & curl """
  40.   --enable-sockets \
  41.   --with-curl \
  42.   """ 压缩与归档 """
  43.   --with-zlib \
  44.   --enable-zip \
  45.   --with-bz2 \
  46.   """ GNU Readline 命令行快捷键绑定 """
  47.   --with-readline

如果你的 Web Server 使用的 Apache 请添加类似:--with-apxs2=/usr/local/apache-xx/bin/apxs 参数。

关于 mysqlnd 请查看 什么是 PHP 的 MySQL Native 驱动? 或查看 MySQL 官方介绍:MySQL native driver for PHP, 或 Installation on Unix

PHP 5.6 內建了 phpdbg 交互式调试器,通过 --enable-phpdbg 开启,会在 PREFIX/bin 目录下产生一个 phpdbg 命令,感兴趣的可以试一下。

更多编译参数请使用 ./configure --help 查看。

# make && make install

如果想重新安装:

  1.   make clean
  2.   make clean all
  3.    
  4.   ./configure ...
  5.   make && make install

配置 PHP

配置文件:

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

php-fpm 服务

  1.   cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
  2.   cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
  3.   chmod +x /etc/init.d/php-fpm

启动 php-fpm

  1.   service php-fpm start
  2.   Starting php-fpm done

php-fpm 可用参数 start|stop|force-quit|restart|reload|status

添加 PHP 命令到环境变量

编辑 ~/.bash_profile,将:

  1.   PATH=$PATH:$HOME/bin
  2.   改为:
  3.   PATH=$PATH:$HOME/bin:/usr/local/php/bin

使 PHP 环境变量生效:

~/.bash_profile

查看看 PHP 版本

  1.   php -v
  2.   PHP 5.6.0 (cli) (built: Sep 23 2014 03:44:18)
  3.   Copyright (c) 1997-2014 The PHP Group
  4.   Zend Engine v2.6.0, Copyright (c) 1998-2014 Zend Technologies
转载请注明出处。
本文地址:http://blog.aboutc.net/linux/65/compile-and-install-php-on-linux

标签:enable,--,dev,devel,fpm,linux,php5.6,安装,php
来源: https://www.cnblogs.com/shuangxinye/p/13653416.html