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
centos6.8服务器配置之编译安装PHP、配置nginx的更多相关文章
- centos6.9 PHP的编译安装并连接nginx
1.安装yum -y install libxml2-devel openssl-devel bzip2-devel libmcrypt-devel 解决php包的依赖关系,可能libmcrypt会报 ...
- CentOS6.7下使用非root用户(普通用户)编译安装与配置mysql数据库并使用shell脚本定时任务方式实现mysql数据库服务随机自动启动
CentOS6.7下使用非root用户(普通用户)编译安装与配置mysql数据库并使用shell脚本定时任务方式实现mysql数据库服务随机自动启动1.关于mysql?MySQL是一个关系型数据库管理 ...
- libCURL开源库在VS2010环境下编译安装,配置详解
libCURL开源库在VS2010环境下编译安装,配置详解 转自:http://my.oschina.net/u/1420791/blog/198247 http://blog.csdn.net/su ...
- CentOS-6.6下Tomcat-7.0安装与配置(Linux)
CentOS-6.6下Tomcat-7.0安装与配置(Linux) 一.认识tomcat Tomcat是一个免费的开源的Serlvet容器,它是Apache基金会的Jakarta项目中的一个核心项目, ...
- Centos6下Python3的编译安装
本文转载自 Centos6下Python3的编译安装 系统环境:CentOS 6.8-Minimal 安装Python依赖包: 1 [root@Python src]# yum install zli ...
- centos6.8下redis的安装和配置
centos6.8下redis的安装和配置 下载.安装 在redis官网可以获取到最新版本的redis 进入/usr/local/目录,执行如下命令 wget http://download.redi ...
- CentOS 7上源码编译安装和配置LNMP Web+phpMyAdmin服务器环境
CentOS 7上源码编译安装和配置LNMP Web+phpMyAdmin服务器环境 什么是LNMP? LNMP(别名LEMP)是指由Linux, Nginx, MySQL/MariaDB, PHP/ ...
- php编译安装与配置
php编译安装与配置 =========================================== 官网:http://php.net/ 官网下载:http://php.net/downlo ...
- 编译安装php、nginx
以centos6.6为例 1.安装以及配置php 首先在官网下载源码包http://php.net/downloads.php 这里下载php-7.1.16 .tar.gzcd php-7.1.16 ...
随机推荐
- Monty Hall悖论
Monty Hall悖论又称为蒙提·霍尔悖论.三门问题.Monty Hall是上个世纪60年代,电视游戏节目“Let's Make a Deal”的主持人,这个悖论便是以他的名字来命名的.节目的规则是 ...
- AC日记——[Sdoi2010]粟粟的书架 bzoj 1926
1926 思路: 主席树+二分水题: 代码: #include <bits/stdc++.h> using namespace std; #define maxn 500005 #defi ...
- 【已解决】php本地环境超级慢
打开 C:\Windows\System32\drivers\etc去掉 #127.0.0.1 localhost 前面的#保留 #::1 localhost 前面的#
- (5) go 控制台输入输出、进制转换、原反补码、位运算
一.控制台接受输入 二.原反补码 三.位运算 四.移位运算
- VisualStudio 2013 快捷键
有些快捷键不是默认的,需要插件支持,如Resharper,WebEssentials,VSCommands Ctrl单键系列 Ctrl+Q Quick Info Ctrl+W Extend Selec ...
- STL容器 -- Priority_Queue
核心:和队列相似,但优先队列中的 “下一个元素” 指的是 “优先级最高” 的元素. 头文件:#include<queue> 普通类型的构造方法: priority_queue<int ...
- SystemProperties cannot be resolved错误
单独用eclipse打开一个工程,出现SystemProperties.get()会出现SystemProperties cannot be resolved.错误 1. 引用SystemProper ...
- 【linux入门必备】小白需要掌握的基础知识_不定期更新
因为博主对linux掌握暂时不需要太精通,遇到一个记录一个. 零碎 知识点: 杂类常用命令: 模糊匹配补齐 TAB 系统相关命令: 查阅手册 man 更新软件 sudo apt-get update ...
- 洛谷——P2299 Mzc和体委的争夺战
P2299 Mzc和体委的争夺战 题目背景 mzc与djn第四弹. 题目描述 mzc家很有钱(开玩笑),他家有n个男家丁(做过前三弹的都知道).但如此之多的男家丁吸引来了我们的体委(矮胖小伙),他要来 ...
- HZAU 1203 One Stroke(倍增)
题目链接:http://acm.hzau.edu.cn/problem.php?id=1203 [题意]给你一颗完全二叉树每个节点都有一个权值,然后要你从上往下找一条链,值得链上权值的和<K,且 ...