首页 新闻 搜索 专区 学院

vagrant 搭建PHP开发环境,可以转发apache端口,不可以转发mysql端口

0
悬赏园豆:20 [已解决问题] 解决于 2015-07-04 14:25

目前是Virtualbox+vagrant搭建php开发环境。目前装好了Apache + mysql + PHP了,可以转发80端口,但是mysql连接不上。

目前使用的

virtualbox: 4.3.12

vagrant: 1.7.2

OS: Ubuntu 12.04 LTS (GUN/Linux 3.2.0-23-generic-pae i686)

virtualbox 网络:

 

配置文件:

# -*- mode: ruby -*-
# vi: set ft=ruby :

# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure(2) do |config|
  # The most common configuration options are documented and commented below.
  # For a complete reference, please see the online documentation at
  # https://docs.vagrantup.com.

  # Every Vagrant development environment requires a box. You can search for
  # boxes at https://atlas.hashicorp.com/search.
  config.vm.box = "ubuntu"

  # Disable automatic box update checking. If you disable this, then
  # boxes will only be checked for updates when the user runs
  # `vagrant box outdated`. This is not recommended.
  # config.vm.box_check_update = false

  # Create a forwarded port mapping which allows access to a specific port
  # within the machine from a port on the host machine. In the example below,
  # accessing "localhost:8080" will access port 80 on the guest machine.
  config.vm.network "forwarded_port", guest: 80, host: 8080

  # Create a private network, which allows host-only access to the machine
  # using a specific IP.
  # config.vm.network "private_network", ip: "192.168.33.10"

  # Create a public network, which generally matched to bridged network.
  # Bridged networks make the machine appear as another physical device on
  # your network.
  # config.vm.network "public_network"

  # Share an additional folder to the guest VM. The first argument is
  # the path on the host to the actual folder. The second argument is
  # the path on the guest to mount the folder. And the optional third
  # argument is a set of non-required options.
  config.vm.synced_folder "D:/develop", "/var/www/html"

  # Provider-specific configuration so you can fine-tune various
  # backing providers for Vagrant. These expose provider-specific options.
  # Example for VirtualBox:
  #
  # config.vm.provider "virtualbox" do |vb|
  #   # Display the VirtualBox GUI when booting the machine
  #   vb.gui = true
  #
  #   # Customize the amount of memory on the VM:
  #   vb.memory = "1024"
  # end
  #
  # View the documentation for the provider you are using for more
  # information on available options.

  # Define a Vagrant Push strategy for pushing to Atlas. Other push strategies
  # such as FTP and Heroku are also available. See the documentation at
  # https://docs.vagrantup.com/v2/push/atlas.html for more information.
  # config.push.define "atlas" do |push|
  #   push.app = "YOUR_ATLAS_USERNAME/YOUR_APPLICATION_NAME"
  # end

  # Enable provisioning with a shell script. Additional provisioners such as
  # Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the
  # documentation for more information about their specific syntax and use.
  # config.vm.provision "shell", inline: <<-SHELL
  #   sudo apt-get update
  #   sudo apt-get install -y apache2
  # SHELL
end
config.vm.network  private_network 不能修改为192.168.1.xx,因为修改为192.168.1.xx的话,vagrant up就会启动失败。如果是192.168.33.10,启动成功了,但是我自己访问不到。
config.vm.network public_network 启用这个,可以生成192.168.1.120的IP,但是访问不到192.168.1.120:80

目前开启的是: config.vm.network forwarded_port,我可以通过localhost:8080访问到我的apache,但是在Navicat for mysql中,

尝试用端口转发的方式:出现如下错误



加入我直接连接:localhost:3306


,目前转了PHPmyadmin也是:

,查询不到数据,看不了表结构。
五毛钱的饼的主页 五毛钱的饼 | 菜鸟二级 | 园豆:317
提问于:2015-07-04 11:43
< >
分享
最佳答案
0

暂时不使用Navicate for mysql,暂时使用phpmyadmin操作数据库。

因为我 /etc/phpmyadmin/config-db.php 配置错误导致的,

<?php
##
## database access settings in php format
## automatically generated from /etc/dbconfig-common/phpmyadmin.conf
## by /usr/sbin/dbconfig-generate-include
## Sat, 04 Jul 2015 03:29:09 +0000
##
## by default this file is managed via ucf, so you shouldn't have to
## worry about manual changes being silently discarded.  *however*,
## you'll probably also want to edit the configuration file mentioned
## above too.
##
$dbuser='phpmyadmin';
$dbpass='wakasann';
$basepath='';
$dbname='phpmyadmin';
$dbserver='';
$dbport='';
$dbtype='mysql';

我改为

<?php
##
## database access settings in php format
## automatically generated from /etc/dbconfig-common/phpmyadmin.conf
## by /usr/sbin/dbconfig-generate-include
## Sat, 04 Jul 2015 03:29:09 +0000
##
## by default this file is managed via ucf, so you shouldn't have to
## worry about manual changes being silently discarded.  *however*,
## you'll probably also want to edit the configuration file mentioned
## above too.
##
$dbuser='root';
$dbpass='wakasann';
$basepath='';
$dbname='';
$dbserver='';
$dbport='';
$dbtype='mysql';

,我的PHPmyadmin就可以正常操作mysql了

顺利解决了。谢谢@dudu的帮忙

参考了:

 1. 使用配置文件中定义的控制用户连接失败 解决方法

 2. ubuntu: 缺少 mcrypt 扩展,请检查 php 配置

 3. Ubuntu下phpmyadmin出错,重装phpmyadmin步骤

 4. ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var mysql 启动不了

五毛钱的饼 | 菜鸟二级 |园豆:317 | 2015-07-04 14:17

navicate for mysql或者mysql workbench 都支持SSH 方式连接mysql数据库的

五毛钱的饼 | 园豆:317 (菜鸟二级) | 2015-12-23 18:15
其他回答(1)
0

建议先确认一下mysql的服务是否已启动

收获园豆:20
dudu | 园豆:36417 (高人七级) | 2015-07-04 11:58

mysql 已启动了,phpmyadmin可以连接进去

支持(0) 反对(0) 五毛钱的饼 | 园豆:317 (菜鸟二级) | 2015-07-04 12:02

@wakasann: phpmyadmin用的是哪个端口?

支持(0) 反对(0) dudu | 园豆:36417 (高人七级) | 2015-07-04 12:10

@dudu: 3306,已解决了,我就用phpmyadmin操作数据库,是phpmyadmin配置没配置好

支持(0) 反对(0) 五毛钱的饼 | 园豆:317 (菜鸟二级) | 2015-07-04 14:10
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册