原文 : https://ivanagyro.medium.com/於centos7安裝-nginx-php7-php-fpm-laravel5-6-df8631681acf
安装nginx

 1/ 用yum安裝Nginx

yum install nginx

預設開機開啟Nginx

systemctl enable nginx

啟動Nginx

systemctl start nginx


安装php
2 安装Remi和EPEL数据源
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm -Uvh https://rpms.remirepo.net/enterprise/remi-release-7.rpm

3. 启用Remi

vi /etc/yum.repos.d/remi.repo

4.更改[remi]区域的代码块为如下,相同则不用更改

[remi]
name=Remi's RPM repository for Enterprise Linux 7 - $basearch
#baseurl=http://rpms.remirepo.net/enterprise/7/remi/$basearch/
#mirrorlist=https://rpms.remirepo.net/enterprise/7/remi/httpsmirror
mirrorlist=http://cdn.remirepo.net/enterprise/7/remi/mirror
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi

5.启用Remi PHP7.3数据源

vi /etc/yum.repos.d/remi-php73.repo

6.更改[remi-php73]区域的代码块为如下

[remi-php73]
name=Remi's PHP 7.3 RPM repository for Enterprise Linux 7 - $basearch
#baseurl=http://rpms.remirepo.net/enterprise/7/php73/$basearch/
mirrorlist=https://rpms.remirepo.net/enterprise/7/php73/httpsmirror
mirrorlist=http://cdn.remirepo.net/enterprise/7/php73/mirror
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi

7.升级php到php7.3

yum -y upgrade php*

8.检查php版本

php -v

9.重启php-fpm

service restart php-fpm

安裝與設定php-fpm

  1. 安裝php-fpm
yum install php-fpm

2. 設定php-fpm,修改 /etc/php-fpm.d/www.conf

修改user和group,為nginx

user = nginx
group = nginx

如果要改為使用socket file(預設使用127.0.0.1:9000),則需開啟並修改listen設定為下方樣子

listen = /path/to/unix/socketlisten.owner = nobody
listen.group = nobody
listen.mode = 0666

3. 如果在debug階段,想要開啟display error,則修改以下設定

php_flag[display_errors] = on
php_flag[display_startup_errors] = on

4. 預設開機開啟php-fpm

systemctl enable php-fpm

5. 啟動php-fpm

systemctl start php-fpm

設定Nginx

  1. 修改 /etc/nginx/conf.d/default.conf ,以連接php-fpm,以下為範例
server {
listen 80;
server_name localhost; #charset koi8-r;
#access_log /var/log/nginx/host.access.log main; root /usr/share/nginx/html;
index index.html index.htm index.php; location / {
# autoindex on; // 如果想要開啟顯示資夾目錄的話加入這條
// 建議只在debug階段開啟
try_files $uri $uri/ /index.php?$query_string;
} #error_page 404 /404.html; # redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
} # proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000
// 若使用file socket則改成下面這行
# fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
} # deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}

2. 重新載入Nginx的設定

nginx -s reload

現在可以試著在Nginx的root directory加入index.php,內容如下。看是否能透過瀏覽器取得php的資訊

