您的位置:首页 > 编程语言 > PHP开发

php-7.2.10编译安装过程

2018-10-07 13:40 591 查看

php-7.2.10编译安装过程

1、安装前准备

1.1、准备安装的服务器或虚拟机

[root@localhost ~]# cat /etc/redhat-release

CentOS Linux release 7.2.1511 (Core)

 

[root@localhost ~]# ifconfig

eno16777736: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500

        inet 192.168.10.10  netmask 255.255.255.0  broadcast 192.168.10.255

        inet6 fe80::20c:29ff:fe48:bb2f  prefixlen 64  scopeid 0x20<link>

        ether 00:0c:29:48:bb:2f  txqueuelen 1000  (Ethernet)

        RX packets 95999  bytes 124353019 (118.5 MiB)

        RX errors 0  dropped 0  overruns 0  frame 0

        TX packets 39612  bytes 4818173 (4.5 MiB)

        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

1.2、关闭防火墙和selinux

[root@localhost ~]# getenforce

Disabled

[root@localhost ~]# iptables -L

Chain INPUT (policy ACCEPT)

target     prot opt source               destination        

 

Chain FORWARD (policy ACCEPT)

target     prot opt source               destination        

 

Chain OUTPUT (policy ACCEPT)

target     prot opt source               destination   

1.3、配置好网络yum源和epel源

注意:这里一定要配置好网络yum源和epel源,这对于后面安装依赖会减少麻烦,如果配置的是内网源,一定要确保内网中有相关的php依赖包,针对没有的依赖包,可以到相关网站下载好依赖包上传到服务器。否则,安装过程肯定不顺利。

