centos 7.5构建Nginx/PHP-FPM

该博客详细介绍了如何在CentOS 7.5上安装Nginx 1.14.2、PHP 7.2.12以及PHP-FPM,包括变更root用户、安装所需仓库、启动和设置开机启动Nginx及PHP-FPM,以及配置Nginx和PHP-FPM以实现PHP文件处理。
摘要由CSDN通过智能技术生成

 

1. Install Nginx, PHP 7.2.12 and PHP-FPM

1.1 Change to root user.


sudo -i
## OR ##
su -

1.2 Install needed repositories


## Remi Dependency on CentOS 7 and Red Hat (RHEL) 7 ##
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

## CentOS 7 and Red Hat (RHEL) 7 ##
rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm

 

1.3 Install Nginx, PHP 7.2.12 and PHP-FPM


yum --enablerepo=remi,remi-php72 install nginx php-fpm php-common

1.4 Install PHP 7.2.12 modules

  • OPcache (php-opcache) – The Zend OPcache provides faster PHP execution through opcode caching and optimization.
  • APCu (php-pecl-apcu) – APCu userland caching
  • CLI (php-cli) – Command-line interface for PHP
  • PEAR (php-pear) – PHP Extension and Application Repository framework
  • PDO (php-pdo) – A database access abstraction module for PHP applications
  • MySQL (php-mysqlnd) – A module for PHP applications that use MySQL databases
  • PostgreSQL (php-pgsql) – A PostgreSQL database module for PHP
  • MongoDB (php-pecl-mongodb) – PHP MongoDB database driver
  • Redis (php-pecl-redis) – Extension for communicating with the Redis key-value store
  • Memcache (php-pecl-memcache) – Extension to work with the Memcached caching daemon
  • Memcached (php-pecl-memcached) – Extension to work with the Memcached caching daemon
  • GD (php-gd) – A module for PHP applications for using the gd graphics library
  • XML (php-xml) – A module for PHP applications which use XML
  • MBString (php-mbstring) – A module for PHP applications which need multi-byte string handling
  • MCrypt (php-mcrypt) – Standard PHP module provides mcrypt library support

 


yum --enablerepo=remi,remi-php72 install php-opcache php-pecl-apcu php-cli php-pear php-pdo php-mysqlnd php-pgsql php-pecl-mongodb php-pecl-redis php-pecl-memcache php-pecl-memcached php-gd php-mbstring php-mcrypt php-xml

1.5 Start Nginx HTTP server and PHP-FPM (FastCGI Process Manager)

Start Nginx


## Fedora 29/28/27 and CentOS/RHEL 7.5 ##
systemctl start nginx.service

Start PHP-FPM


## Fedora 29/28/27 and CentOS/RHEL 7.5 ##
systemctl start php-fpm.service

1.6 Autostart Nginx and PHP-FPM on boot

Autostart Nginx on boot


## Fedora 29/28/27 and CentOS/RHEL 7.5 ##
systemctl enable nginx.service

Autostart PHP-FPM on boot


## Fedora 29/28/27 and CentOS/RHEL 7.5 ##
systemctl enable php-fpm.service

1.7 Configure Nginx and PHP-FPM

配置nginx支持php
 cp /etc/nginx/nginx.conf  /etc/nginx/nginx.confbak#备份原有配置文件
vi /etc/nginx/nginx.conf #编辑
user nginx nginx; #修改nginx运行账号为:nginx组的nginx用户
:wq  #保存退出
cp /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.confbak #备份原有配置文件
vi /etc/nginx/conf.d/default.conf #编辑

index index.php index.html index.htm; #增加index.php

# 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 $document_root$fastcgi_script_name;
 include fastcgi_params;
 }
#取消FastCGI server部分location的注释,并要注意fastcgi_param行的参数,改为$document_root$fastcgi_script_name,或者使用绝对路径
systemctl restart nginx.service #重启nginx

把 test.php 上传/usr/share/nginx/html.

cd /usr/share/nginx/html

vi test.php  #添加以下代码
<?php
phpinfo();
?>

:wq! #保存退出

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值