[英]Setting up MySQL on a Google Cloud Compute Engine VM instance
I've been moving my site from GoDaddy to Google Cloud and I'm very close to being able to launch.我一直在将我的网站从 GoDaddy 转移到 Google Cloud,而且我非常接近能够启动。 The only missing piece is setting up the database.
唯一缺少的部分是设置数据库。
I've already installed MySQL on the server and when I run sudo service mysql status
, it says that mariadb.service
is active (running) and "Taking your SQL requests now..."我已经在服务器上安装了 MySQL,当我运行
sudo service mysql status
,它说mariadb.service
处于活动状态(正在运行)和“现在接受你的 SQL 请求......”
I also added the VM instance's IP address to the SQL instance's Connections.我还将 VM 实例的 IP 地址添加到 SQL 实例的连接中。
However, when I try to connect on the live site, I get a php error that reads:但是,当我尝试在实时站点上进行连接时,出现一个 php 错误,内容为:
PHP Fatal error: Uncaught Error: Class 'mysql' not found in db.php:3
PHP 致命错误:未捕获的错误:在 db.php:3 中找不到类“mysql”
Am I missing a setup step?我是否缺少设置步骤? I followed all of Google's tutorials and help files about this and don't understand what I'm missing.
我遵循了 Google 的所有教程和关于此的帮助文件,但不明白我错过了什么。
I installed the libraries with these commands:我使用以下命令安装了库:
sudo apt-get update
sudo apt-get install apache2 php libapache2-mod-php
sudo apt-get install mysql-server
sudo apt-get install mysql-client
I'm trying to connect with this string in my php code:我试图在我的 php 代码中连接这个字符串:
$dbcon=@new mysql('[SQL instance IP address]','[DB username]','[DB password]','[DB name]');
To solve this problem, do three things:要解决这个问题,要做三件事:
1) Install the PHP MySQL Extensions: 1) 安装 PHP MySQL 扩展:
sudo apt-get install php7.0-mysqlnd
2) Make sure that the extension is enabled in your php.ini
file. 2) 确保在
php.ini
文件中启用了扩展。 There will be one for the PHP interpreter and another one for the Apache web server.将有一个用于 PHP 解释器,另一个用于 Apache Web 服务器。
3) Change your code to not use the mysql
class and use mysqli
instead: 3) 将代码更改为不使用
mysql
类,而是使用mysqli
:
$dbcon = new mysqli('localhost', $db_username, $db_password, $db_name);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.