我正在使用Vagrant设置一个带有LAMP堆栈和Wordpress的VM,但我无法通过http://localhost:8000
上的主机访问Wordpress网站。我可以访问/var/www
中放入的HTML文件。我错过了什么吗?
Vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure(2) do |config|
config.vm.box = "ubuntu/trusty64"
config.vm.network "forwarded_port", guest: 80, host: 8000, auto_correct: true
config.vm.network "forwarded_port", guest: 443, host: 44300, auto_correct: true
config.vm.network "forwarded_port", guest: 3306, host: 33060, auto_correct: true
config.vm.provision :shell, path: "bootstrap.sh"
end
bootstrap.sh
#!/usr/bin/env bash
echo -e "\n--- Starting VM bootstrapping... ---\n"
echo -e "\n--- Add repos ---\n"
add-apt-repository ppa:ondrej/apache2 > /dev/null 2>&1
add-apt-repository ppa:ondrej/php5-5.6 > /dev/null 2>&1
sudo add-apt-repository ppa:ondrej/mysql-5.6 > /dev/null 2>&1
echo -e "\n--- Update ---\n"
apt-get -qq update
echo -e "\n--- Installing Apache, PHP and PHP specific packages --- \n"
apt-get -y install apache2 php5 php5-curl php5-mcrypt php5-mysql php5-xdebug > /dev/null 2>&1
echo -e "\n--- Install MySQL Server ---\n"
apt-get -y install debconf-utils > /dev/null 2>&1
debconf-set-selections <<< "mysql-server mysql-server/root_password password root"
debconf-set-selections <<< "mysql-server mysql-server/root_password_again password root"
apt-get -y install mysql-server > /dev/null 2>&1
echo -e "\n--- Enable mod-rewrite ---\n"
a2enmod rewrite
echo -e "\n--- Create Virtual Host ---\n"
cat > "/etc/apache2/sites-available/000-default.conf" << EOF
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName localhost
DocumentRoot /var/www
<Directory /var/www>
Options -Indexes +FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
EOF
echo -e "\n--- Change apache user to vagrant user ---\n"
sed -i 's/APACHE_RUN_USER=www-data/APACHE_RUN_USER=vagrant/' /etc/apache2/envvars
sed -i 's/APACHE_RUN_GROUP=www-data/APACHE_RUN_GROUP=vagrant/' /etc/apache2/envvars
echo -e "\n--- Restarting Apache ---\n"
service apache2 restart
# Other packages
echo -e "\n--- Install other useful packages ---\n"
apt-get -y install git > /dev/null 2>&1
# ENV Setup stops here, APP setup starts.
echo -e "\n--- Starting App bootstraping... ---\n"
rm -rf /var/www/*
cd /var/www
echo -e "\n--- Install Composer for PHP package management ---\n"
curl --silent https://getcomposer.org/installer | php > /dev/null 2>&1
mv composer.phar /usr/local/bin/composer
echo -e "\n--- Install WP-CLI ---\n"
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar > /dev/null 2>&1
chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp
echo -e "\n--- Install WP ---\n"
wp core download --allow-root
wp core config --dbuser=root --dbpass=root --dbname=mkp --allow-root
wp db create --allow-root
wp core install --url=localhost --title=Example --admin_user=admin --admin_password=root --admin_email=john@example.com --allow-root
echo -e "\n--- Symlink to /vagrant folder ---\n"
sudo ln -fs /vagrant /var/www/wp-content/themes/mytheme
#cd /vagrant
#
echo -e "\n--- Changing permissions and ownership where needed ---\n"
sudo chmod 777 -R .
sudo chown -R $USER:$USER .
修改
curl -v http://localhost:8000
输出以下内容:
* Rebuilt URL to: http://localhost:8000/
* Adding handle: conn: 0x22853e0
* Adding handle: send: 0
* Adding handle: recv: 0
* Curl_addHandleToPipeline: length: 1
* - Conn 0 (0x22853e0) send_pipe: 1, recv_pipe: 0
* About to connect() to localhost port 8000 (#0)
* Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 8000 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.33.0
> Host: localhost:8000
> Accept: */*
>
< HTTP/1.1 301 Moved Permanently
< Date: Wed, 15 Jul 2015 13:06:15 GMT
* Server Apache/2.4.12 (Ubuntu) is not blacklisted
< Server: Apache/2.4.12 (Ubuntu)
< X-Pingback: http://localhost/xmlrpc.php
< Location: http://localhost/
< Content-Length: 0
< Content-Type: text/html; charset=UTF-8
<
* Connection #0 to host localhost left intact
答案 0 :(得分:0)
问题是您的网站正在发送重定向,返回默认端口80.请参阅curl输出行:
Location: http://localhost/
如果您在localhost上没有Web服务器,则可以使用透明的localhost端口80到VM端口80映射。或者在apache或wordpress中配置一些东西以使用端口8000并使其成为透明端口。