centos6.8服务器配置之编译安装PHP、配置nginx

php version 5.6.31、nginx version: nginx/1.10.2

1、下载:

wget http://cn2.php.net/distributions/php-5.6.31.tar.gz

2、安装组件

yum install -y gcc gcc-c++ make zlib zlib-devel pcre pcre-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel openssl openssl-devel openldap openldap-devel  openldap-clients openldap-servers php-mcrypt  libmcrypt  libmcrypt-devel

3、解决64位系统的问题,编译时会报错:configure: error: Cannot find ldap libraries in /usr/lib

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

4、安装liviconv

1.15版

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

1.13版

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

两个版本任选其一即可

find / -name libiconv.so.2
ln -s /usr/local/lib/libiconv.so.2 /usr/lib/libiconv.so.2
ldconfig

5、编译

./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql --with-mysqli --with-iconv-dir=/usr/local --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib-dir --with-libxml-dir=/usr --with-pdo-mysql --with-openssl --with-curl --with-ldap --with-ldap-sasl --with-xmlrpc --with-mcrypt --with-gd --with-zlib --with-mhash --disable-rpath --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --enable-mbregex --enable-fpm --enable-mbstring --enable-gd-native-ttf --enable-pcntl --enable-sockets --enable-zip --enable-soap --without-pear --disable-phar --enable-pdo 

编译配置说明:

# 指定 php 安装目录
--prefix=/usr/local/php

# 指定php.ini位置
--with-config-file-path=/usr/local/php/etc 

# mysql安装目录,对mysql的支持
--with-mysql

#mysqli扩展技术不仅可以调用MySQL的存储过程、处理MySQL事务,而且还可以使访问数据库工作变得更加稳定。
--with-mysqli=/usr/local/mysql/bin/mysql_config  

#整合 apache,apxs功能是使用mod_so中的LoadModule指令,加载指定模块到 apache,要求 apache 要打开SO模块
--with-apxs2=/usr/local/apache/bin/apxs 

# 选项指令 --with-iconv-dir 用于 PHP 编译时指定 iconv 在系统里的路径,否则会扫描默认路径。
--with-iconv-dir=/usr/local 
--without-iconv   关闭iconv函数,字符集间的转换
--with-freetype-dir   打开对freetype字体库的支持 
--with-jpeg-dir   打开对jpeg图片的支持 
--with-png-dir   打开对png图片的支持 
--with-zlib-dir   打开zlib库的支持,用于http压缩传输
--with-libxml-dir   打开libxml2库的支持
--with-curl    打开curl浏览工具的支持 
--with-curlwrappers    运用curl工具打开url流 
--with-mcrypt                    mcrypt算法扩展
--with-mhash                     mhash算法扩展
--with-gd    打开gd库的支持 
--with-openssl      openssl的支持,加密传输https时用到的
--with-xmlrpc    打开xml-rpc的c语言 
--with-bz2    打开对bz2文件的支持        
--with-ttf     打开freetype1.*的支持,可以不加了 
--with-xsl     打开XSLT 文件支持,扩展了libXML2库 ,需要libxslt软件 
--with-gettext     打开gnu 的gettext 支持,编码库用到 
--with-pear    打开pear命令的支持,PHP扩展用的 
--with-mime-magic=/usr/share/file/magic.mime      魔术头文件位置

--disable-rpath    关闭额外的运行库文件 
--disable-debug    关闭调试模式 

--enable-bcmath    打开图片大小调整,用到zabbix监控的时候用到了这个模块
--enable-shmop --enable-sysvsem  这样就使得你的PHP系统可以处理相关的IPC函数了。
--enable-inline-optimization  优化线程

--enable-mbregex
--enable-fpm 打上PHP-fpm 补丁后才有这个参数,CGI方式安装的启动程序
--enable-mbstring    多字节,字符串的支持 
--enable-gd-native-ttf   支持TrueType字符串函数库
--enable-pcntl   freeTDS需要用到的,可能是链接mssql 才用到
--enable-sockets     打开 sockets 支持
--enable-zip   打开对zip的支持 
--enable-ftp   打开ftp的支持 
--enable-calendar    打开日历扩展功能
--enable-exif    图片的元数据支持 
--enable-magic-quotes    魔术引用的支持 

#以下是CGI方式安装才用的参数
--enable-fastCGI            支持fastcgi方式启动PHP
--enable-force-CGI-redirect        重定向方式启动PHP
--with-ncurses         支持ncurses 屏幕绘制以及基于文本终端的图形互动功能的动态库
--with-gmp  应该是支持一种规范
--enable-dbase                     建立DBA 作为共享模块
--with-pcre-dir=/usr/local/bin/pcre-config      perl的正则库案安装位置
--disable-dmalloc
--with-gdbm                     dba的gdbm支持
--enable-sigchild
--enable-sysvshm
--enable-zend-multibyte         支持zend的多字节
--enable-wddx
--enable-soap

常见问题:

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

解决方法:cp -frp /usr/lib64/libldap* /usr/lib/

可能的原因是安装了64位的系统,在lib64下面有这个文件,可能在lib这文件夹里面没有,所以强制复制一次。

2、configure: error: Cannot find ldap.h,发现依赖于openldap包,通过yum解决问题:
解决方法:yum install -y openldap install openldap-devel

3、WARNING: unrecognized options: --enable-discard-path, --enable-safe-mode, --with-curlwrappers, --enable-fastcgi, --enable-force-cgi-redirect
解决办法:说明参数被废弃了

