0
我已經使用vagrant按照these說明設置了開發環境。動態重定向文件夾到流浪者vm上的子域
這會將我的主文件夾'./'(192.168.22.33/projectname/...或user/myname/sites/mysite)同步到虛擬機上的虛假來賓文件夾:「/ var/www/html」
它可以很好地作爲指定文件夾(例如mysite)的LAMP堆棧,但我希望允許每個文件夾作爲子域進行訪問,例如對於foldername.ip.xip.io映射到IP/FOLDERNAME
我希望能夠創建中的網站「的新文件夾,然後通過去訪問它們:
mysite.local.dev or mysite.192.168.22.33 accessing /user/myname/sites/mysite
mysite2.local.dev or mysite2.192.168.22.33 accessing the mysite2 folder.
- 我嘗試過使用
.htaccess
,這很有效,但我希望它是 隱形,我明白這不是最佳做法。 - 我試着玩弄文檔根。
- 我試過編輯
vhosts
在我的install.sh
文件和啓用vhost_alias
- 但我無法讓它工作。 - 我只能爲指定的文件夾做例如在我的流浪文件中列出了一些ips。我不想這樣做,因爲我想設置虛擬機,以便如果我創建一個新文件夾(例如通過拉一個git倉庫)它可以自動工作,而不必每次創建新的子域時都需要重新設置vagrant 。
我認爲虛擬主機必須是正確的方式來做到這一點,但我不能得到它的工作 - 我在下面錯過了什麼?
謝謝!
我vagrantfile包含:
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "precise32"
config.vm.box_url = "http://files.vagrantup.com/precise32.box"
config.vm.network :forwarded_port, guest: 80, host: 8080
config.vm.network :forwarded_port, guest: 443, host: 8443
config.vm.provision :shell, :path => "install.sh"
config.vm.synced_folder ".", "/vagrant", :mount_options => ["dmode=777", "fmode=666"]
#config.vm.synced_folder ".", "/var/www", :mount_options => ["dmode=777", "fmode=666"]
# If true, then any SSH connections made will enable agent forwarding.
# Default value: false
# config.ssh.forward_agent = true
# 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 "./myproject", "/var/www/html"
end
我install.sh文件包含:
#!/usr/bin/env bash
echo "--- Installing now. ---"
echo "--- Fixing the TTY STDIN error ---"
sed -i 's/^mesg n$/tty -s \&\& mesg n/g' /root/.profile
echo "--- Updating packages list ---"
sudo apt-get update
echo "--- MySQL time ---"
sudo debconf-set-selections <<< 'mysql-server mysql-server/root_password password root'
sudo debconf-set-selections <<< 'mysql-server mysql-server/root_password_again password root'
echo "--- Installing base packages ---"
sudo apt-get install -y vim curl python-software-properties
echo "--- Installing PHP5 ---"
sudo add-apt-repository -y ppa:ondrej/php5
echo "--- Updating packages list ---"
sudo apt-get update
echo "--- Installing PHP-specific packages ---"
sudo apt-get install -y php5 apache2 libapache2-mod-php5 php5-curl php5-gd php5-mcrypt mysql-server-5.5 php5-mysql git-core
echo "--- Installing and configuring Xdebug ---"
sudo apt-get install -y php5-xdebug
cat << EOF | sudo tee -a /etc/php5/mods-available/xdebug.ini
xdebug.scream=1
xdebug.cli_color=1
xdebug.show_local_vars=1
EOF
# echo "--- Configuring Hosts ---"
# sudo a2enmod vhost_alias
# # setup hosts file
# VHOST=$(cat <<EOF
# <VirtualHost *:80>
# ServerName vhosts.fqdn
# ServerAlias *.local.dev
# VirtualDocumentRoot /var/www/%1+
# </VirtualHost>
# EOF
#)
# echo "${VHOST}" > /etc/apache2/sites-available/000-default.conf
echo "--- Enabling mod-rewrite ---"
sudo a2enmod rewrite
echo "--- Setting document root ---"
#sudo mkdir "/var/www"
sudo rm -rf /var/www/html
sudo ln -fs /vagrant/public/ /var/www/html
#sed -i "s#DocumentRoot /var/www/html#DocumentRoot /var/www#g" /etc/apache2/sites-available/000-default.conf
echo "--- Turn errors on ---"
sed -i "s/error_reporting = .*/error_reporting = E_ALL/" /etc/php5/apache2/php.ini
sed -i "s/display_errors = .*/display_errors = On/" /etc/php5/apache2/php.ini
sed -i 's/AllowOverride None/AllowOverride All/' /etc/apache2/apache2.conf
echo "--- Set php short open tags to on. ---"
sed -i "s/short_open_tag = .*/short_open_tag = On/" /etc/php5/apache2/php.ini
echo "--- Restarting Apache ---"
sudo service apache2 restart
echo "--- Set up composer ---"
curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer
# Framework stuff here
echo "--- All set to go! ---"