web开发环境搭建第三篇CentOS7.6编译安装php7.3.8
下载地址
删除centos自带的php
[root@localhost src]# rpm -qa|grep php
php-process-5.4.16-42.el7.x86_64
php-pear-1.9.4-21.el7.noarch
php-common-5.4.16-42.el7.x86_64
php-xml-5.4.16-42.el7.x86_64
php-devel-5.4.16-42.el7.x86_64
php-cli-5.4.16-42.el7.x86_64
[root@localhost src]# rpm -e php-devel-5.4.16-42.el7.x86_64
如果有的话,请一个一个的删除完
安装一些必要的工具和库
yum -y install libxslt-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel gcc-c++ autoconf libXpm-devel
安装libmcrypt
[root@localhost src]# wget http://nchc.dl.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz
[root@localhost src]# tar -zxf libmcrypt-2.5.8.tar.gz
[root@localhost src]# cd libmcrypt-2.5.8
[root@localhost libmcrypt-2.5.8]#./configure
[root@localhost libmcrypt-2.5.8]# make && make install
安装libzip
yum remove libzip
wget https://libzip.org/download/libzip-1.2.0.tar.gz
tar -zxvf libzip-1.2.0.tar.gz
cd libzip-1.2.0
./configure
make && make install
编译安装PHP
编译有点慢
[root@localhost src]# wget http://cn2.php.net/distributions/php-7.3.8.tar.gz
[root@localhost src]# tar -zxf php-7.3.8.tar.gz
[root@localhost src]# cd php-7.3.8
[root@localhost php-7.3.8]# ./buildconf --force
[root@localhost php-7.3.8]# ./configure \
--prefix=/usr/local/php \
--exec-prefix=/usr/local/php \
--with-pdo-mysql=mysqlnd \
--with-mysql-sock=/tmp/mysql.sock \
--with-gd \
--with-png-dir \
--with-jpeg-dir \
--with-freetype-dir \
--with-xpm-dir=/usr/lib \
--with-zlib \
--with-iconv \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-fpm \
--with-fpm-user=nginx \
--with-fpm-group=nginx \
--enable-mbstring \
--enable-ftp \
--with-openssl \
--enable-opcache \
--enable-pcntl \
--enable-sockets \
--enable-sysvmsg \
--enable-sysvsem \
--enable-sysvshm \
--with-xmlrpc \
--enable-zip \
--enable-soap \
--without-pear \
--with-curl \
--with-mhash
[root@localhost php-7.3.8]# make
[root@localhost php-7.3.8]# make install
问题
usr/local/include/zip.h:59:21: fatal error: zipconf.h: No such file or dire
#解决方法:手动复制过去
cp /usr/local/lib/libzip/include/zipconf.h /usr/local/include/zipconf.h
配置php.ini
一、查看php.ini配置文件的路径
[root@localhost php-7.3.8]# /usr/local/php/bin/php --ini
Configuration File (php.ini) Path: /usr/local/php/lib
显示在lib下面,所有我们应该拷贝源码包里面配置文件到/usr/local/php/lib下面
[root@localhost php-7.3.8]# cp php.ini-production /usr/local/php/lib/php.ini
二、配置php.ini
A.关闭在http头中显示php版本信息
expose_php = Off
B.错误的处理
error_reporting = E_ALL & ~E_NOTICE
display_errors = Off
log_errors = On
error_log = /data/log/php/php_errors.log
注意:一定要保证php_errors.log有可写权限,有两种方式:
下面我们会配置php-fpm运行的用户和用户组为nginx,所以,我们这里可以将php_errors.log的所有者和所属组改成nginx
mkdir -p /data/log/php
touch /data/log/php/php_errors.log
chown nginx:nginx /data/log/php/php_errors.log
C. 设置时区
date.timezone = PRC
linux的配置是不用去开启curl、mysql之类的扩展的,configure配置编译的时候已经默认开启了
配置php-fpm
一、创建日志目录
mkdir -p /data/log/php-fpm
二、php-fpm.conf
[root@localhost php-7.3.8]# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
① 去掉;pid = run/php-fpm.pid 前面的分号,使之生效
② 设置错误日志路径
error_log = /data/log/php-fpm/php-fpm.log
三、www.conf
[root@localhost php-7.3.8]# cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
;设置用户和用户组
user = nginx
group = nginx
;设置监听
;listen = 127.0.0.1:9000
listen = /dev/shm/php-fpm.sock
listen.owner = nginx
listen.group = nginx
listen.mode = 0660
;进程相关,这个得根据硬件情况来设置
pm.max_children = 100
pm.start_servers = 50
pm.min_spare_servers = 40
pm.max_spare_servers = 60
;开启慢日志
slowlog = /data/log/php-fpm/$pool-slow.log
request_slowlog_timeout = 10s
;开启抓去php的错误输出
catch_workers_output = yes
原因是php-fpm的配置文件php-fpm.conf中默认是关闭worker进程的错误输出,直接把他们重定向到/dev/null,所以我们在nginx的error log 和php-fpm的errorlog都看不到php的错误日志,直接开启catch_workers_output = yes 即可
检测php-fpm配置文件
[root@localhost php-7.3.8]# /usr/local/php/sbin/php-fpm -t
[30-Mar-2017 12:20:36] NOTICE: configuration file /usr/local/php/etc/php-fpm.conf test is successful
设置php-fpm开机自启动
[root@localhost php-7.3.8]# cp ./sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@localhost php-7.3.8]# chmod 0744 /etc/init.d/php-fpm
[root@localhost php-7.3.8]# chkconfig --add php-fpm
[root@localhost php-7.3.8]# chkconfig --level 35 php-fpm on
chkconfig --list 来查看是否将php-fpm添加到了自启动
启动php-fpm
方式一:
[root@localhost php-7.3.8]# /usr/local/php/sbin/php-fpm
方式二:
当然,第3步我们已经把php-fpm加入了开机自启动,也就是加入了服务,所有,我就可以用这样的命令来控制php-fpm了:
[root@localhost php-7.3.8]# service php-fpm start|restart|stop|reload|status|force-quit
方式三:
[root@localhost php-7.3.8]# /etc/init.d/php-fpm start|restart|stop|reload|status|force-quit
配置nginx支持php脚本
Nginx + PHP-FPM设置虚拟主机 + 开启PATHINFO模式
/usr/local/nginx/conf/nginx.conf
user nginx nginx;
worker_processes 2;
error_log logs/error.log;
error_log logs/error.log notice;
error_log logs/error.log info;
pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
gzip on;
client_max_body_size 5m;
#设置404
fastcgi_intercept_errors on;
include vhost/*.conf;
}
/usr/local/nginx/conf/vhost/www.example.com.conf
server {
listen 80;
server_name www.example.com example.com;
charset utf-8;
access_log /data/log/nginx/example.access.log;
root /data/example/www;
if ($host != 'www.example.com') {
rewrite ^/(.*)$ http://www.example.com/$1 permanent;
}
location /favicon.ico {
log_not_found off;
access_log off;
}
location / {
index index.php index.html index.htm;
if (!-e $request_filename) {
rewrite ^/(.*)$ /index.php/$1 last;
}
}
location ~ \.php(/|$) {
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
fastcgi_pass unix:/dev/shm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}
/usr/local/php/etc/php-fpm.conf
pid = run/php-fpm.pid
user = nginx
group = nginx
;listen = 127.0.0.1:9000
listen = /dev/shm/php-fpm.sock
listen.owner = nginx
listen.group = nginx
listen.mode = 0660
/usr/local/php/etc/php-fpm.d/www.conf
现在nginx多了一个php-fpm.d/www.conf,把之前在php-fpm.conf里面的一些配置分到了php-fpm.d下面的多个conf里面
user = nginx
group = nginx
;listen = 127.0.0.1:9000
listen = /dev/shm/php-fpm.sock
listen.owner = nginx
listen.group = nginx
listen.mode = 0660
网友评论