[root@localhost ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

 

[root@localhost ~]# curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

2、安装PHP环境

2.1、安装PHP需要的相关依赖包

注意:这里涉及到的软件包最好都安装上,如果缺少相关依赖,后面安装php会报错,会给安装增加不少麻烦,之前都是一步步踩坑过来的。

[root@localhost ~]# yum -y install gcc gcc-c++ libmcrypt-devel mcrypt mhash gd-devel ncurses-devel libxml2-devel bzip2-devel libcurl-devel curl-devel libjpeg-devel libpng-devel freetype-devel net-snmp-devel openssl-deve python-devel zlib-devel freetype libxslt* bison autoconf re2c

2.2、编译安装PHP软件

[root@localhost ~]# wget http://cn2.php.net/distributions/php-7.2.10.tar.gz

[root@localhost ~]# tar -xf php-7.2.10.tar.gz

[root@localhost php-7.2.10]# ./configure \

--prefix=/usr/local/php \

--exec-prefix=/usr/local/php \

--bindir=/usr/local/php/bin \

--sbindir=/usr/local/php/sbin \

--includedir=/usr/local/php/include \

--libdir=/usr/local/php/lib/php \

--mandir=/usr/local/php/php/man \

--with-config-file-path=/usr/local/php/etc \

--with-mysql-sock=/var/run/mysql/mysql.sock \

--with-mhash \

--with-openssl \

--with-mysqli=shared,mysqlnd \

--with-pdo-mysql=shared,mysqlnd \

--with-gd \

--with-iconv \

--with-zlib \

--enable-zip \

--enable-inline-optimization \

--disable-debug \

--disable-rpath \

--enable-shared \

--enable-xml \

--enable-bcmath \

--enable-shmop \

--enable-sysvsem \

--enable-mbregex \

--enable-mbstring \

--enable-ftp \

--enable-pcntl \

--enable-calendar \

--enable-exif \

--enable-sockets \

--with-xmlrpc \

--with-libxml-dir \

--enable-soap \

--without-pear \

--with-gettext \

--enable-session \

--with-curl \

--with-jpeg-dir \

--with-png-dir \

--with-freetype-dir \

--with-bz2 \

--enable-opcache \

--enable-fpm \

--with-fpm-user=nginx \

--with-fpm-group=nginx \

--without-gdbm \

--enable-fast-install \

--disable-fileinfo

 

[root@localhost php-7.2.10]# make && make install

[root@localhost php-7.2.10]# cd ..

[root@localhost ~]# /usr/local/php/bin/php -v   #到这里就说明php已经安装成功    

PHP 7.2.10 (cli) (built: Oct  3 2018 18:03:11) ( NTS )

Copyright (c) 1997-2018 The PHP Group

Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies

2.3、编译PHP的选项说明

configure选项

选项作用

--prefix=/usr/local/php

php安装的根目录

--exec-prefix=/usr/local/php

php执行文件所在目录

--bindir=/usr/local/php/bin

php的bin目录所在位置

--sbindir=/usr/local/php/sbin

php的sbin目录所在位置

--includedir=/usr/local/php/include

php包含文件所在目录

--libdir=/usr/local/php/lib/php

php的lib目录所在位置

--mandir=/usr/local/php/php/man

php的man目录所在位置

--with-config-file-path=/usr/local/php/etc

php的配置文件目录所在位置

--with-mysql-sock=/var/run/mysql/mysql.sock

php的Unix socket通信文件

--with-mcrypt

php里面重要的加密支持扩展库,linux环境下该库在默认情况下不开启

--with-mhash

Mhash是基于离散数学原理的不可逆向的php加密方式扩展库,其在默认情况下不开启

--with-openssl

OpenSSL 是一个安全套接字层密码库

--with-mysqli=shared,mysqlnd

php依赖mysql库

--with-pdo-mysql=shared,mysqlnd

php依赖mysql库

--with-gd

gd库

--with-iconv

关闭iconv函数,字符集间的转换

--with-zlib

zlib是提供数据压缩用的函式库

--enable-zip

打开对zip的支持

--enable-inline-optimization

优化线程

--disable-debug

关闭调试模式

--disable-rpath

关闭额外的运行库文件

--enable-shared

启用动态库

--enable-xml

开启xml扩展

--enable-bcmath

打开图片大小调整,用到zabbix监控的时候用到了这个模块

--enable-shmop

共享内存

--enable-sysvsem

内存共享方案

--enable-mbregex

开启多字节正则表达式的字符编码

--enable-mbstring

开启多字节字符串函数

--enable-ftp

打开ftp的支持

--enable-pcntl

PHP的进程控制支持实现了Unix方式的多进程创建

--enable-calendar

打开日历扩展功能

--enable-sockets

开启套接字

--enable-exif

开启图片的元数据支持

--with-xmlrpc

打开xml-rpc的c语言

--enable-soap

开启简单对象访问协议简单对象访问协议

--without-pear

开启php扩展与应用库

--with-gettext

开户php在当前域中查找消息

--enable-session

允许php会话session

--with-curl

允许curl扩展

--with-jpeg-dir

指定jpeg安装目录yum安装过后不用再次指定会自动找到

--with-png-dir

打开对png图片的支持

--with-freetype-dir

指定freetype安装目录yum安装过后不用再次指定会自动找到

--with-bz2

打开对bz2文件的支持

--with-libxml-dir

打开libxml2库的支持

--enable-opcache

开启使用opcache缓存

--enable-fpm

开启fpm

--with-fpm-user=nginx

php-fpm的用户

--with-fpm-group=nginx

php-fpm的用户组

--without-gdbm

数据库函数使用可扩展散列和类似于标准UNIX dbm的工作

--enable-fast-install

为快速安装优化

--disable-fileinfo

禁用fileinfo支持

3、PHP安装后的配置

3.1、配置php.ini文件

[root@localhost ~]# useradd nginx

[root@localhost ~]# cd php-7.2.10

[root@localhost php-7.2.10]# cp -a php.ini-production /usr/local/php/etc/php.ini

[root@localhost php-7.2.10]# ln -s /usr/local/php7/etc/php.ini /etc/php.ini

[root@localhost ~]# vim /usr/local/php/etc/php.ini

#找到下面的参数并修改成下面的样子

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

#列出PHP可以禁用的函数,如果某些程序需要用到这个函数,可以删除取消禁用

 

date.timezone = Asia/shanghai    #指定时区为上海

expose_php = Off      #禁止显示PHP版本

short_open_tag = ON   #支持PHP短标签

opcache.enable=1      #PHP支持opcode缓存

opcache.enable_cli=0

extension=mysqli.so

extension=pdo_mysql.so

zend_extension=opcache.so     #在最后一行添加,开启opcode缓存功能

:wq   #保存退出

3.2、配置php-fpm和www.conf

[root@localhost ~]# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf

[root@localhost ~]# cp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf

 

[root@localhost ~]# cd php-7.2.10

[root@localhost php-7.2.10]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm

[root@localhost ~]# chmod +x /etc/rc.d/init.d/php-fpm

[root@localhost ~]# chkconfig --add php-fpm

[root@localhost ~]# chkconfig php-fpm on

3.3、设置环境变量让php相关命令可直接使用

[root@localhost ~]# echo 'export PATH=$PATH:/usr/local/php/bin/:/usr/local/php/sbin/' >>/etc/profile

[root@localhost ~]# source /etc/profile

4、启动php-fpm

[root@localhost ~]# systemctl start php-fpm

[root@localhost ~]# ss -ant|grep 9000

LISTEN     0      128    127.0.0.1:9000                     *:*      

5、测试php能否解析php文件

5.1、安装nginx并创建一个php测试文件

[root@localhost ~]# yum -y install nginx

[root@localhost ~]# vim /etc/nginx/nginx.conf

#把下面一段插入到server标签内

location ~ \.php$ {

            root           html;

            fastcgi_pass   127.0.0.1:9000;

            fastcgi_index  index.php;

            fastcgi_param  SCRIPT_FILENAME   $document_root$fastcgi_script_name;

            include        fastcgi_params;

        }

 

[root@localhost ~]# vim /usr/share/nginx/html/index.php  #添加一个测试的php网页文件

<?php

phpinfo();

?>

[root@localhost ~]# systemctl start nginx

5.2、使用浏览器测试php页面

访问我们配置的服务器IP地址192.168.10.10,就出现了下面的nginx欢迎界面。

接着浏览器访问192.168.10.10/index.php,出现下面的页面说明我们的PHP没有问题

到此PHP环境已经安装并配置完成,生产环境使用时,需要根据实际需求进行配置。


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息