Linux-安装-PHP

20191114 作者:陈文小超

准备工作

  1. 安装php依赖包
wget https://sourceforge.net/projects/mcrypt/files/Libmcrypt/2.5.8/

tar -zxvf libmcrypt-2.5.8.tar.gz

cd libmcrypt-2.5.8

./configure --prefix=/usr/local/libmcrypt

make

make install

# 依赖包
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 krb5 krb5-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers

yum install gcc 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

安装PHP

  1. 下载php包并解压
# 下载地址(https://www.php.net/downloads.php)
cd /usr/local/src

# 在windows上前往php官网下载php-7.2.0包,然后使用rz指令将下载好的php安装包上传到centos7上,解压:

tar -zxvf php-7.2.24.tar.gz
  1. 编译PHP

报错参考链接 安装上述步骤进行,一般不会出错

–with-config-file-path此配置是php.ini要存放的目录切记

cd /usr/local/src/php-7.2.24

./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/conf --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-mcrypt --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-native-ttf --enable-gd-jis-conv --with-gettext --with-gmp --with-mhash --enable-json --enable-mbstring --enable-mbregex --enable-mbregex-backtrack --with-libmbfl --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

# 大约需15-20分钟
make

# 进行检验,也可以不执行,大约需要8-10分钟
make test

make install
  • make报错 virtual memory exhausted: Cannot allocate memory make: *** [ext/fileinfo/libmagic/apprentice.lo] Error 1

解决方法参考链接

./configure 执行这一步是添加--disable-fileinfo # 不要采用此方法,会导致后续问题 composer 不能正常使用
  1. 添加PHP命令到环境变量
vim  /etc/profile

# 在文件末尾加入
PATH=$PATH:/usr/local/php/bin
export PATH

# 要使改动立即生效执行
source /etc/profile

# 查看PHP 版本
php -v

这时候,nginx还是不支持php的,它需要php-fpm来处理两者的依赖关系,所以我们要胚子php-fpm

  1. 配置PHP-fpm
# 创建conf
mkdir /usr/local/php/conf

# php.ini-production此文件就在/usr/local/src/php-7.2.24下面
cp php.ini-production /usr/local/php/conf/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

# 注册系统服务并设置开机自启
cp /usr/local/src/php-7.2.24/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm
  1. 启动php-fpm
/etc/init.d/php-fpm start

# 报错
ERROR: [pool www] cannot get uid for user 'nginx'
[14-Nov-2019 03:47:41] ERROR: FPM initialization failed
# 解决方法
useradd nginx
groupadd nginx
usermod -G nginx nginx

启动php-fpm报错解决方法
CentOS7.X中设置nginx和php-fpm的开机自启动

  1. nginx和php-fpm整合–配置nginx支持php
vim /usr/local/nginx/conf/nginx.conf
location / {
            root   html;
            index  index.php index.html index.htm;
        }

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;
        }

# 切记重启Nginx
  1. 写一个PHP文件进行检验
<?php
echo phpinfo();

安装结束

参考文献

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

陈文小超_自律

努力自己,幸福他人

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值