yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel #编译环境
cd /opt
wget https://nginx.org/download/nginx-1.25.3.tar.gz
tar zxvf nginx-1.25.3.tar.gz
cd nginx-1.25.3
mkdir -p /www/nginx
./configure --prefix=/www/nginx
make && make install
/www/nginx/sbin/nginx
常用指令
nginx -V 查看版本,以及配置文件地址
nginx -v 查看版本
nginx -c filename 指定配置文件
nginx -h 帮助
nginx -s reload|reopen|stop|quit // 重新加载配置|重启|停止|退出 nginx")重新加载配置|重启|停止|退出 nginx
nginx -t //查看配置是否有语法错误
nginx -c /usr/local/etc/nginx/nginx.conf //启动是加载指定nginx.conf文件
location ~ \.php$ {
root /www/nginx/php;
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; #支持解析php文件
include fastcgi_params;
}
yum -y install epel-release yum-utils
Remi软件源官方地址: https://rpms.remirepo.net/
yum -y install https://rpms.remirepo.net/enterprise/remi-release-7.rpm
yum启动php模块,根据需要选择自己格式的版本,如remi-php74模块,就是php7.4版本。:
yum-config-manager --enable remi-php80 #启用remi源的php8.0模块
注:如果显示没有这个命令,则需要先安装yum -y install yum-utils 插件。
yum install php 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
安装成功:php -v 查看版本为php8.0版本
[root@xx logs]# whereis php-fpm
php-fpm: /usr/sbin/php-fpm /etc/php-fpm.d /etc/php-fpm.conf /usr/share/man/man8/php-fpm.8.gz
[root@xx logs]# systemctl start php-fpm
yum安装mysql
MySQL三种安装方法(yum安装、编译安装、二进制安装)
如果安装过先卸载,第一次安装略过此步
[root@bunian etc]# rpm -qa | grep mysql
mysql-community-common-5.7.38-1.el7.x86_64
mysql-community-client-5.7.38-1.el7.x86_64
mysql80-community-release-el7-6.noarch
mysql-community-server-5.7.38-1.el7.x86_64
mysql-community-libs-5.7.38-1.el7.x86_64
# 所有组件都要删除
[root@bunian etc]# rpm -e --nodeps mysql-community-common-5.7.38-1.el7.x86_64
[root@bunian etc]# rpm -e --nodeps mysql-community-client-5.7.38-1.el7.x86_64
[root@bunian etc]# rpm -e --nodeps mysql80-community-release-el7-6.noarch
[root@bunian etc]# rpm -e --nodeps mysql-community-server-5.7.38-1.el7.x86_64
[root@bunian etc]# rpm -e --nodeps mysql-community-libs-5.7.38-1.el7.x86_64
# 清理yum headers cache
[root@bunian etc]# yum clean all
[root@bunian tmp]# rpm -ivh https://dev.mysql.com/get/mysql80-community-release-el7-6.noarch.rpm
[root@bunian tmp]# wget https://dev.mysql.com/get/mysql80-community-release-el7-6.noarch.rpm
[root@bunian tmp]# yum localinstall mysql80-community-release-el7-6.noarch.rpm
[root@bunian tmp]# yum repolist all | grep mysql
mysql-cluster-7.5-community/x86_64 MySQL Cluster 7.5 Comm 禁用
mysql-cluster-7.5-community-source MySQL Cluster 7.5 Comm 禁用
mysql-cluster-7.6-community/x86_64 MySQL Cluster 7.6 Comm 禁用
mysql-cluster-7.6-community-source MySQL Cluster 7.6 Comm 禁用
mysql-cluster-8.0-community/x86_64 MySQL Cluster 8.0 Comm 禁用
mysql-cluster-8.0-community-debuginfo/x86_64 MySQL Cluster 8.0 Comm 禁用
mysql-cluster-8.0-community-source MySQL Cluster 8.0 Comm 禁用
mysql-connectors-community/x86_64 MySQL Connectors Commu 启用: 192
mysql-connectors-community-debuginfo/x86_64 MySQL Connectors Commu 禁用
mysql-connectors-community-source MySQL Connectors Commu 禁用
mysql-tools-community/x86_64 MySQL Tools Community 启用: 90
mysql-tools-community-debuginfo/x86_64 MySQL Tools Community 禁用
mysql-tools-community-source MySQL Tools Community 禁用
mysql-tools-preview/x86_64 MySQL Tools Preview 禁用
mysql-tools-preview-source MySQL Tools Preview - 禁用
mysql57-community/x86_64 MySQL 5.7 Community Se 禁用
mysql57-community-source MySQL 5.7 Community Se 禁用
mysql80-community/x86_64 MySQL 8.0 Community Se 启用: 343
mysql80-community-debuginfo/x86_64 MySQL 8.0 Community Se 禁用
mysql80-community-source MySQL 8.0 Community Se 禁用
默认是开启8.0版本
这个地方容易出错,原因是没有去除校验导致服务安装后无法启动
#gpgcheck改成0
[root@bunian tmp]# vim /etc/yum.repos.d/mysql-community.repo
[mysql80-community]
name=MySQL 8.0 Community Server
baseurl=http://repo.mysql.com/yum/mysql-8.0-community/el/7/$basearch
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2022
file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
[root@bunian tmp]# yum install mysql-community-server
[root@bunian tmp]# vim /etc/my.cnf
[mysqld]
# 不区分大小写
lower_case_table_names=1
# 端口号
port = 3306
[root@bunian tmp]# systemctl start mysqld
初始密码在这里/var/log/mysqld.log
# 密码是:6;-#?gn*q;0H
[root@bunian etc]# grep 'temporary password' /var/log/mysqld.log
2022-06-21T03:25:39.021858Z 1 [Note] A temporary password is generated for root@localhost: 6;-#?gn*q;0H
[root@bunian etc]# mysql -h localhost -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 13
Server version: 5.7.38 MySQL Community Server (GPL)
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'newpasswd';
在 mysql 数据库的 user 表中查看当前 root 用户的相关信息
select host, user, authentication_string, plugin from user;
执行完上面的命令后会显示一个表格
查看表格中 root 用户的 host,默认应该显示的 localhost,只支持本地访问,不允许远程访问。
授权 root 用户的所有权限并设置远程访问
update user set host='%' where user='root';
GRANT ALL ON *.* TO 'root'@'%';
GRANT ALL ON *.* TO 'root'@'%';
执行两次 GRANT ALL ON . TO ‘root’@‘%’;
刷新权限
mysql> flush privileges;
# 查看mysql端口号
[root@bunian etc]# netstat -nltp | grep 3306
tcp6 0 0 :::33060 :::* LISTEN 1292/mysqld
tcp6 0 0 :::3306 :::* LISTEN 1292/mysqld
由于目前已有的客户端连接软件还不支持Mysql8新增加的加密方式: caching_sha2_password
所以我们需要修改用户的加密方式,将其改为老的加密验证方式: mysql_native_password
#登录
mysql -h localhost -p
#选择数据库
use mysql;
# 注意:先 select host, user from user; 查看host值再决定以下是'root'@'%' 还是 'root'@'localhost'
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '你的数据库密码';
#刷新权限
FLUSH PRIVILEGES;
连接Navicat创建test数据库、new表
vim /www/nginx/php/index.php
$servername = "localhost";
$username = "root";
$password = "password";
$dbname = "test";
// 创建连接
$conn = new mysqli($servername, $username, $password, $dbname);
// 检查连接
if ($conn->connect_error) {
die("连接失败: " . $conn->connect_error);
}
// 执行查询
$sql = "SELECT * FROM new";
$result = $conn->query($sql);
// 输出数据
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
echo "id: " . $row["id"]. " - name: " . $row["name"]. "
";
}
} else {
echo "0 结果";
}
//访问ip/index.php
id: 1 - name: 测试文章