Can’t reach wordpress on vagrant

I’m using Vagrant to setup a VM with a LAMP stack and WordPress on top, but I can’t access the WordPress website from the host machine on http://localhost:8000. I can access HTML files i put in /var/www. Am I missing something?

Vagrantfile

Read More
# -*- 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 .

Edit:

curl -v http://localhost:8000outputs the following:

* 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

Related posts

1 comment

  1. The problem is your website is sending back a redirect, back to the default port 80. see the curl output line:

    Location: http://localhost/
    

    If you dont have a webserver on localhost, you can use a transparent localhost port 80 to VM port 80 mapping. Or configure something in apache or wordpress to use port 8000 and make that the transparent port.

Comments are closed.