Loading... ## nginx ### 下载安装 [https://nginx.org/download](https://nginx.org/download) ```bash 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 ``` ### 启动 ```bash /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文件 #### 建立软链接 建立软链接目的是省去根目录快捷操作nginx ```bash [root@xxx opt]# ln -s /www/nginx/sbin/nginx /usr/sbin/ [root@xxx opt]# nginx -v nginx version: nginx/1.25.3 # 删除软连接 rm -rf /usr/sbin/nginx ``` ### 安装启动好php-fpm后,修改nginx.conf并重启nginx 把 **/scripts$fastcgi_script_name** 改成 **$document_root$fastcgi_script_name** ```bash 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; } ``` 重启nginx ```bash nginx -t nginx -s reload ``` > PS:如果还报错 [error] 37432#0: *85 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream 那一定是php文件路径不对 ## php ### yum方式安装 [用yum方式安装php最新版](https://blog.58heshihu.com/index.php/archives/1793/) #### 1 安装 epel-release源和 源管理工具yum-utils ```bash yum -y install epel-release yum-utils ``` #### 2 安装Remi软件源 Remi软件源官方地址: [https://rpms.remirepo.net/](https://rpms.remirepo.net/) ##### CentOS7安装: ```bash yum -y install https://rpms.remirepo.net/enterprise/remi-release-7.rpm ``` ##### CentOS7启动php模块并安装: yum启动php模块,根据需要选择自己格式的版本,如remi-php74模块,就是php7.4版本。: ```bash yum-config-manager --enable remi-php80 #启用remi源的php8.0模块 ``` > 注:如果显示没有这个命令,则需要先安装yum -y install yum-utils 插件。 ##### 安装php及相关扩展: ```bash 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版本 #### 3 启动php-fpm ```bash [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 ``` ## mysql [yum安装mysql](https://cloud.tencent.com/developer/article/2147473?from=15425) [MySQL三种安装方法(yum安装、编译安装、二进制安装)](https://blog.csdn.net/m0_62396418/article/details/133754221) ### yum安装mysql #### 1.卸载旧版mysql 如果安装过先卸载,第一次安装略过此步 ```bash [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 ``` #### 2.安装 ##### 2.1 rpm安装yum源 ```bash [root@bunian tmp]# rpm -ivh https://dev.mysql.com/get/mysql80-community-release-el7-6.noarch.rpm ``` ##### 2.2 下载rpm源文件再安装 ```bash [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 ``` #### 3.选择mysql版本 ```bash [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版本 #### 4.去除公钥检索校验 (最重要的地方) 这个地方容易出错,原因是没有去除校验导致服务安装后无法启动 ```bash #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 ``` #### 5.安装mysql ```bash [root@bunian tmp]# yum install mysql-community-server ``` #### 6.配置mysql ```bash [root@bunian tmp]# vim /etc/my.cnf [mysqld] # 不区分大小写 lower_case_table_names=1 # 端口号 port = 3306 ``` [lower_case_table_names](https://blog.58heshihu.com/index.php/archives/1884/) #### 7.启动mysql ```bash [root@bunian tmp]# systemctl start mysqld ``` #### 8.修改mysql root密码及外网访问 初始密码在这里/var/log/mysqld.log ```bash # 密码是: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 ``` ##### 登录mysql修改密码 ```bash [root@bunian etc]# mysql -h localhost -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 11 Server version: 8.0.35 Copyright (c) 2000, 2023, Oracle and/or its affiliates. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'newpasswd'; 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 数据库的 user 表中查看当前 root 用户的相关信息** ```mysql select host, user, authentication_string, plugin from user; ``` 执行完上面的命令后会显示一个表格 查看表格中 root 用户的 host,默认应该显示的 localhost,只支持本地访问,不允许远程访问。 **授权 root 用户的所有权限并设置远程访问** ```mysql update user set host='%' where user='root'; GRANT ALL ON *.* TO 'root'@'%'; GRANT ALL ON *.* TO 'root'@'%'; ``` > 执行两次 GRANT ALL ON *.* TO 'root'@'%'; **刷新权限** ```mysql mysql> flush privileges; ``` #### 9.检验是否安装成功 ```bash # 查看mysql端口号 [root@bunian etc]# netstat -nltp | grep 3306 tcp6 0 0 :::33060 :::* LISTEN 1292/mysqld tcp6 0 0 :::3306 :::* LISTEN 1292/mysqld ``` #### 10.Navicat连接 ##### 用Navicat连接报错:2059 - Authentication plugin 'caching_sha2_password' cannot be loaded ##### 原因以及解决办法 由于目前已有的客户端连接软件还不支持Mysql8新增加的加密方式: **caching_sha2_password** 所以我们需要修改用户的加密方式,将其改为老的加密验证方式: **mysql_native_password** ```mysql #登录 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; ``` #### 11.php连接mysql 连接Navicat创建test数据库、new表 vim /www/nginx/php/index.php ```php <?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"]. "<br>"; } } else { echo "0 结果"; } //访问ip/index.php id: 1 - name: 测试文章 ``` 最后修改:2023 年 11 月 28 日 © 允许规范转载 赞 如果觉得我的文章对你有用,请随意赞赏