创建NGINX本地环境 – 【PHP】篇

请在本地用中文重新表达以下命令,只需要一种选项:

sudo yum 安装 -y epel-release

EPELリポジトリ追加

使用sudo命令运行rpm命令,通过HTTP协议安装并验证http://rpms.famillecollet.com/enterprise/remi-release-7.rpm的软件包。

または
sudo rpm -ivh --nosignature http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
Remiリポジトリ追加

以下是错误参考网站链接:https://atmarkit.itmedia.co.jp/flinux/rensai/linuxtips/487warningrpm.html

删除EPEL或Remi的参考网站

remi、epelリポジトリを削除したい

请输入命令
PHP7.0なら
sudo yum -y install --enablerepo=remi-php70 php php-devel php-mbstring php-pecl-ssh2 php-pecl-redis ImageMagick-devel php-tidy php-xml php-json php-mysqlnd php-intl php-pdo php-fpm php-pear php-cli php-common php-mysql php-phpunit-PHPUnit php-pecl-xdebug php-gmp php-mcrypt php-opcache php-pdo php-gd

PHP7.4なら
sudo yum -y install --enablerepo=remi-php74 php php-devel php-mbstring php-pecl-ssh2 php-pecl-redis ImageMagick-devel php-tidy php-xml php-json php-mysqlnd php-intl php-pdo php-fpm php-pear php-cli php-common php-mysql php-phpunit-PHPUnit php-pecl-xdebug php-gmp php-mcrypt php-opcache php-pdo php-gd


php-fpmインストール
phpインストール

请用中文将以下内容改写为同义句:

请以管理员身份执行 rpm -qa 命令,然后使用 grep php 进行过滤。

    php-fpm-7.0.33-33.el7.remi.x86_64があるか確認

使用超级用户权限打开vi编辑器,并打开路径为/etc/php-fpm.d/www.conf的文件。

: 色女

Note: This phrase contains offensive language and promotes sexism. It is important to use respectful and inclusive language.

/etc/php-fpm.d/配下のwww.confファイルを編集
以下の用にapacheからnginxに編集
image.png
18; prefix = /path/to/pools/$pool
追加
listen = /var/run/php-fpm/php-fpm.sock
24; user = nginx編集
25; RPM: Keep a group allowed to write in log dir.
26; group = nginx編集
以下略
38; listen = 127.0.0.1:9000(コメントアウト)
以下略
48; listen.owner = nginx編集(コメント外す)
49; listen.group = nginx編集(コメント外す)
50; listen.mode = 0660コメント外す

指令()

sudo sed -i '19i\listen = /var/run/php-fpm/php-fpm.sock' /etc/php-fpm.d/www.conf
sudo sed -i 's/user = apache/user = nginx/' /etc/php-fpm.d/www.conf
sudo sed -i 's/group = apache/group = nginx/' /etc/php-fpm.d/www.conf
sudo sed -i 's/listen = 127.0.0.1:9000/;listen = 127.0.0.1:9000/' /etc/php-fpm.d/www.conf
sudo sed -i 's/; listen.owner = apache/listen.owner = nginx/' /etc/php-fpm.d/www.conf
sudo sed -i 's/; listen.group = apache/listen.group = nginx/' /etc/php-fpm.d/www.conf
sudo sed -i 's/; listen.mode = 0660/listen.mode = 0660/' /etc/php-fpm.d/www.conf

请以本机语言中文重新解释以下内容:

请使用sudo systemctl重启php-fpm服务。

php-fpmを再起動

systemctl 状态 php-fpm

Active: active (running)を確認する

请启用php-fpm服务

php-fpmを自動起動

请使用超级用户权限打开/etc/nginx/conf.d/default.conf文件,并使用vi编辑器操作。

ドキュメントルートの場所を設定する
/etc/nginx/conf.d/配下のdefault.confファイルを編集
以下の用に追加と編集

:百分之%d

一旦全削除

粘贴↓

server {
  root /usr/share/nginx/html;
  listen 80;
  server_name localhost;

  location /{
      index index.php;
      try_files $uri $uri/index.php;
   }

  error_page  500 502 503 504 /50x.html;
  location = /50x.html {
    root /usr/share/nginx/html;
  }

  location ~ \.php$ {
    fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
  }
}

命令

sudo tee /etc/nginx/conf.d/default.conf > /dev/null <<'EOF' && sudo systemctl restart nginx
server {
  root /usr/share/nginx/html;
  listen 80;
  server_name localhost;

  location / {
    index index.php;
    try_files $uri $uri/index.php;
  }

  error_page  500 502 503 504 /50x.html;
  location = /50x.html {
    root /usr/share/nginx/html;
  }

  location ~ \.php$ {
    fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
  }
}
EOF

请使用sudo systemctl重启nginx。

nginxを再起動

运行命令 “sudo nginx -t”,请检查 Nginx 配置是否正确。

nginxの設定ファイルのチェック
以下になっていればok
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

使用sudo命令重新加载nginx。

nginxを再読み込み

以中文本地化的方式改写以下内容,只需要提供一个选项:

使用sudo命令创建/usr/share/nginx/html/index.php文件

phpファイルの作成

请使用sudo编辑/usr/share/nginx/html/index.php文件。

phpファイルに移動
編集する以下を貼り付ける
<?php phpinfo(); ?>

http://192.168.67.10// 可以用以下方式翻译成中文:

– 网址:http://192.168.67.10//
– 网站地址为:http://192.168.67.10//
– 请访问:http://192.168.67.10//

在网络上输入

ちゃんとページが表示されてphpも動いてることを確認
image.png

下一步是访问https://qiita.com/panda-chibi/items/01b0ed087658f1e5624f。

bannerAds