简体   繁体   English

更改默认的xampp htdocs位置会导致“数据库错误”(Mac OSX)

[英]Changing default xampp htdocs location results in 'Database Error' (Mac OSX)

I'm trying to set up my Xampp htdocs location to a Google Drive folder so that I can work on my wordpress site from any location and also sharing it with my PC-laptop. 我正在尝试将Xampp htdocs位置设置为Google云端硬盘文件夹,以便可以从任何位置在wordpress网站上工作,并与我的PC笔记本电脑共享。

Following along some tips & tutorials (such as: how to change xampp htdocs directory in OSX? ) I now can access my localhost. 遵循一些提示和教程(例如: 如何在OSX中更改xampp htdocs目录? ),我现在可以访问我的本地主机。 However, browsing to my wordpress site located in localhost/testsite/ results in: 但是,浏览到位于localhost / testsite /的wordpress网站会导致:

'Error establishing a database connection" '建立数据库连接时出错”

Any suggestions what can be wrong? 有什么建议可能会出错吗? Is it no possible to share htdocs-folder between PC & MAC? 是否无法在PC和MAC之间共享htdocs文件夹?

my vhost.conf looks like (unchanged): 我的vhost.conf看起来像(不变):

<VirtualHost *:80>
    ServerAdmin webmaster@dummy-host.example.com
    DocumentRoot "/Applications/XAMPP/xamppfiles/docs/dummy-host.example.com"
    ServerName dummy-host.example.com
    ServerAlias www.dummy-host.example.com
    ErrorLog "logs/dummy-host.example.com-error_log"
    CustomLog "logs/dummy-host.example.com-access_log" common
</VirtualHost>

<VirtualHost *:80>
    ServerAdmin webmaster@dummy-host2.example.com
    DocumentRoot "/Applications/XAMPP/xamppfiles/docs/dummy-host2.example.com"
    ServerName dummy-host2.example.com
    ErrorLog "logs/dummy-host2.example.com-error_log"
    CustomLog "logs/dummy-host2.example.com-access_log" common
</VirtualHost>

And the changes made to http.conf 以及对http.conf所做的更改

DocumentRoot "/Users/username/Google Drive/htdocs"
<Directory "/Users/username/Google Drive/htdocs">

.. ..

# User/Group: The name (or #number) of the user/group to run httpd as.
# It is usually good practice to create a dedicated user and group for
# running httpd, as with most system services.
#
User username

UPDATE : 更新

I've tried to make some changes to my wp-config.php file accordingly to some threads on this problem. 我试图对我的wp-config.php文件进行一些更改,以适应此问题的一些线程。

/** MySQL database username */
define('DB_USER', ''); 

/** MySQL hostname */
define('DB_HOST', '127.0.0.1'); 

Changes - Removed root from DB_USER - Tried changing DB_HOST to both Localhost (notice capital L) and 127.0.0.1. 更改-从DB_USER删除了根目录-尝试将DB_HOST更改为Localhost(注意大写L)和127.0.0.1。 This makes the wp-config-file compatible with PC but just wanted to troubleshoot. 这使得wp-config-file与PC兼容,但只想进行故障排除。

Localhost throws parse error and 127.0.0.1 results in "Error establishing a database connection" Localhost引发解析错误,并且127.0.0.1导致“建立数据库连接时出错”

try accessing http://localhost/phpmyadmin and checking the credentials. 尝试访问http:// localhost / phpmyadmin并检查凭据。 Usually user is root and no password by default. 通常,用户是root,默认情况下没有密码。 Also, don't forget to create a database for wordpress if you haven't done so already. 另外,如果您还没有为wordpress创建数据库,请不要忘记这样做。 So your wp-config.php should contain something like this: 因此,您的wp-config.php应该包含以下内容:

define('DB_NAME', 'wordpress');
define('DB_USER', 'root');
define('DB_PASSWORD', '');
define('DB_HOST', 'localhost');

Architecturally, Google Drive was not designed for what you are trying to do. 从结构上讲,Google云端硬盘并非针对您要尝试的功能而设计。 You may hack something together and get it working, but there are much better solutions. 您可能会一起破解某些东西并使它正常工作,但是有更好的解决方案。

  • VVV is a good solution for creating a local development server. VVV是创建本地开发服务器的良好解决方案。 It builds a box you control via the command line and can access through a browser anywhere on your LAN. 它构建了一个可以通过命令行控制的框,并且可以通过局域网上任何位置的浏览器进行访问。 You can a git based deployment strategy and have this box wherever you need it. 您可以基于git的部署策略,并在需要的地方使用此框。
  • An even better solution is using Trellis , part of the Roots.io ecosystem. 更好的解决方案是使用Rolls.io生态系统的一部分Trellis It uses Ansible to provision a ready-to-go vagrant instance and you can even deploy the entire server onto a bare-metal instance (like AWS or Digital Ocean). 它使用Ansible来准备一个随时可用的无所事事的实例,您甚至可以将整个服务器部署到一个裸机实例(如AWS或Digital Ocean)上。 I have used this with great success, but you have to get more into the dev ops. 我已经成功地使用了它,但是您必须更多地参与开发操作。
  • For cross-browser testing, I would recommend using browsersync as part of a gulp build process. 对于跨浏览器测试,我建议在gulp构建过程中使用browsersync You'd run gulp serve locally and, if you have browsersync as part of your build script, it will watch your codebase, automatically make updates for you in the browser and allow you to remotely access your local dev box for cross-browser testing. 您将在本地运行gulp serve ,如果您在构建脚本中使用了browsersync,它将监视您的代码库,并在浏览器中自动为您进行更新,并允许您远程访问本地dev框以进行跨浏览器测试。

Alright, solution to this is far from revolutionary. 好吧,解决这个问题远非革命性的。 Of course its not only the htdocs-folder that has to be synced between the PC and MAC but also the MySQL data folder. 当然,不仅要在PC和MAC之间同步htdocs文件夹,还要同步MySQL数据文件夹。

Exporting the database from phpmyadmin on the PC and importing it into my Xampp setup on Mac solve this problem with "Error establishing a database connection" message. 从PC上的phpmyadmin导出数据库并将其导入到Mac上的Xampp设置中,将出现“建立数据库连接错误”消息,从而解决了此问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM