每个项目应以.dev结尾。
不希望为每个项目创建一个支持数据库的构建版本。
我无法理解Puppet或Chef。我宁愿避免使用它们,但很乐意从repo克隆。
我需要一些建议或指引。
谢谢。
请查看下面的更新信息
我一直在寻找提高我的 Web 开发工作流程的方法。目前,我正在使用各种工具和应用程序,如 LAMP、Webmin 和 Filezilla 等来进行主题项目等工作。然后我发现了这个神奇的工具——Vagrant,在测试了它与我的项目之后,我爱上了它,并决定将其整合到当前的本地 Web 开发环境中。因此,我进一步挖掘并寻找可能性,以使用我选择的基础镜像 Ubuntu 12.04 Precise Pangolin 32-bit
来创建和设置一个使用Vagrant的多个虚拟主机设置。在 Google 上搜索返回了许多结果,但我决定单击来自 stackoverflow 的链接,并在此问题中得到解答。我遵循了 Dimitri Kouvdis
回答中提到的链接,这是一个 Github 仓库。我已经测试过了,并遇到了与 Dimitri Kouvdis
遇到的非常相似的问题。但现在已经解决了,感谢他的评论,我让它工作了。但是在寻找我的理想具有多个虚拟支持的 Vagrant Box的过程中,我从 Github 上搜索和测试了几个仓库,直到找到适合我的一个。之所以追寻这些仓库,是因为我还不知道如何使用 Puppet 和 Chef 来提供自己的 Dev 服务器。
onema / vagrant-lamp-development
https://github.com/onema/vagrant-lamp-development
在测试 Dimitri Kouvdis
提到的 Github 仓库时,我遇到了几个问题,并且在那段时间内停止了工作,决定从 Github 中寻找类似的仓库。我发现了几个并测试了其中一些,包括 Nino Paolo 的仓库(https://github.com/paolooo/vagrant-lamp)。我再次遇到了几个问题,尤其是在 vagrant up
期间。我决定再次寻找另一个,直到我找到并成功设置了 onema 的仓库。我最终决定使用并将这个解决方案整合到我的 Web 开发实践环境中。我开始爱上 onema
的仓库,因为;
正如我之前提到的那样,通过阅读并按照在其Github Repo页面上找到的说明进行设置(特别是对于新手和像我这样的自学者)非常容易。- https://github.com/onema/vagrant-lamp-development。您可以选择使用下载的zip文件或选择使用git clone https://github.com/onema/vagrant-lamp-development
将Vagrant
文件复制到本地驱动器。
git
and do the basic Vagrant and VirtualBox setup. Read instruction from the Github Page, plus do the below steps.With my setup, I've edited the Vagrantile
a bit. In line: 70
of the orig Vagranfle
file, I disabled NFS by putting a comment #
to
config.vm.synced_folder "~/Sites", "/vagrant", nfs: true
so, it now looks like this...
#config.vm.synced_folder "~/Sites", "/vagrant", nfs: true
and then commenting out...
#config.vm.synced_folder "~/Sites", "/vagrant"
line: 140
from the orig Vagrantfile
so, it now looks like this...
config.vm.synced_folder "~/Sites", "/vagrant"
I am doing this because in my machine, during vagrant up
, it throws several NFS related errors that I do not understand.
Now, for the sake of this example, and from the example from it's Repo Page, create a folder and you must name it Sites
. This should be located in your User Account's folder root or your Home Folder. /home/your-user-account-home-folder/Sites
In my case, (take note of that capital S)
/home/gary/Sites
A.
Create your sample dev-site/vhost and create a new folder named wordpress.dev
and make this as the document root of your vhost wordpress.dev
Then add your project files here. See example below;
/home/gary/Sites/wordpress.dev
B.
Now, reate a simple splash page for your newly created vhost so you can confirm that your configuration is redirecting you to the destination vhost root folder, when you visit the dev site from your browser. Of course, when your configurations are correct, you shall see the splash page. This is how I made my splash page.
I created an index.php
file and put some codes inside it,like so;
<?php echo "Success!!! Your wordpress.dev looks fine"; ?>
So when you successfully reached your vhost, you'll be greeted by the message Success!!! Your wordpress.dev looks fine
Now, add your Vagrant Box's IP Address to your hosts
file and mapping your dev site wordpress.dev
to it, like so;
192.168.50.4 wordpress.dev
Note: 192.168.50.4
is the default configured IP Address of the Vagrant Box, you may change this to your liking and update your hosts
file.
In my case, I put it like so,
A
10.10.10.10 wordpress.dev
- in my hosts file, while
Bconfig.vm.network "private_network", ip: "10.10.10.10"
in my Vagrantfile.
You can find this settings by looking inside your Vagrantfile
and navigating just below this line # Host-Only networking required for nfs shares
Then change the ip:
settings from there and update your hosts
file to match the IP.
Edit your Vagrantfile
again and add your vhost settings, to point to your dev site folder, add these code block like so;
:wordpress => {
:name => "wordpress",
:host => "wordpress.dev",
:aliases => ["wordpress.dev"],
:docroot => "/wordpress.dev"
}
When you added the code to the orig Vagrantfile
, it should look like this;
:vhost => {
:localhost => {
:name => "localhost",
:host => "localhost",
:aliases => ["localhost.web", "dev.localhost-static.web"],
:docroot => ""
},
:wordpress => {
:name => "wordpress",
:host => "wordpress.dev",
:aliases => ["wordpress.dev"],
:docroot => "/wordpress.dev"
}
So your Vagrantfile
shall now look like this one below; take note on the comma ,
right above the w
of the :wordpress
and right of closing curly brace }
.
There should be a comma in there, when you add another vhost, you should add another comma to the right of the closing curly brace }
of wordpress.
Vagrant.configure("2") do |config|
config.vm.box = "precise32"
config.vm.box_url = "http://files.vagrantup.com/precise32.box"
config.vm.host_name = "localhost"
config.vm.provision "chef_solo" do |chef|
chef.cookbooks_path = "cookbooks"
chef.add_recipe "vagrant_main"
#####################################
# MONGODB
# https://github.com/edelight/chef-cookbooks
#####################################
chef.add_recipe "mongodb::10gen_repo"
chef.add_recipe "mongodb::default"
#####################################
# REDIS
# https://github.com/phlipper/chef-redis
#####################################
chef.add_recipe "redis"
chef.json.merge!({
:mysql => {
:server_root_password => "root",
:server_debian_password => "root",
:server_repl_password => "root"
},
#####################################
# YOU WILL NEED TO ADD THESE DOMAINS
# TO THE LIST OF HOSTS IN YOUR LOCAL
# ENVIRONMENT FOR THESE TO BE PROPERLY
# ROUTED
#####################################
:vhost => {
:localhost => {
:name => "localhost",
:host => "localhost",
:aliases => ["localhost.web", "dev.localhost-static.web"],
:docroot => ""
},
:symfony => {
:name => "symfony",
:host => "symfony.web",
:aliases => ["symfony"],
:docroot => "/symfony/web"
},
:wordpress => {
:name => "wordpress",
:host => "wordpress.dev",
:aliases => ["wordpress"],
:docroot => "/wordpress.dev"
}
}
})
end
config.vm.network "forwarded_port", guest: 80, host: 8080
config.vm.network "forwarded_port", guest: 3306, host: 3307
##########################################################################
# UNCOMMENT IF NFS IS DISABLED
##########################################################################
config.vm.synced_folder "~/Sites", "/vagrant"
##########################################################################
# NFS
# Enable if you have performance issues with large projects.
# see the following links for more info:
# http://forum.symfony-project.org/viewtopic.php?t=52241&p=167041#p147056
# http://docs.vagrantup.com/v2/synced-folders/nfs.html
# http://www.phase2technology.com/blog/vagrant-and-nfs/
###########################################################################
# Host-Only networking required for nfs shares
config.vm.network "private_network", ip: "10.10.10.10"
#config.vm.synced_folder "~/Sites", "/vagrant", nfs: true
config.vm.provider :virtualbox do |vb|
# # Don't boot with headless mode
# vb.gui = true
#
# # Use VBoxManage to customize the VM. For example to change memory:
vb.customize ["modifyvm", :id, "--memory", "512"]
end
end
ctrl + alt + t
and type in cd vagrant-lamp-development
to change directory to vagrant-lamp-development
folder and type in vagrant up
To Add New Vhosts, just create a new folder inside /home/your-home-folder/Sites/new-project-folder
and then...
Repeat Steps 3B, 4A, 5
If you made the changes or the addition of Vhosts to your Vagrantfle
while the VM Box is Running, type..
vagrant provision
in your terminal to make the changes take effect.
If you made the changes or the addition of vhosts to your Vagrantfile
while the VM Box is OFF, type...
vagrant up --provision
in your terminal to make the changes take effect.
NOTE: The Vagrantfile
used in this guide will download a 64-bit Precise Pangolin Basebox Base Box
, you could change it to a 32-bit Precise Pangolin Basebox
by changing the config from the Vagrantfile
.
I did this in my case, because I already downloaded my 32-bit base box. So I changed it to 32-bit, so I don't have to download again.
Change...
Vagrant.configure("2") do |config|
config.vm.box = "precise64"
config.vm.box_url = "http://files.vagrantup.com/precise64.box"
To
Vagrant.configure("2") do |config|
config.vm.box = "precise32"
config.vm.box_url = "http://files.vagrantup.com/precise32.box"
以下是如何添加新的vhosts
Create a new .json
file matching your desired dev-site name, ex: wordpress.dev
in
vagrant-lamp/data_bags/sites
So it shall look like...
vagrant-lamp/data_bags/sites/wordpress.json
Edit the newly created file wordpress.json
and add the following (for example only);
{
"id": "wordpress",
"host": "wordpress.dev",
"aliases": [
"www.wordpress.dev"
]
}
Create a new folder named wordpress.dev
inside vagrant-lamp/public
So it will look like...
vagrant-lamp/public/wordpress.dev
Edit your hosts
file to add and map 192.168.33.10``wordpress.dev
So it shall look like this...
192.168.33.10 wordpress.dev
And you're good to go... Fire up vagrant and type vagrant up --provision
, if the box is turned off
If the box is turned on when you did the procedure, then type vagrant provision
instead.
After this, fire up your browser and test your config, browse to http://wordpress.dev
.
Make sure you put some index files in there.
各位,我的Linux Mint 13(基于Ubuntu 12.04)开发机坏了。这就是为什么我不得不重新安装我的操作系统(我的错...使用Fake RAID并且没有备份),但这一次,我使用了Linux Mint 17,它是基于Ubuntu 14.0.4 LTS的。
所以我从头开始重新安装了所有东西,并快速设置了我的Web开发环境。但结果发现,我的之前与vagrant配合使用的工作环境已经不再起作用了。因此,我搜索了如何设置另一个Web开发环境的解决方案,以使其能够与Ubuntu 14.04 LTS兼容。幸运的是,我找到了一个可行的解决方案,使用了另一个名为CPT Server
的Github存储库。
以下是设置步骤:
vagrant up
就是这样!第一次启动需要很长时间。
只需编辑config/config.yaml并转到文件的最底部。查找vhost:
行并像这样插入新的虚拟主机:
ServerName: mydevsite.dev
ServerAlias: mydevsite.dev
DocumentRoot: /var/www/mydevsite.dev
ServerAdmin: webmaster@localhost
接下来在 www
文件夹内创建一个新文件夹,并将其命名为与 ServerName 或 DocumentRoot 文件夹相匹配的名称 mydevsite.dev
如果在 Vagrant 运行时添加了一个新的主机,则执行以下操作:vagrant provision
如果在 Vagrant box 运行时修改了 config.yaml 的上部分,请执行以下操作:vagrant reload --provision
不要忘记更新主机机器的 hosts 文件,将您的虚拟主机指向 Vagrant 的 IP。
这就是全部内容。
你也可以使用这个:
https://github.com/paolooo/vagrant-lamp
你可以去看看。
https://github.com/fideloper/Vaprobash
观看 "Apache虚拟主机配置" 视频,快速学习创建虚拟主机的方法。
安装前别忘了取消注释你喜欢的数据库类型 :)
额外福利: 我能在几秒钟内通过Sequel Pro连接到唯一的vagrant设置的数据库
vagrant up
之前运行sudo launchctl load /Library/LaunchDaemons/org.virtualbox.startup.plist
。你的方法比我的复杂得多。我稍后会编辑我的帖子。 - Dimitri Kouvdisr8
存储库中遇到了几个问题。而在onema
存储库中则没有任何问题。使用onema
存储库添加额外的虚拟主机只需要编辑Vagrantfile
和hosts
文件即可。总之,我只是为了我的新手同伴们写了这篇文章。 - GaryPhttps://github.com/mitchellh/vagrant/issues/1673
。Mitchellh提到:“是的,这是一个已知的‘问题’。它并不是真正的问题,因为它并不会导致任何问题。实际上,这个错误消息出现的原因是Ubuntu中的一个bug,它没有检查stdin是否是TTY,而只是假设它是。” - GaryP