4、PEAR package PHP_Archive not installed: generated phar will require PHP's phar extension be enabled.
php 的编译时需要依赖pear package ,目前的问题错误"PEAR package PHP_Archive not installed",已经明显报出这个问题。 
因此编译使用参数 --without-pear   将pear 屏蔽掉编译安装后,再进行安装;同时因为phar 属于pear的一个库 ,所以不将phar关闭掉,同时还会报这个错误, 
同时需要使用 --disable-phar   编译参数. 

./configure --without-pear  --disable-phar
make
make install
成功编译安装完成后,再安装pear

wget  http://pear.php.net/go-pear.phar 
/usr/local/bin/php go-pear.phar


5、Bug #72663: Create an Unexpected Object and Don't Invoke __wakeup() in Deserialization [ext/standard/tests/strings/bug72663_3.phpt] (warn: XFAIL section but test passes)
直接make install

5、ext/xmlrpc/libxmlrpc/.libs/encodings.o: In function `convert':
/usr/local/php/ext/xmlrpc/libxmlrpc/encodings.c:73: undefined reference to `libiconv_open'
/usr/local/php/ext/xmlrpc/libxmlrpc/encodings.c:81: undefined reference to `libiconv'
/usr/local/php/ext/xmlrpc/libxmlrpc/encodings.c:101: undefined reference to `libiconv_close'
collect2: ld returned 1 exit status
make: *** [sapi/cli/php] Error 1


/usr/local/php/sapi/cli/php: error while loading shared libraries: libiconv.so.2: cannot open shared object file: No such file or directory
make[1]: *** [install-pear-installer] Error 127          #很明显meke  install的时候找不到libiconv.so.2的库文件了
make: *** [install-pear] Error 2                            #貌似这个错误在Centos6.x上面每次编译都会报错!



解决的方法如下:


1.在/etc/ld.so.conf中加一行/usr/local/lib,


2.然后运行/sbin/ldconfig

这样就ok了它就能找到库文件了

Bug #52202 (CURLOPT_PRIVATE gets clobbered) [ext/curl/tests/bug52202.phpt]

 

 

6、

make ZEND_EXTRA_LIBS='-liconv'
make test
make install

7、给php创建专有的用户和组www-data

groupadd www-data
useradd -g www-data www-data -s /sbin/nologin

8、配置php-fpm(php自带)

#修改php-fpm的默认配置,并使php-fpm以www-data用户的身份运行:
cd /usr/local/php/etc
cp php-fpm.conf.default php-fpm.conf

vim php-fpm.conf
#找到并修改为以下行:
pid = run/php-fpm.pid
user = www-data
group = www-data
#找到并修改以下行
listen = 127.0.0.1:9000

9、启动php-fpm

/usr/local/php/sbin/php-fpm

10、添加php-fpm为系统服务

检测/usr/local/php/var/run/php-fpm.pid是否存在:

若不存在:去除/usr/local/php/etc/php-fpm.conf里的“;pid = run/php-fpm.pid”前面的分号,并重启php-fpm就会自动生成php-fpm.pid

如何重启php-fpm(当然重启系统也是可以的):

#查看php-fpm当前的进程
ps -ef | grep php-fpm
#结束php-fpm所有进程即可
kill -9 进程id
#启动php-fpm
/usr/local/php/sbin/php-fpm

新建php-fpm文件

vim /etc/init.d/php-fpm

添加内容如下

#! /bin/sh
# Comments to support chkconfig on CentOS
# chkconfig: 2345 65 37
#
set -e
 
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DESC="php-fpm daemon"
NAME=php-fpm
DAEMON=/usr/local/php/sbin/$NAME
 
CONFIGFILE=/usr/local/php/etc/php-fpm.conf
PIDFILE=/usr/local/php/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
 
# Gracefully exit if the package has been removed.
test -x $DAEMON || exit 0
 
d_start() {
  $DAEMON -y $CONFIGFILE || echo -n " already running"
}
 
d_stop() {
  kill -QUIT `cat $PIDFILE` || echo -n " not running"
}
 
d_reload() {
  kill -HUP `cat $PIDFILE` || echo -n " can't reload"
}
 
case "$1" in
  start)
        echo -n "Starting $DESC is success"
        d_start
        echo "."
        ;;
  stop)
        echo -n "Stopping $DESC is success"
        d_stop
        echo "."
        ;;
  reload)
        echo -n "Reloading $DESC configuration..."
        d_reload
        echo "reloaded."
  ;;
  restart)
        echo -n "Restarting $DESC is success"
        d_stop
        sleep 1
        d_start
        echo "."
        ;;
  *)
         echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
         exit 3
        ;;
esac

修改其权限并开机启动

#修改权限
chmod 755 /etc/init.d/php-fpm
#开机启动
chkconfig php-fpm on
#查看开机启动的服务
chkconfig --list

11、启动

#启动服务
service php-fpm start
#停止服务
service php-fpm stop
#重启服务
service php-fpm reload

12、安装nginx

yum install nginx -y

13、nginx配置

server {
    listen       80;
    server_name  www.baidu.com;
    root   /www/web/pc;

       index  index.php;
    location / {
     
    #       root /www/web/pc;
      # index  index.php;
    }

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
    location ~ \.php$ {
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }

    location ~ /\.ht {
        deny  all;
    }
}

14、启动nginx

#检查语法
/usr/sbin/nginx -t
#启动
/usr/sbin/nginx
#重启
/usr/sbin/nginx -s reload

15、web目录权限配置

#查看php-fpm、nginx的用户
ps aux|grep nginx
ps aux|grep php-fpm
#php-fpm的用户不能是web目录的拥有者,最小权限原则
web rwx r-- r-x root vuser 
cache rwx rwx rwx root root

 

posted @ 2017-09-18 20:25  做个好男人  阅读(1945)  评论(0编辑  收藏  举报