Centos 7源码编译安装 php7.2 之生产篇 | 任我乐


本站和网页 https://renwole.com/archives/29 的作者无关,不对其内容负责。快照谨为网络故障时之索引,不代表被搜索网站的即时页面。

Centos 7源码编译安装 php7.2 之生产篇 | 任我乐
任我乐
Linux OS Mirror Repository
菜单
跳至正文
OS镜像
镜像
谷歌翻译
关于
留言
ILNMP
Centos 7源码编译安装 php7.2 之生产篇
41条回复
介绍:
久闻php7的速度以及性能那可是比php5系列的任何一版本都要快,具体性能有多好,建议还是先尝试下再说。如果你是升级或新安装,那你首先需要考虑php7和程序是否存在兼容性,如果程序是基于php5开发的,那么就需要考虑php7是否适合你当前的生产环境,今天我就实操并安装用于生产中。
先安装php依赖包,否则在编译安装php7的过程当中会出现各种报错,安装完成后即可进入下一个环节。
安装扩展包并更新系统内核:
$ yum install epel-release -y
$ yum update
安装php依赖组件(包含Nginx依赖):
$ yum -y install wget vim pcre pcre-devel openssl openssl-devel libicu-devel gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel ncurses ncurses-devel curl curl-devel krb5-devel libidn libidn-devel openldap openldap-devel nss_ldap jemalloc-devel cmake boost-devel bison automake libevent libevent-devel gd gd-devel libtool* libmcrypt libmcrypt-devel mcrypt mhash libxslt libxslt-devel readline readline-devel gmp gmp-devel libcurl libcurl-devel openjpeg-devel
创建用户和组,并下载php安装包解压:
$ cd /tmp
$ groupadd www
$ useradd -g www www
$ wget //am1.php.net/distributions/php-7.2.1.tar.gz
$ tar xvf php-7.2.1.tar.gz
$ cd php-7.2.1
设置变量并开始源码编译:
$ cp -frp /usr/lib64/libldap* /usr/lib/
$ ./configure --prefix=/usr/local/php \
--with-config-file-path=/usr/local/php/etc \
--enable-fpm \
--with-fpm-user=www \
--with-fpm-group=www \
--enable-mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--enable-mysqlnd-compression-support \
--with-iconv-dir \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--with-libxml-dir \
--enable-xml \
--disable-rpath \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-inline-optimization \
--with-curl \
--enable-mbregex \
--enable-mbstring \
--enable-intl \
--with-mcrypt \
--with-libmbfl \
--enable-ftp \
--with-gd \
--enable-gd-jis-conv \
--enable-gd-native-ttf \
--with-openssl \
--with-mhash \
--enable-pcntl \
--enable-sockets \
--with-xmlrpc \
--enable-zip \
--enable-soap \
--with-gettext \
--disable-fileinfo \
--enable-opcache \
--with-pear \
--enable-maintainer-zts \
--with-ldap=shared \
--without-gdbm \
--enable-fileinfo \
若无报错执行下一步安装,如果编译过程中出现错误,根据报错安装依赖包,通常不会出现这种问题。
注意:–enable-gd-jis-conv  此参数会导致Zabbix中文字符乱码,建议取消。
开始安装:
$ make -j 4 && make install
完成安装后配置php.ini文件:
$ cp php.ini-development /usr/local/php/etc/php.ini
$ cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
$ cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
修改 php.ini 相关参数:
$ vim /usr/local/php/etc/php.ini
expose_php = Off
short_open_tag = ON
max_execution_time = 300
max_input_time = 300
memory_limit = 128M
post_max_size = 32M
date.timezone = Asia/Shanghai
mbstring.func_overload=2
extension = "/usr/local/php/lib/php/extensions/no-debug-zts-20160303/ldap.so"
设置 OPcache 缓存:
[opcache]
zend_extension=/usr/local/php/lib/php/extensions/no-debug-zts-20160303/opcache.so
opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=4000
opcache.revalidate_freq=60
opcache.fast_shutdown=1
opcache.enable_cli=1
设置php安全函数:
$ vim /usr/local/php/etc/php.ini
默认值:
disable_functions =
修改为:
disable_functions = passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,escapeshellcmd,dll,popen,disk_free_space,checkdnsrr,checkdnsrr,getservbyname,getservbyport,disk_total_space,posix_ctermid,posix_get_last_error,posix_getcwd, posix_getegid,posix_geteuid,posix_getgid, posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid, posix_getppid,posix_getpwnam,posix_getpwuid, posix_getrlimit, posix_getsid,posix_getuid,posix_isatty, posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid, posix_setpgid,posix_setsid,posix_setuid,posix_strerror,posix_times,posix_ttyname,posix_uname
或通配:
disable_functions = passthru,exec,system,chroot,chgrp,chown,shell_exec,proc_open,proc_get_status,popen,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru
配置www.conf
取消以下注释并修改优化其参数:
listen = /var/run/www/php-cgi.sock
listen.owner = www
listen.group = www
listen.mode = 0660
listen.allowed_clients = 127.0.0.1
pm = dynamic
listen.backlog = -1
pm.max_children = 180
pm.start_servers = 50
pm.min_spare_servers = 50
pm.max_spare_servers = 180
request_terminate_timeout = 120
request_slowlog_timeout = 50
slowlog = var/log/slow.log
创建php-cgi.sock存放目录
$ mkdir /var/run/www/
$ chown -R www:www /var/run/www
配置php-fpm.conf
取下以下注释并填写完整路径:
pid = /usr/local/php/var/run/php-fpm.pid
至此php7已经安装完成。
说明:禁用php函数,如果程序需要这些函数,可以取消禁止,新手建议忽略此步骤。
创建system系统单元文件php-fpm启动脚本:
$ vim /usr/lib/systemd/system/php-fpm.service
添加如下变量内容:
[Unit]
Description=The PHP FastCGI Process Manager
After=syslog.target network.target
[Service]
Type=simple
PIDFile=/usr/local/php/var/run/php-fpm.pid
ExecStart=/usr/local/php/sbin/php-fpm --nodaemonize --fpm-config /usr/local/php/etc/php-fpm.conf
ExecReload=/bin/kill -USR2 $MAINPID
[Install]
WantedBy=multi-user.target
启动php-fpm服务并加入开机自启动:
$ systemctl enable php-fpm.service
$ systemctl restart php-fpm.service
PHP整个安装过程已经完成。如果你是按照本文安装未成功的,希望你能留言说明错误原因,我将无偿协助你配置。
如果你有好的建议完善该文章,非常欢迎你提出和改进,我们一起共同学习和进步。
本条目发布于2017年4月30日。属于PHP分类,被贴了 Centos、Centos7安装php7、linux安装php7、Nginx依赖、openssl、php、php5、php7.1、php7.1安装、php7依赖包、php7高性能 标签。作者是Node。
文章导航
← Centos 7 二进制安装配置 MariaDB(MySQL)数据库
Centos 7 源码编译安装 Nginx 1.13 →
《Centos 7源码编译安装 php7.2 之生产篇》有41个想法
隔海 2021年5月14日 下午3:35
我照着步骤走,发现确实www.conf文件,这个什么原因呢
回复 ↓
Node 文章作者2021年5月15日 下午3:53
是否在 cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf 这一步骤有没有缺少配置的地方,若没有,你看下是php的版本上有没有区别,活在可以在当前目录find下是否存在该文件,例如:find /usr/local/php -name www"*" 看看是否能够查询到
回复 ↓
lcf 2018年8月10日 下午10:14
这篇文档就是个坑,各种错误
回复 ↓
曾曾 2018年5月16日 下午2:31
博主我用netstat查看并没有看到php和9000端口起来,是错了吗
[root@localhost php-7.2.1]# netstat -tulnp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 21682/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1437/master
tcp6 0 0 :::22 :::* LISTEN 21682/sshd
tcp6 0 0 ::1:25 :::* LISTEN 1437/master
回复 ↓
曾曾 2018年5月16日 下午2:33
全都安你的博客来做的
回复 ↓
曾曾 2018年5月16日 下午3:15
是因为配置www.conf
将listen = 127.0.0.1:9000修改了所以用netstat看不到 php的程序和端口吗?
listen = /var/run/www/php-cgi.sock
回复 ↓
tycell 2018年4月25日 上午10:27
你好: 有个疑问就是,源码编译安装后的 php.ini ,打开一看 类似于这些 extension=php_mysqli.dll 之类的语句 是为window准备的?linux上只能通过phpinfo或者命令去查看哪些扩展的安装?
回复 ↓
Node Cloud 文章作者2018年5月4日 下午8:27
extension=php_mysqli.dll等可以忽略的,linux下用不到,你编译安装的时候那些参数就是你的扩展
回复 ↓
PeopleSea 2018年4月3日 下午8:36
请问和nginx用不了怎么整…
nginx.conf
server {
listen 80;
server_name localhost;
root /localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
index index.php index.html index.htm;
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
error_page 500 502 503 504 /50x.html;
location = /50x.html {
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ \.php$ {
fastcgi_pass unix:/var/run/www/php-cgi.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
# deny access to .htaccess files, if Apache’s document root
# concurs with nginx’s one
#location ~ /\.ht {
# deny all;
#}
回复 ↓
Node Cloud 文章作者2018年4月5日 下午6:09
有报错日志吗
回复 ↓
小蜗牛 2018年3月23日 下午5:48
你好 博主 我用你的教程安装了PHP-7.2.3之后服务起来了 但是不能用php -v这个命令啊
回复 ↓
Node Cloud 文章作者2018年3月29日 上午12:54
有日志吗
回复 ↓
oldna 2018年3月30日 下午12:04
PHP 命令没添加到环境变量
可以用下面命令测试
/usr/local/php/bin/php -v
回复 ↓
xphp 2018年3月17日 下午7:56
设置变量并开始源码编译:
$ cp -frp /usr/lib64/libldap* /usr/lib/
确定不是
$ cp -frp /usr/lib64/libldap* /usr/lib64/
另外这一句的命令是必须的吗?
能解释下这一句命令的作用吗,在别处看见的编译安装php7没有这一句命令。
回复 ↓
xxxphp 2018年3月17日 下午7:53
设置变量并开始源码编译:
$ cp -frp /usr/lib64/libldap* /usr/lib/
确定不是
$ cp -frp /usr/lib64/libldap* /usr/lib64/
另外这一句命令是必须的吗?
在别处看见的编译安装php7没有这一句。
能解释下这一句命令的作用吗。
回复 ↓
xxxphp 2018年3月17日 下午2:20
设置变量并开始源码编译:
$ cp -frp /usr/lib64/libldap* /usr/lib/
确定不是
$ cp -frp /usr/lib64/libldap* /usr/lib64/
回复 ↓
xxxphp 2018年3月17日 下午2:24
另外这一句命令是必须的吗?
为什么别处的编译安装php7没有这一句命令
回复 ↓
xxxphp 2018年3月17日 下午2:26
另外这一句命令是必须的吗?
在别处看到的编译安装php7没有这一句。
回复 ↓
xxphp 2018年3月17日 下午8:00
这一句命令有什么作用呢?
回复 ↓
Node Cloud 文章作者2018年3月29日 上午12:54
64位可以用后者
回复 ↓
frans 2018年3月13日 下午3:48
编译时有两个模块可以删除了。
–with-mcrypt \
–enable-gd-native-ttf \
回复 ↓
frans 2018年3月13日 下午3:49
我这边的版本是 7.2.3
回复 ↓
Node Cloud 文章作者2018年3月29日 上午12:55
OK,我会编辑下,谢谢您的建议。
回复 ↓
PHPSIX 2018年3月8日 上午10:31
你好,博主,我根据你的教程安装了好多遍,但是终究没有成功。能麻烦留一下您的联系方式吗? 想请教你一下。我博客上有我的联系方式,麻烦了。
回复 ↓
Node Cloud 文章作者2018年3月9日 上午12:08
您好,有什么具体的报错吗
回复 ↓
PHPSIX 2018年3月9日 上午9:21
报404,查了好多遍没找到什么原因
回复 ↓
Node Cloud 文章作者2018年3月9日 下午7:49
网站根目录指定的不对吧
回复 ↓
PHPSIX 2018年3月11日 上午9:35
对的,具体的nginx配置代码我已经粘上来了,麻烦看一下。
回复 ↓
PHPSIX 2018年3月9日 下午1:46
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
location ~ \.php$ {
try_files $uri =404;
#root html;
fastcgi_pass unix:/var/run/www/php-cgi.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
# deny access to .htaccess files, if Apache’s document root
# concurs with nginx’s one
#location ~ /\.ht {
# deny all;
#}
回复 ↓
ysl 2018年3月8日 上午10:20
; Default Value: 511 (-1 on FreeBSD and OpenBSD)
listen.backlog = -1
centos的系统要注意
回复 ↓
xxxphp 2018年3月17日 下午8:03
centos的系统要注意
这个是什么意思?
回复 ↓
木木 2018年3月5日 上午10:15
您好,我想问问关于编译参数–enable-maintainer-zts的问题。这个参数意味着启用线程安全,那么使用CGI/FastCGI模式时需要启用该选项吗?区分在Nginx、Apache、IIS上的配置差异。
PHP手册中的话:
What does thread safety mean when downloading PHP?
Thread Safety means that binary can work in a multithreaded webserver context, such as Apache 2 on Windows. Thread Safety works by creating a local storage copy in each thread, so that the data won’t collide with another thread.
So what do I choose? If you choose to run PHP as a CGI binary, then you won’t need thread safety, because the binary is invoked at each request. For multithreaded webservers, such as IIS5 and IIS6, you should use the threaded version of PHP.
也就是说在Nginx上使用时,由于使用的是FastCGI,所以不启用该选项对吧?
回复 ↓
Node Cloud 文章作者2018年3月9日 上午12:08
不建议使用
回复 ↓
lazysheep 2018年1月5日 下午11:25
你好,我安装nginx后发现无法解析php 我该如何调试解决?
回复 ↓
lazysheep 2018年1月6日 上午12:12
现在502了
回复 ↓
Node Cloud 文章作者2018年1月7日 下午10:43
请把Nginx解析php配置段发出来看看
回复 ↓
符号 2017年12月26日 上午10:22
哇哇哇,正是我需要的啊
回复 ↓
小秘 2017年5月21日 下午10:24
centos6可以安装吗
回复 ↓
Node Cloud 文章作者2017年5月21日 下午10:26
如果你需要在centos6下进行安装,那么启动脚本需要重写,启动方式也有所不同,例如centos6系列下没有systemctl管理工具,需要使用service
回复 ↓
厉害了 2017年5月21日 下午10:23
不错
回复 ↓
柚子 2017年5月8日 下午8:54
堪称经典,收藏了
回复 ↓
发表回复 取消回复您的电子邮箱地址不会被公开。 必填项已用*标注评论 * 显示名称 *
电子邮箱地址 *
网站地址
看不清?点击图片刷新!
验证码 *
搜索
AlmaLinux
Alpine Linux
AnolisOS
Apache
Arch Linux
CentOS
Debian
Deepin
ElasticStack
EndeavourOS
Fedora
FreeBSD
Git
Kali Linux
Keepalived
Linux
Linux Mint
MariaDB
MongoDB
MX Linux
MySQL
Nginx
OpenBSD
openEuler
openKylin
OpenSSL
openSUSE
Oracle Linux
OS
PHP
PostgreSQL
Redis
Rocky Linux
Shell
SQL server
Storage
Tomcat
Ubuntu
Ubuntu Kylin
Windows
Zabbix
粤ICP备16117021号-3
自豪地采用WordPress