CentOS7 安装 Nginx PHP
生活随笔
收集整理的這篇文章主要介紹了
CentOS7 安装 Nginx PHP
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
安裝 Nginx
# Nginx沒有內(nèi)置在默認的CentOS repositories, 我們先安裝EPEL repository yum install epel-release -y # 安裝 Nginx yum install nginx -y # 啟動nginx和讓nginx在linux啟動時自動運行 systemctl start nginx systemctl enable nginx安裝 PHP v7.4
# 安裝額外包括 PHP v7.4 的 CentOS repo wget http://rpms.remirepo.net/enterprise/remi-release-7.rpm rpm -Uvh remi-release-7.rpm# 使 php74 repository 生效(默認不生效): yum install yum-utils -y yum-config-manager --enable remi-php74# 然后安裝 PHP package: yum --enablerepo=remi,remi-php72 install php-fpm php-common# 安裝通用模塊: 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配置 Nginx 和 PHP 7.4 匹配
修改 /etc/nginx/conf.d/default.conf:
server {listen 80;server_name your_server_ip;# note that these lines are originally from the "location /" blockroot /usr/share/nginx/html;index index.php index.html index.htm;location / {#try_files $uri $uri/ =404;try_files $uri $uri/ /index.php?q=$uri&$args;}error_page 404 /404.html;error_page 500 502 503 504 /50x.html;location = /50x.html {root /usr/share/nginx/html;}location ~ \.php$ {try_files $uri =404;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;} }修改完重啟nginx:
systemctl restart nginx進行 PHP-FPM 的配置:/etc/php-fpm.d/www.conf
找到并替換幾行:
user = apache 換為: user = nginx group = apache 換為:group = nginx listen.owner = nobody 換為: listen.owner = nginx listen.group = nobody 換為: listen.group = nginx在listen = 127.0.0.1:9000 下面增加:
listen = /var/run/php-fpm/php-fpm.sock最后, 啟動 php-fpm 并讓它自啟動:
systemctl start php-fpm.service systemctl enable php-fpm.service測試
echo "<?php phpinfo(); ?>" >> /usr/share/nginx/html/index.php總結(jié)
以上是生活随笔為你收集整理的CentOS7 安装 Nginx PHP的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: VSCode设置命令行终端为Git
- 下一篇: ThinkPHP6项目基操(7.模型)