CentOS7安裝 Nginx + php7 + php-fpm的更多相关文章

  1. centos7下搭建nginx+php7.1+mariadb+memcached+redis

    一.环境准备 1.首先介绍一下环境,以及我们今天的主角们 我用的环境是最小化安装的centos7,mariadb(江湖传言mysql被oracle收购后,人们担心像java一样毁在oracle手上于是 ...

  2. CentOS7下搭建Nginx+PHP7的安装配置

    一.安装编译工具及库文件: yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel 环境要求 nginx是C ...

  3. linux下nginx安裝

    1.yum安裝 yum安裝  http://nginx.org/packages/centos/7/noarch/RPMS/ 第一步: 安裝命令: yum localinstall http://ng ...

  4. Ubuntu安裝nginx-1.6.2

    1.在執行完./configure 和make install 後出現 test -d '/usr/local/nginx/logs'         || mkdir -p '/usr/local/ ...

  5. Centos7 Nginx+PHP7 配置

    Centos7 Nginx+PHP7 配置 内容: 源码编译安装Nginx和PHP 配置PHP和Nginx,实现Nginx转发到PHP处理 测试 设置Nginx.PHP开机自启 安装的版本: Ngin ...

  6. 沈逸老师ubuntu速学笔记(2)-- ubuntu16.04下 apache2.4和php7结合编译安装,并安裝PDOmysql扩展

    1.编译安装apache2.4.20 第一步: ./configure --prefix=/usr/local/httpd --enable-so 第二步: make 第三步: sudo make i ...

  7. 鸟哥之安裝 CentOS7.x

    http://linux.vbird.org/linux_basic/0157installcentos7.php since 2002/01/01 新手建議 開始閱讀之前 網站導覽 Linux 基礎 ...

  8. centos7 系統vps安裝mysql5.6及設置本地遠程連接筆記

    用xshell連接上vps 1,下载mysql的repo源 wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm su ...

  9. Centos7編譯安裝LAMP平臺

    什麽是LAMP? 拆開看 L 就是Linux系統 A是Apache的縮寫 M.P則是MySQL和PHP的简写. 其实就是把Apache, MySQL以及PHP安装在Linux系统上,组成一个环境来运行 ...

  10. Linux Centos7.2 编译安装PHP7.0.2

    操作环境: 1.系统:Centos7.2 2.服务:Nginx 1.下载PHP7.0.2的安装包解压,编译,安装: $ cd /usr/src/ $ wget http://cn2.php.net/d ...

随机推荐

  1. Ubuntu snap 下载慢

    解决方法 sudo apt-get install snapd sudo snap install snap-store sudo snap install snap-store-proxy sudo ...

  2. Java 入门与进阶P-7.3+P-7.4

    函数的调用 简单应用举例 例1:编写一个求两个数的和的子函数 要求使用键盘录入的方式: 分析与总结: 要实现某一功能,把其定义为一个函数封装起来 就可以重复多次使用:这样一来,main函数里的代码减少 ...

  3. C#实现聊天消息渲染、图文混排(支持Windows、Linux)

    在实现聊天软件时,渲染文字表情图文混排是一项非常繁琐的工作,再加上还要支持GIF动图.引用消息.撤回消息.名片等不同样式的消息渲染时,就更加麻烦了. 好在我们可以使用 ESFramework 提供的 ...

  4. 关于C#中async/await的用法

    一直对c#中async/await的用法模模糊糊,不太清晰,今天写了一下Demo彻底明确一下async/await的用法,以免因为对其不了解而对后期的业务产生影响(比如事务导致的锁表等等). 1. 首 ...

  5. KingbaseES恢复被删除数据

    KingbaseES恢复被删除数据 生产环境操作请先备份整个data目录或cp 当前数据目录/home/kingbase/pg_data到新的data目录,然后在备份的data目录进行恢复被删除数据操 ...

  6. 用ksweb+Android做服务器,搭建WordPress博客环境

    旧的安卓手机不要仍,安装上ksweb给wordpress做服务器,隔壁小孩都馋哭了. 为了能在自己的安卓手机服务器上写博客,首先我们来了解一下WordPress和ksweb: WordPress是使用 ...

  7. Ribbon负载均衡 (源码分析)

    Ribbon负载均衡 SpringCloud已经删除了ribbon组件,所以需要手动导入依赖.(要学是因为很多项目业务已经使用了ribbon) 服务拉取的时候添加了@LoadBalanced注解,实现 ...

  8. RestTemplate的超全讲解(全)转

    RestTemplate的超全讲解(全)转 https://blog.csdn.net/weixin_47872288/article/details/121842374 (81条消息) RestTe ...

  9. Html音频播放代码

    页面代码: <html> <head> <script src="https://code.jquery.com/jquery-3.1.1.min.js&quo ...

  10. centos7 在线或离线安装python3

    1.前言 本文会使用到yum和wget,如果两者都不能用,参考安装教程 https://www.cnblogs.com/dennisdong/p/17037248.html 2.查看是否安装wget和 ...