doupapin172773 2013-03-19 17:12
浏览 84
已采纳

从Vagrant中的Chef Recipe运行PHP脚本时,MySQL无法正常工作

I've got a custom virtual machine base box that has PHP, Apache2 and MySQL pre-installed. So I can just boot up the virtual machine using this box and it wont need to install any of the above from Chef Cookbooks.

However, there is one Chef Cookbook I'm trying to install, but it's failing. The Cookbook I'm trying to install runs a PHP script, which connects and uses a MySQL db.

The reason it fails is because PHP cannot connect to the mysql server. I think it's because MySQL isn't started (or ready) at the time the script tries to connect. It only fails when I boot the VM. When I provision it (vagrant provision), it works. So that's why I think MySQL isn't ready to go when the PHP script attempts to connect.

The errors:

mysql_connect(): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) in .....

And the code in the Chef Cookbook Recipe:

execute "doInstall" do
  cwd "/vagrant"
  command "php path/to/my/script.php"
end

Any ideas?

  • 写回答

1条回答 默认 最新

  • douliao7930 2013-03-19 17:27
    关注

    Maybe you can do a

    service "mysql" do
      action :start, :immediately
    end
    

    at the beginning of your recipe or simply do a heuristical

    execute "doInstall" do
      cwd "/vagrant"
      command "sleep 10; php path/to/my/script.php"
    end
    

    which seems a bit dirty to me but might solve your issue quickly.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 matlab求解平差
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办
  • ¥15 vue2登录调用后端接口如何实现
  • ¥85 永磁型步进电机PID算法