CentOS7.4安装PHP7.3.8 - Go语言中文社区

CentOS7.4安装PHP7.3.8


1、下载 
官方地址: www.php.net

我们下载7.3.8版本的

# cd /mydata/
# wget https://www.php.net/distributions/php-7.3.8.tar.gz

最后出现:‘php-7.3.8.tar.gz’ saved [19559584]  下载完整

2、安装依赖

# yum -y install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel

3、编辑配置项生成安装文件 Makefile

# tar -zxvf php-7.3.8.tar.gz
# cd php-7.3.8/
# 编辑PHP的配置项
# ./configure --prefix=/usr/local/php --with-config-file-path=/etc --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --enable-inline-optimization --disable-debug --disable-rpath --enable-shared --enable-soap --with-libxml-dir --with-xmlrpc --with-openssl --with-mhash --with-pcre-regex --with-sqlite3 --with-zlib --enable-bcmath --with-iconv --with-bz2 --enable-calendar --with-curl --with-cdb --enable-dom --enable-exif --enable-fileinfo --enable-filter --with-pcre-dir --enable-ftp --with-gd --with-openssl-dir --with-jpeg-dir --with-png-dir --with-zlib-dir --with-freetype-dir  --enable-gd-jis-conv --with-gettext --with-gmp --with-mhash --enable-json --enable-mbstring --enable-mbregex --enable-mbregex-backtrack --with-onig --enable-pdo --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-zlib-dir --with-pdo-sqlite --with-readline --enable-session --enable-shmop --enable-simplexml --enable-sockets --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-wddx --with-libxml-dir --with-xsl --enable-zip --enable-mysqlnd-compression-support --with-pear --enable-opcache --disable-fileinfo

注意:里面的配置项 --with-libmbfl  从php7.3开不再支持,你可以去掉 (这里我们直接去掉即可)

几个重点配置项:

./configure
--prefix=/usr/local/php      //定义PHP安装目录
-with-config-file-path=/etc   //指定php.ini文件的放置路径 
--enable-fpm     //开启php-fpm    必须,
--with-fpm-user=nginx    //PHP的用户为nginx
--with-fpm-group=nginx    PHP的用户组为nginx
--disable-fileinfo        //当服务器内存为1G时,此项很有必要

注意PHP的用户为nginx、用户组为nginx 。和上面安装的nginx的用户、用户组一定要相同。
如果出现如下报错:configure: WARNING: unrecognized options: --with-mcrypt, --enable-gd-native-ttf
说明此版本不再支持 --with-mcrypt, --enable-gd-native-ttf 这两个选项, 直接删除,重新编辑即可。

报错处理:

错误一:libzip


错误原因:libzip 版本过低 libzip 版本过低,因为使用 yum 最新版只到 0.10,不足以达到要求,需要更新版本,我们手工下载并默认安装即可

# cd /mydata/
# yum remove -y libzip  先卸载旧版本(如果已经安装)
# wget  https://nih.at/libzip/libzip-1.2.0.tar.gz
# tar -zxvf libzip-1.2.0.tar.gz
# cd ./libzip-1.2.0
# ./configure   回车执行即可,什么都不用配置,使用默认即可
# make && make install
# 安装成功即可

安装成功后继续 回到./php-7.3.8/目录 执行 ./configure编译命令

 错误二:off_t未定义

如果出现未定义的类型 off_t 错误的话,off_t 类型是在头文件 unistd.h 中定义的,在 32 位系统编译成 long int,64 位系统则编译成 long long int,在进行编译的时候默认查找 64 位的动态链接库,但是默认情况下 CentOS 的动态链接库配置文件 /etc/ld.so.conf 没有加入搜索路径,所以需要将 /usr/local/lib64 和 /usr/lib64 这些针对 64 位的库文件路径加进去:

# echo '/usr/local/lib64 
/usr/local/lib
/usr/lib
/usr/lib64'>>/etc/ld.so.conf

然后跟新缓存
# ldconfig -v

