ubuntu20(root)+PHP+nginx+mysql
nginx【较新版】
wget http://nginx.org/keys/nginx_signing.keyapt-key add nginx_signing.keylsb_release -avi /etc/apt/sources.list# lsb_release -a 返回的Ubuntu系统版本编码(英文) 添加到sources.list中。【focal为Ubuntu20.04对应版本编码】deb http://nginx.org/packages/ubuntu/ focal nginxdeb-src http://nginx.org/packages/ubuntu/ focal nginx# 保存sources.list退出:wq# 安装nginxapt updateapt -y install nginxsystemctl enable/disable/status/start/stop/restart nginx# 查看Nginx版本nginx -v1.22.0
PHP7.4【修改数字即可安装不同版本】
# 彻底卸载apt安装的PHPaptitude purge `dpkg -l | grep php| awk '{print $2}' |tr "\n" " "` apt -y install software-properties-commonadd-apt-repository ppa:ondrej/phpapt updateapt -y install php7.4 php7.4-fpm# 安装PHP扩展,php7.4-dev用于后面pecl安装扩展时自动编译(支持命令:phpize)apt -y install php7.4-mcrypt php7.4-mbstring php7.4-curl php7.4-cli php7.4-mysql php7.4-gd php7.4-intl php7.4-xsl php7.4-zip php7.4-dev php7.4-xml php7.4-soapsystemctl enable/disable/status/start/stop/restart php7.4-fpm# 查询PHP版本php -v7.4.22
mysql8
apt install -y mysql-server
mysql8设置root密码
第一步:mysql8默认安装完成后,root账户没有密码,直接执行命令“mysql”即可登录。
第二步:还原密码设置。
update mysql.user set authentication_string='' where user='root';update mysql.user set plugin='mysql_native_password' where user='root';FLUSH PRIVILEGES;
第三步:通过mysql提供的脚本来设置密码。
MySQL安装随附一个名为的脚本mysql_secure_installation。可以借助它设置我们MYSQL服务器的安全性!
mysql_secure_installation
按提示执行即可。最后出现“All done!”说明脚本执行完成。直接使用新设置密码登录即可。
整合PHP+nginx
find / -name www.confvi /etc/php/7.4/fpm/pool.d/www.conf# 设置php-fpm通过监听端口方式工作;listen = /run/php/php7.4-fpm.socklisten = 127.0.0.1:9000
nginx配置文件路径
ps -ef|grep nginx# nginx配置文件地址root 498847 1 0 00:42 ? 00:00:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.confvi /etc/nginx/nginx.conf# 自定义配置文件位置include /etc/nginx/conf.dclass Test { protected $DB_SQLSERVER = array( 'db_type' => 'sqlsrv', 'db_user' => 'user', 'db_pwd' => "password", 'db_host' => '127.0.0.1', 'db_port' => '1433', 'db_name' => 'dbname', 'db_charset' => 'UTF8', ); public function test(){ $sql='select * from table_name where id =1'; dump($this->querySql($sql)); } protected $sqlsrvConn = null; protected function sqlsrvConn(){ $dbServerName = $this->DB_SQLSERVER['db_host'] . "," . $this->DB_SQLSERVER['db_port']; $connInfo = array(); $connInfo['UID'] = $this->DB_SQLSERVER['db_user']; $connInfo['PWD'] = $this->DB_SQLSERVER['db_pwd']; $connInfo['Database'] = $this->DB_SQLSERVER['db_name']; $connInfo['Encrypt'] = 'no'; // 不使用SSL加密 $this->sqlsrvConn = sqlsrv_connect($dbServerName,$connInfo); if($this->sqlsrvConn === false){ $this->ajaxReturn(genInfoTip(CODE_FAIL, "sqlserver数据库连接失败:".sqlsrv_errors())); } } public function querySql($sql){ if(empty($sql)){ return genInfoTip(CODE_FAIL, "sql不能为空"); } $this->sqlsrvConn(); $queryRet = sqlsrv_query($this->sqlsrvConn, $sql); if($queryRet === false){ $this->ajaxReturn(genInfoTip(CODE_FAIL, "sqlserver数据库查询异常:".sqlsrv_errors())); } $result = array(); while(($row = sqlsrv_fetch_array($queryRet))){ $result[] = $row; } return $result; } public function execSql($sql){ if(empty($sql)){ return genInfoTip(CODE_FAIL, "sql不能为空"); } $this->sqlsrvConn(); $exec = sqlsrv_query($this->sqlsrvConn, $sql); if($exec === false){ $this->ajaxReturn(genInfoTip(CODE_FAIL, "sqlserver数据库sql操作异常:".sqlsrv_errors())); } $num=sqlsrv_rows_affected($exec);//返回修改的行数 return $num; }
问题
报错:SQLSTATE[08001]: [Microsoft][ODBC Driver 18 for SQL Server]SSL Provider: [error:0A000086:SSL routines::certificate verify failed:self-signed certificate]
看到报错SSL,又是verify failed。怀疑是http传输加密,导致验证失败。
考虑是否可以取消SSL加密。
查询官网(使用连接字符串关键字 - SQL Server Native Client | Microsoft Learn)
发现有个字段和加密相关:Encrypt
然后直接sqlcmd测试(sqlcmd使用方式参考:使用 sqlcmd 进行连接 - ODBC Driver for SQL Server | Microsoft Learn):
测试 -N 参数:
最后,发现ThinkPHP3.2中并不支持此参数。故上文Test.class.php中采用直连方式 配置此参数,最终连接成功!
来源地址:https://blog.csdn.net/pjz161026/article/details/127399345