一、安装Nginx
1.1关闭seinux
vim /etc/selinux/config
#SELINUX=enforcing #注释掉
#SELINUXTYPE=targeted #注释掉
SELINUX=disabled #增加
shutdown -r now #重启系统
getenforce #查看SEliunx状态
1.2 安装环境依赖包
yum groupinstall "Development tools" -y
yum install pcre-devel expat-devel zlib zlib-devel openssl-devel expat-devel -y
yum install gcc gcc-c++ pcre pcre-devel -y
1.3 下载nginx 并解压nginx
wget http://nginx.org/download/nginx-1.20.2.tar.gz
tar xf nginx-1.20.2.tar.gz
1.4 创建nginx 用户和组
useradd -r -s /sbin/nologin nginx
1.5 编译安装Nginx
cd nginx-1.20.2
vim nginx.sh (将下列信息复制到脚本)
./configure \
--prefix=/usr/local/nginx \
--sbin-path=/usr/sbin/nginx \
--modules-path=/usr/lib64/nginx/modules \
--conf-path=/etc/nginx/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--pid-path=/var/run/nginx.pid \
--lock-path=/var/run/nginx.lock \
--http-client-body-temp-path=/var/cache/nginx/client_temp \
--http-proxy-temp-path=/var/cache/nginx/proxy_temp \
--http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \
--http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \
--http-scgi-temp-path=/var/cache/nginx/scgi_temp \
--user=nginx \
--group=nginx \
--with-compat \
--with-file-aio \
--with-threads \
--with-http_addition_module \
--with-http_auth_request_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_mp4_module \
--with-http_random_index_module \
--with-http_realip_module \
--with-http_secure_link_module \
--with-http_slice_module \
--with-http_ssl_module \
--with-http_stub_status_module \
--with-http_sub_module \
--with-http_v2_module \
--with-mail \
--with-mail_ssl_module \
--with-stream \
--with-stream_realip_module \
--with-stream_ssl_module \
--with-stream_ssl_preread_module
chmod +x nginx.sh #给脚本添加可执行权限
./nginx.sh #运行脚本
make && make install #编译并安装
1.6添加环境变量,查看版本,防火墙放行80端口
export PATH=$PATH:/usr/sbin/nginx
source /etc/profile
nginx -v
firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --reload
firewall-cmd --zone=public --list-ports
systemctl restart firewalld.service
1.7测试nginx
netstat -lnt | grep 80
nginx -t
问题:
nginx: [emerg] mkdir() "/var/cache/nginx/client_temp" failed (2: No such file or directory)
解决: mkdir -p /var/cache/nginx/client_temp
1.8 设置Nginx 开机自启动
vim /lib/systemd/system/nginx.service
填写以下信息
[Unit]
Description=nginx service
After=network.target
[Service]
Type=forking
ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf #路径请根据实际配置修改
ExecReload=/usr/sbin/nginx-s reload #路径请根据实际配置修改
ExecStop=/usr/sbin/nginx -s quit #路径请根据实际配置修改
PrivateTmp=true
[Install]
WantedBy=multi-user.target
systemctl enable nginx.service 设置开机自启
二、安装Mysql 8.0.28
2.1 删除系统已有的数据库
rpm -qa | grep mysql
yum remove mysql-xxx-xxx-
rpm -qa | grep mariadb
rpm -e --nodeps mariadb-libs-5.5.68-1.el7.x86_64
2.1 下载mysql 8.0 官方yum源
wgethttps://dev.mysql.com/get/mysql80-community-release-el7-5.noarch.rpm
yum localinstall mysql80-community-release-el7-5.noarch.rpm -y
2.3 更新yum源
yum clean all
yum makecache
2.4 安装mysql 并启动sql服务
yum install mysql-community-server -y
systemctl start mysqld
2.5 更改mysql默认的随机密码
查看默认密码
cat /var/log/mysqld.log | grep password
mysql -u root -p 输入默认密码进行修改
ALTER USER 'root'@'localhost' IDENTIFIED BY 'Test@#1';
三 、安装php8.1.3
3.1 安装之前先检查一下系统是否有默认安装的php,如有删除
rpm -qa|grep php
rpm -e ***(包名) #删除已有包
3.2 将yum源更换为aliyun的remi
yum install epel-releas
yum -y installhttps://mirrors.aliyun.com/remi/enterprise/remi-release-7.rpm
yum -y install yum-utils
3.3 查询可安装的PHP包版本
yum repolist all |grep php
3.4 安装php8.1.3 并查看版本
yum-config-manager --enable remi-php81
sudo yum install -y php-cli php-fpm php-mysqlnd php-zip php-devel php-gd php-mbstring php-curl php-xml php-pear php-bcmath php-json php-redis --skip-broken
php -v
四、配置Nginx 解析php
4.1 vim /etc/nginx/nginx.conf (修改以下信息)
4.1.1找到
location / {
root html;
index index.html index.htm index.php;
} 增加index.php
4.1.2 找到
#location ~ \.php$ {
#root html;
#fastcgi_pass 127.0.0.1:9000;
#fastcgi_index index.php;
#fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
#include fastcgi_params;
#}
修改
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
#fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
4.2 vim测试PHP
vim /usr/local/nginx/index.php (添加php配置信息文档)
<?php
phpinfo();
?>
4.3 nginx -s reload #重启nginx服务
4.4 systemctl restart php-fpm #重启php服务
五、修改ssh 端口,配置防火墙
5.1 vim /etc/ssh/sshd_config
5.2 去掉注释 增加Port 10010
5.3 yum install -y policycoreutils-python
5.4 semanage port -l|grep ssh #查看SELinux开放给ssh使用的端口
5.5 semanage port -a -t ssh_port_t -p tcp 10010 # SELinux 添加10010端口
5.6 firewall-cmd --zone=public --add-port=10010/tcp --permanent # 防火墙放行10010端口
5.7 firewall-cmd --reload #重新加载防火墙策略
5.8 firewall-cmd --zone=public --list-ports # #查看开放的窗口
5.9 systemctl restart sshd #重启sshd服务
5.10 systemctl restart firewalld.service #重启防火墙
5.11 shutdown -r now #重启机器进行链接