继续执行 ./configure编译命令
(不同的环境报错可能不一样:也可能报缺少 BZip2 的错误,需要安装 bzip2 和 bzip2-devel 。使用 # yum install -y bzip2 bzip2-devel安装即可)
最后出现

OK 编译完成

4、make && make install 
(注意下面的报错(2),为节约时间建议先进行错误(2)的文件复制,再进行# make命令的执行)

(1)如果出现 make: *** [ext/fileinfo/libmagic/apprentice.lo] Error 1
是因为服务器内存不足1G。只需要在上面的配置命令中添加 --disable-fileinfo即可(上面已经添加)。
再次执行
# ./configure .....  --disable-fileinfo

(2)zip安装错误
如果出现如下图错误

只需要复制此zipconf.h文件即可

# cp /usr/local/lib/libzip/include/zipconf.h /usr/local/include/zipconf.h

然后继续 # make
直到出现:

。。。
Generating phar.php
Generating phar.phar
PEAR package PHP_Archive not installed: generated phar will require PHP's phar extension be enabled.
directorygraphiterator.inc
clicommand.inc
directorytreeiterator.inc
pharcommand.inc
invertedregexiterator.inc
phar.inc

Build complete.
Don't forget to run 'make test'.

继续# make install 
最后出现:

安装成功!
 

5、添加环境变量到PHP中

# vim /etc/profile

在此文件的最后添加如下两行
PATH=$PATH:/usr/local/php/bin
export PATH

# source /etc/profile  使配置立即生效

再次检查:# php  -v  出现php版本号信息
# echo  $PATH

/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/usr/local/nginx/sbin:/usr/local/mysql/bin:/usr/local/php/bin:/root/bin

OK  已经配置成功

6、配置PHP-fpm 并设置开启重启
进入php的安装包(注意是解压出来的那个安装包,而不是安装目录)
# cd /mydata/php-7.2.17/
# ls -al
可以找到两个 php.ini-development(测试配置文件) php.ini-production生产环境配置文件
复制以下四个文件。

# cp php.ini-production /etc/php.ini      //设置PHP启动文件
# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm  //把php-fpm放入系统管理配置项中
# chmod +x /etc/init.d/php-fpm    //为其添加可执行权限

# 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

添加到环境系统启动项
# chkconfig --add php-fpm             //添加到开机重启
# chkconfig php-fpm on

查看是否添加成功
# chkconfig --list 
......
mysqld          0:off   1:off   2:on    3:on    4:on    5:on    6:off
netconsole      0:off   1:off   2:off   3:off   4:off   5:off   6:off
network         0:off   1:off   2:on    3:on    4:on    5:on    6:off
nginx           0:off   1:off   2:on    3:on    4:on    5:on    6:off
php-fpm         0:off   1:off   2:on    3:on    4:on    5:on    6:off  --- php-fpm 添加成功



启动 php-fpm
# chkconfig php-fpm on            //启动php-fpm
# /etc/init.d/php-fpm start
出现 Starting php-fpm  done 
# /etc/init.d/php-fpm  status     //查看PHP(也就是php-fpm)运行状态
php-fpm (pid 2306) is running...   运行成功

7、常用命令(启动PHP 也就是 php-fpm)

/etc/init.d/php-fpm  start    开启服务
/etc/init.d/php-fpm  stop    停止服务
/etc/init.d/php-fpm  status    查看状态
/etc/init.d/php-fpm  restart    重启服务
/etc/init.d/php-fpm  reload    平滑重启

加入系统服务以后可以使用
service php-fpm  start/stop/status/restart/reload

 8、PHP安装路径

# netstat -ntpl     查看9000端口是否开启(PHP使用的是9000端口)
/etc/init.d/php-fpm    php启动文件
/usr/local/php    PHP安装目录
/usr/local/php/bin/  可执行目录
/etc/php.ini      PHP配置文件

9、让nginx支持php

(1)在默认站点目录下创建 index.php
# vim /usr/local/nginx/html/index.php 
内容如下:
<?php
        phpinfo();
?>

(2)修改默认站点的配置文件

# vim /usr/local/nginx/conf/nginx.conf

修改如下两处

Nginx中的PHP是以fastcgi扩展的方式结合起来的,也可以理解为Nginx代理了php的fastcgi,因此还需要开放下面的配置,(把前面的#号去掉)

(3)重启nginx 

访问:http://106.12.52.97/index.php

OK PHP可以正常在nginx服务器运行了

10、让PHP支持Mysql

(1)官方下载phpmyadmin-4.9.0.1
https://www.phpmyadmin.net/

# cd /mydata/
# wget https://files.phpmyadmin.net/phpMyAdmin/4.9.0.1/phpMyAdmin-4.9.0.1-all-languages.zip
# unzip phpMyAdmin-4.9.0.1-all-languages.zip  解压
# mv phpMyAdmin-4.9.0.1-all-languages phpmyadmin    重命名
# cp -r ./phpmyadmin  /usr/local/nginx/html/      拷贝到 默认站点下

(2)http://106.12.52.97/phpmyadmin/index.php  输入用户名root  密码niu123456 登录,首页出现如下:

解决:短语密码
# cd /usr/local/nginx/html/phpmyadmin/
依次在 ./config.sample.ini.php 和  ./libraries/config.default.php 两个文件中找到 
$cfg['blowfish_secret'] = ' ';
设置一个32位的值(数字字母任意写)
如 : $cfg['blowfish_secret'] = '62fce85190b89bd61fa6ba2e87a39658';

创建 tmp目录
# mkdir tmp
# chmod -R 777 ./tmp

 

再次登录 http://106.12.52.97/phpmyadmin/index.php  OK 成功 
到此, 整个LNMP 全部安装配置完成!!
更多设置,可以 拷贝./config.sample.ini.php 变为  config.ini.php 进行配置

 

版权声明:本文来源CSDN,感谢博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
原文链接:https://blog.csdn.net/niuxitong/article/details/99783280
站方申明:本站部分内容来自社区用户分享,若涉及侵权,请联系站方删除。
  • 发表于 2020-03-01 21:56:10
  • 阅读 ( 1992 )
  • 分类:Linux

0 条评论

请先 登录 后评论

官方社群

GO教程

猜你喜欢