搭建个人网站软件安装(均在Root用户下完成)
系统环境为:Centos7.6
参考文献:
在CentOS 7系统上安装PHP 7.4版本的方法
解决CentOS中yum安装程序时出现的"Transaction check error"错误
Centos7下安装MySQL
Centos 7下安装配置Nginx
Nginx和PHP的配置
确保系统中有网络工具
sudo yum install -y net-tools
服务启动失败可能原因:端口被占用
netstat -nptl #查看端口占用情况
firewall-cmd --state #查看防火墙状态
##查看开启的端口和服务
firewall-cmd --permanent --zone=public --list-services //服务空格隔开
firewall-cmd --permanent --zone=public --list-ports //端口空格隔开
1.Nginx安装
- 配置 EPEL 源
yum install epel-release -y
yum -y update
- 安装Nginx
yum install -y nginx
- 开启端口
firewall-cmd --permanent --zone=public --add-service=http
firewall-cmd --permanent --zone=public --add-service=https
firewall-cmd --reload
- Nginx 操作
systemctl start nginx #启动Nginx
systemctl status nginx #查看nginx运行状态
systemctl stop nginx #停止nginx
systemctl restart nginx #重启nginx
systemctl enable nginx #开机自启
systemctl disable nginx #禁止开机自启
2.MySQL安装
- 下载并安装官方yum源
wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
- 安装MySQL
yum -y install mysql57-community-release-el7-10.noarch.rpm
yum -y install mysql-community-server
- MySQL操作
systemctl start mysqld.service #启动MySQL
systemctl status mysqld.service #查看MySQL运行状态
- 查询初始密码
grep "password" /var/log/mysqld.log
- 进入数据库
mysql -uroot -p
- 修改密码(大小写字母符号都要有)
ALTER USER 'root'@'localhost' IDENTIFIED BY 'new password';
- 关闭自动更新
yum -y remove mysql57-community-release-el7-10.noarch
3.PHP安装
- 添加EPEL和REMI存储库
yum install dnf -yyum -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
yum -y install https://rpms.remirepo.net/enterprise/remi-release-7.rpm
- 启用PHP 7.4 Remi 存储库
yum -y install yum-utils
yum-config-manager --enable remi-php74
- 安装PHP 7.4
yum update
yum install php php-cli
如果出现"Transaction check error"错误,则删除报冲突的软件包,具体见出现的"Transaction check error"错误
- 安装其他软件包
yum install php php-cli php-fpm php-mysqlnd php-zip php-devel php-gd php-mcrypt php-mbstring php-curl php-xml php-pear php-bcmath php-json
- 查看版本
php -v
- 查看启用的模块
php --modules
4.配置nginx.conf
- php文件路径
/usr/share/nginx/html;
- nginx.conf 文件路径
/etc/nginx/nginx.conf
- 配置示例
server {listen 80; #default_server;#listen [::]:80 default_server;server_name www.nikkicqd.com;#注释掉原本的根路径#root /usr/share/nginx/html/;# Load configuration files for the default server block.include /etc/nginx/default.d/*.conf;location / {root /usr/share/nginx/html;index index.php index.html index.htm;}error_page 404 /404.html;location = /404.html {}error_page 500 502 503 504 /50x.html;location = /50x.html {}#新添加信息location ~ \.php$ {#设置默认网站根目录root /usr/share/nginx/html;#设置监听端口fastcgi_pass 127.0.0.1:9000;#设置nginx的默认首页文件fastcgi_index index.php;#设置脚本文件请求的路径fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;include fastcgi_params;}}
- 重启服务
systemctl restart nginx
5.验证Nginx+PHP已经配置成功
在 /usr/share/nginx/html 中创建 php_info.php,写入
<?php
phpinfo();
在网页上访问 www.***.com/php_info.php