> 文章列表 > CentOS 7 Linux安装nginx 1.22.1 + php 8.0.28 + mysql

CentOS 7 Linux安装nginx 1.22.1 + php 8.0.28 + mysql

CentOS 7 Linux安装nginx 1.22.1 + php 8.0.28 + mysql

centos 7永久关闭SELinux

sudo sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
sudo setenforce 0

centos 7安装mysql

https://rudon.blog.csdn.net/article/details/130097058

centos 7安装php 8.0.28

# 先假设我们要设置/var/www/localhost目录为localhost根目录
# 再假设我们当前使用的用户为nginx、php-fpm的运行用户,方便我们编辑www文件
# 预先写入index.php文件,显示phpinfo()

sudo mkdir -p /var/www/localhost
sudo chown -R king:king /var/www/localhost
sudo bash -c 'echo "<?php phpinfo(); " >> /var/www/localhost/index.php'

# 添加remi源(可能需要提前安装epel-release)

sudo yum install -y https://rpms.remirepo.net/enterprise/remi-release-7.rpm

# 单独启用php80的源(没有yum-config-manager命令的话需要安装yum-utils)

sudo yum install -y yum-utils device-mapper-persistent-data lvm2
sudo yum-config-manager --disable 'remi-php*'
sudo yum-config-manager --enable remi-php80

# 安装相关拓展

sudo yum install -y php-bcmath php-cli php-common php-devel php-fpm php-gd php-intl php-ldap php-mbstring php-mysqlnd php-odbc php-pdo php-pear php-pecl-xmlrpc php-pecl-zip php-process php-snmp php-soap php-sodium php-xml

# 安装php

sudo yum install -y php

# 设置开机启动

sudo systemctl enable php-fpm.service

# 启动php-fpm

sudo systemctl start php-fpm.service

# 查看php-fpm状态

sudo systemctl status php-fpm

# 检查版本号

php -v
php-fpm -v

# 修改php-fpm配置,使其user和group为当前你的用户名

sudo vim /etc/php-fpm.d/www.conf

找到
user = apache
修改为
user = king
找到
group = apache
修改为
group = king

# 重启php-fpm服务

sudo systemctl restart php-fpm

# 查看php-fpm服务

sudo systemctl status php-fpm

centos 7安装nginx 1.22.1

# 安装nginx

sudo yum install -y nginx

# 设置开机启动

sudo systemctl enable nginx.service

# 启动nginx

sudo systemctl start nginx.service

# 重启nginx

sudo systemctl restart nginx.service

# 修改nginx主配置文件,设置运行用户为你的当前用户名

sudo vim /etc/nginx/nginx.conf

参考内容:

user  king;
worker_processes  auto;error_log  /var/log/nginx/error.log notice;
pid        /var/run/nginx.pid;events {worker_connections  1024;
}http {include       /etc/nginx/mime.types;default_type  application/octet-stream;log_format  main  '$remote_addr - $remote_user [$time_local] "$request" ''$status $body_bytes_sent "$http_referer" ''"$http_user_agent" "$http_x_forwarded_for"';access_log  /var/log/nginx/access.log  main;sendfile        on;#tcp_nopush     on;keepalive_timeout  65;#gzip  on;include /etc/nginx/conf.d/*.conf;
}

# 虚拟主机vhost配置 - 添加PHP支持
# 注意:两个root的值都要改为项目根目录,另外fastcgi_param已大改,另外已改location /那里的index在最前面添加index.php

sudo vim /etc/nginx/conf.d/default.conf

参考内容:


server {listen       80;server_name  localhost;#access_log  /var/log/nginx/host.access.log  main;location / {root   /var/www/localhost;index  index.php index.html index.htm;}#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   /var/www/localhost;# }# 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$ {root           /var/www/localhost;fastcgi_pass   127.0.0.1:9000;fastcgi_index  index.php;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;#}
}

# 重启nginx服务器

sudo systemctl restart nginx

# 在浏览器中访问 http://localhost

# OK!

绿色卫生网