Wordpress installation inside Vagrant box keeps redirecting back to http://localhost

89 views
Skip to first unread message

Jimbo Jones

unread,
Jan 13, 2016, 5:46:21 AM1/13/16
to Vagrant

I am having a strange issue at the moment where when I browse to a port-forwarded URI (in this case http://localhost:9001) of a Vagrant box in my browser I get redirected back to localhost (default server). I'm not sure why this is happening and it's really frustrating.

On my guest machine I have the root folder hosted in /var/www/wordpress and this is my /nginx/sites-available/nginx_vhost file:

server {
    listen 80;
    listen [::]:80 ipv6only=on;

    root /var/www/wordpress;
    index index.php index.html index.htm;

    server_name localhost;

    location / {
            # try_files $uri $uri/ =404;
            try_files $uri $uri/ /index.php?q=$uri&$args;
    }

    error_page 404 /404.html;

    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
            root /usr/share/nginx/html;
    }

    location ~* \.php$ {
            try_files $uri =404;
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_pass unix:/var/run/php5-fpm.sock;
            fastcgi_index index.php;
            include fastcgi_params;
            #fastcgi_read_timeout 300;
            #proxy_read_timeout 300;
    }

}

Here is my Vagrant file:

Vagrant.configure("2") do |config|

# Set Vagrant box to use
config.vm.box = "ubuntu/trusty64"

# Configure port forwarding
config.vm.network :forwarded_port, guest: 80, host: 9001, auto_correct: true

# Set synched folder
config.vm.synced_folder "./", "/var/www/wordpress", create: true, group: "www-data", owner: "www-data"

# Configure the VM
config.vm.provider "virtualbox" do |v|
    v.name = "Pet Vets Vagrant Box"
    v.customize ["modifyvm", :id, "--memory", "1024"]
end

# Set up shell provisioning
config.vm.provision :shell, :path => "bootstrap.sh"

end

And my bootstrap.sh file:

#!/bin/bash

echo "Provisioning virtual machine..."
apt-get update

echo "Installing Tree..."
apt-get install tree

echo "Installing Git"
apt-get install git -y > /dev/null

echo "Installing Nginx"
apt-get install nginx -y >/dev/null

echo "Configuring Nginx"
cp /var/www/wordpress/nginx_vhost /etc/nginx/sites-available/nginx_vhost > /dev/null

ln -s /etc/nginx/sites-available/nginx_vhost /etc/nginx/sites-enabled/nginx_vhost

rm /etc/nginx/sites-available/default

service nginx restart > /dev/null

echo "Updating PHP repository"
apt-get install python-software-properties build-essential -y > /dev/null
add-apt-repository ppa:ondrej/php5 -y > /dev/null
apt-get update > /dev/null

echo "Installing PHP"
apt-get install php5-common php5-dev php5-cli php5-fpm libssh2-php -y > /dev/null

echo "Installing PHP extensions"
apt-get install curl php5-curl php5-gd php5-mcrypt php5-mysql -y > /dev/null
apt-get install libapache2-mod-php5

The Wordpress installation works fine when I host it on nGinx locally (not using Vagrant) but as soon as I place it in a Vagrant box it doesn't want to play. Does anyone have any ideas? I presume it's something to do with my Vagrant box setup but i'm not sure what!

Thanks!


Alvaro Miranda Aguilera

unread,
Jan 14, 2016, 12:55:28 AM1/14/16
to vagra...@googlegroups.com
Hello,

I did create this basic word press vagrant for some friends, feel free to copy/edit, etc, it's based on the Digital Ocean document, just I make it more simple since not all the features are needed.


Alvaro

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/mitchellh/vagrant/issues
IRC: #vagrant on Freenode
---
You received this message because you are subscribed to the Google Groups "Vagrant" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vagrant-up+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vagrant-up/33cab695-cc0c-4b49-9868-60215c110223%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Edgar Oliveira

unread,
Jan 17, 2016, 6:40:28 AM1/17/16
to Vagrant
Hello,

I tried run this VM and this is a output:

ede@ede ~/Documents/sandbox/vagrantWordpress $ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Box 'ubuntu/trusty64' could not be found. Attempting to find and install...
    default: Box Provider: virtualbox
    default: Box Version: >= 0
==> default: Loading metadata for box 'ubuntu/trusty64'
==> default: Adding box 'ubuntu/trusty64' (v20160108.0.1) for provider: virtualbox
==> default: Successfully added box 'ubuntu/trusty64' (v20160108.0.1) for 'virtualbox'!
==> default: Importing base box 'ubuntu/trusty64'...
==> default: Matching MAC address for NAT networking...
==> default: Checking if box 'ubuntu/trusty64' is up to date...
==> default: Setting the name of the VM: vagrantWordpress_default_1453030187415_67920
==> default: Clearing any previously set forwarded ports...
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
==> default: Forwarding ports...
    default: 80 (guest) => 8080 (host) (adapter 1)
    default: 22 (guest) => 2222 (host) (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2222
    default: SSH username: vagrant
    default: SSH auth method: private key
Timed out while waiting for the machine to boot. This means that
Vagrant was unable to communicate with the guest machine within
the configured ("config.vm.boot_timeout" value) time period.

If you look above, you should be able to see the error(s) that
Vagrant had when attempting to connect to the machine. These errors
are usually good hints as to what may be wrong.

If you're using a custom box, make sure that networking is properly
working and you're able to connect to the machine. It is a common
problem that networking isn't setup properly in these boxes.
Verify that authentication configurations are also setup properly,
as well.

If the box appears to be booting properly, you may want to increase
the timeout ("config.vm.boot_timeout") value.


When I tried execute ssh command I receive this message, after a waiting time:

ede@ede ~/Documents/sandbox/vagrantWordpress $ vagrant ssh
ssh_exchange_identification: read: Connection reset by peer

thanks

Edgar Oliveira

unread,
Jan 17, 2016, 6:44:38 AM1/17/16
to Vagrant
I think what happened an error during installation ssh, because when I did vagrant halt received this output:

==> default: Attempting graceful shutdown of VM...
    default: Guest communication could not be established! This is usually because
    default: SSH is not running, the authentication information was changed,
    default: or some other networking issue. Vagrant will force halt, if
    default: capable.
==> default: Forcing shutdown of VM...

Alvaro Miranda Aguilera

unread,
Jan 17, 2016, 6:49:40 AM1/17/16
to vagra...@googlegroups.com
Hello Edgard.

By general rule, if one particular project fail, you can try like this:

vagrant up --no-provision

That will start the VM without any provision.

If that runs fine, but vagrant provision make the box un-usable, then something in the provision is to blame.

If --no-provision still fails, then is the box to blame.

I always recommend hashicorp/precise64 as test to see if the vagrant setup is working.

Alvaro.

Reply all
Reply to author
Forward
0 new messages