更新Centos7系统
yum update
安装wegt vim htop git
yum install git wegt vim screen
关闭防火墙
systemctl stop firewalld.service
systemctl disable firewalld.service
安装epel仓库
sudo yum install epel-release
安装yum-utils
yum install yum-utils
CentOS 7 安装 Remi 存储库
sudo yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
查 Remi 存储库中有哪些 PHP版本可用
yum --disablerepo="*" --enablerepo="remi-safe" list php[7-9][0-9].x86_64
安装自己需要的版本安装8.1.11
sudo yum-config-manager --enable remi-php81
使用yum安装PHP。将安装所有必需的包以在 Nginx 中设置 PHP 允许它连接到基于 MySQL 的数据库:
sudo yum install php php-mysqlnd php-fpm
更改php配置。我们安装的是nginx php默认apache,改为nginx.
vim /etc/php-fpm.d/www.conf
输入i,编辑文件。修改完后按 ESC+ : wq 保存退出
默认配置文件
…
; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user's group
; will be used.
; RPM: apache user chosen to provide access to the same directories as httpd
user = apache
; RPM: Keep a group allowed to write in log dir.
group = apache
…
改为
…
; RPM: apache user chosen to provide access to the same directories as httpd
user = nginx
; RPM: Keep a group allowed to write in log dir.
group = nginx
…
------------------------------------------------------
listen = 127.0.0.1:9000;
改为
listen = /var/run/php-fpm/php-fpm.sock;
找到此行改为
listen.owner = nginx
listen.group = nginx
listen.mode = 0660
启动php-fpm服务
sudo systemctl start php-fpm
编辑PHP的配置文件,/etc/php.ini,注意去掉分号注释
vim /etc/php.ini
将
;cgi.fix_pathinfo=1
改为
cgi.fix_pathinfo=0
修改nginx配置php
vim /etc/nginx/nginx.conf
server {
listen 80;
server_name server_domain_or_IP;
root /usr/share/nginx/html;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ =404;
}
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 以应用更改
sudo systemctl restart nginx
添加 CentOS 7 EPEL 存储库
sudo yum install epel-release
EPEL 存储库已安装在您的服务器上,使用以下yum命令安装 Nginx
sudo yum install nginx
安装完成后,启动 Nginx 服务:
sudo systemctl start nginx
设置开机启动
sudo systemctl enable nginx
进入opt目录,下载centos7的mysql的yum存储库并安装。
cd /opt
rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
wget https://dev.mysql.com/get/mysql5.7-community-release-el7-7.noarch.rpm
rpm -ivh mysql5.7-community-release-el7-7.noarch.rpm --force --nodeps
选择mysql版本
vim /etc/yum.repos.d/mysql-community.repo
安装mysql-server,并启动
yum install mysql-server
service mysqld start
查看mysql临时密码
grep 'temporary password ' /var/log/mysqld.log
登录mysql
mysql -uroot -p
修改mysql的root密码
alter USER 'root'@'localhost' IDENTIFIED BY 'Aoz07123..';
创建chemex数据库
create database chemex default charset 'utf8';
创建chemex数据库用户和密码
create user 'chemex'@'%' identified by 'Aoz07123..';
给新创建的用户远程登陆权限
grant all on chemex.* to 'chemex'@'%';
刷新配置
flush privileges;
重启数据库
systemctl restart mysqld
Q.E.D.