搜索
首页后端开发PHP7详解LiNUX安装PHP7.X

详解LiNUX安装PHP7.X

Mar 09, 2021 am 09:29 AM
linux

详解LiNUX安装PHP7.X

LiNUX安装PHP7.X
PHP版本:7.2.12
下载地址:http://cn2.php.net/get/php-7.2.12.tar.bz2/from/this/mirror

推荐(免费):PHP7

安装前准备,避免在安装PHP依赖包时报错:configure: error: mcrypt.h not found. Please reinstall libmcrypt.
添加 epel 源

centos 7.x

rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

此处我将PHP 下载到 /usr/local 下,进入此目录下

tar -zxvf php7.2.12tar.gz

进入目录

cd php-7.2.12

安装PHP依赖包

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目录到 /usr/local/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-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

编译并安装:

make && make install

编译完成之后,我们添加PHP命令到环境变量里

vim  /etc/profile

在文件末尾加入:

PATH=$PATH:/usr/local/php/bin
export PATH

要使改动立即生效执行

source /etc/profile

查看PHP 版本

php -v

在这里插入图片描述

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

cp php.ini-production /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
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm

启动php-fpm

/etc/init.d/php-fpm start

nginx和php-fpm整合
编辑/usr/local/nginx/nginx.conf

修改如下:
红框中 “#”号去掉
在这里插入图片描述
在这里插入图片描述
添加红框中内容
在这里插入图片描述
修改内容,如下(找到如下开头内容)
在这里插入图片描述

这里我将配置文件换到我自定义的文件中去,不做以上修改;
在这里插入图片描述
只在文件末尾加入

client_max_body_size 200m;
include vhosts/*.conf;

创建文件夹,并创建编辑 app.conf 文件

mkdir vhosts
vim app.conf

编辑内容:

server
{
  listen       80;
  server_name 39.105.186.95   vv.vv.com;
  index index.php index.html;
  root  /home/html/angel;

  location ~ .*\.(php|php7)?$
  {
    #fastcgi_pass  unix:/tmp/php-cgi.sock;
    fastcgi_pass  127.0.0.1:9000;
    fastcgi_index index.html;
    include       /usr/local/nginx/conf/fastcgi.conf;
    client_max_body_size  1000m;
  }

  location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
  {
    expires      7d;
  }

  location ~ .*\.(js|css)?$
  {
    expires      1h;
  }

  if (!-e $request_filename) {
   rewrite ^/index.php(.*)$ /index.php?s=$1 last;
   rewrite ^(.*)$ /index.php?s=$1 last;
   break;
  }
}

更多相关免费学习推荐:PHP7教程

以上是详解LiNUX安装PHP7.X的详细内容。更多信息请关注PHP中文网其他相关文章!

声明
本文转载于:CSDN。如有侵权,请联系admin@php.cn删除

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

AI Hentai Generator

AI Hentai Generator

免费生成ai无尽的。

热门文章

R.E.P.O.能量晶体解释及其做什么(黄色晶体)
1 个月前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.最佳图形设置
1 个月前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.如果您听不到任何人,如何修复音频
1 个月前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.聊天命令以及如何使用它们
1 个月前By尊渡假赌尊渡假赌尊渡假赌

热工具

Atom编辑器mac版下载

Atom编辑器mac版下载

最流行的的开源编辑器

PhpStorm Mac 版本

PhpStorm Mac 版本

最新(2018.2.1 )专业的PHP集成开发工具

禅工作室 13.0.1

禅工作室 13.0.1

功能强大的PHP集成开发环境

WebStorm Mac版

WebStorm Mac版

好用的JavaScript开发工具

SublimeText3 Mac版

SublimeText3 Mac版

神级代码编辑软件(SublimeText3)