Trouble with Vagrant - "404 - Not Found" - linux

I am attempting to make a LAMP box using Vagrant. I have been told that it is quite simple to use. I am completely new to networks and virtual machines and have very little experience with Linux/Ubuntu. I have currently tried following the tutorial on the official documentation page: http://docs.vagrantup.com/v2/getting-started/networking.html.
I have gotten up to the networking article in the documentation and can't seem to get it working.
Now the problem is, due to my inexperience with networking and linux based OS's I have no idea where to begin trouble shooting. I will try to give as much information I can.
I'm running the latest version of Vagrant with the latest version of Virtualbox with Windows 8.1.
As per the tutorial, my current Vagrantfile looks like this:
Vagrant.configure(2) do |config|
config.vm.box = "hashicorp/precise32"
config.vm.provision :shell, path: "bootstrap.sh"
config.vm.network :forwarded_port, host: 4567, guest: 80
end
My bootstrap.sh file looks like this:
#!/usr/bin/env bash
apt-get update
apt-get install -y apache2
if ! [ -L /var/www ]; then
rm -rf /var/www
ln -f /vagrant /var/www
fi
When I went to http://127.0.0.1:4567, it displayed an error page containing this message:
Not Found
The requested URL / was not found on this server.
===================================================
Apache/2.2.22 (Ubuntu) Server at 127.0.0.1 Port 4567
I would rather not edit any config files, unless there was an explanation, as I feel that would be a workaround. But regardless, ANY help would be appreciated. If I need to open up a port, then how do I'm at the point where I'm just considering using XAMPP.

I had same problem. I tried to restart apache from the vagrant box, I got following warning on my terminal.
vagrant#vagrant-ubuntu-trusty-64:~$ sudo service apache2 restart
* Restarting web server apache2
AH00112: Warning: DocumentRoot [/var/www/html] does not exist
AH00558: apache2: Could not reliably determine the server's fully qualified
domain name, using 10.0.2.15. Set the 'ServerName' directive globally to suppress this message
Create a DocumentRoot to fix the 404 issue by creating a directory called /var/www/html

The issue is on /etc/apache2/sites-enabled 000-default file.
Apache2 is pointing to var/www/html and vagrant example to var/www just remove de /html and make a sudo service apache2 restart.

Can you access your web server from inside your virtual machine ?
For example, try curl localhost:80
if curl is not installed, use sudo apt-get install curl on Ubuntu and try again.
Also, have you checked your apache virtual hosts ?
Is there a 000-default file in /etc/apache2/sites-available ?

There are two issues in bootstrap.sh
You need start the web service. You can also vagrant ssh to manually start it
You need make soft link, not hard link.
So the script will be updated as
$ cat bootstrap.sh
#!/usr/bin/env bash
apt-get update
apt-get install -y apache2
if ! [ -L /var/www ]; then
rm -rf /var/www
ln -s /vagrant /var/www
fi
service apache2 start

I've experimented two working solutions:
The first is to change the file /etc/apache2/sites-enabled/000-default.conf modifing DocumentRoot in /var/www instead of /var/www/html
The second is to change the Vagrant file bootstrap.sh in the following way:
#!/usr/bin/env bash
apt-get update
apt-get install -y apache2
if ! [ -L /var/www/html ]; then
rm -rf /var/www/html
ln -fs /vagrant /var/www/html
fi
Beside that, for some reason I've had to change also the configuration of port forwarding in the Vagrantfile, adding the host_ip key, like this:
Vagrant.configure(2) do |config|
config.vm.box = "hashicorp/precise32"
config.vm.provision :shell, path: "bootstrap.sh"
config.vm.network :forwarded_port, host: 4567, guest: 80, host_ip: "127.0.0.1"
end

Related

Accessing a file from the browser from a vagrant box

I'm very new to Vagrant/ using vm boxes on a daily basis and cant seem to figure out how to access a file that I've shared from my local machine, to the vm, through the browser. I've got a shared folder going to the root home/vagrant which is the directory I'm navigated to when logging in using vagrant ssh. Then opening up a browser and typing in localhost:8000/index.html i get a 404 not found.
I know i'm doing something very wrong and probably using Vagrant incorrectly but at the same time feel like I'm just not pointing my shared folder to the right place.
-- Edit --
So far my vagrantfile a provisioning looks like
Vagrant.configure("2") do |config|
config.vm.box = "scotch/box"
config.vm.network "forwarded_port", guest: 80, host: 9001
config.vm.provision :shell, path: "bootstrap.sh"
config.vm.synced_folder ".", "/var/www"
end
apt-get update
apt-get install -y apache2
if ! [ -L /var/www ]; then
ln -fs /vagrant /var/www
fi
Figured it out, it was a combination of pointing my shared folder to the correct place in the vm using
config.vm.synced_folder "./dist/src", "/var/www"
cding into that directory and then using
php -S <-IP->:8000

How to share (config.vm.synced_folder), directories between Windows 10 and CentOS7 Virtual Machine created using Vagrant and VirtualBox

I'm trying to create a VM CentOS7 using Vagrant (2.2.3) and Virtual Box (6.0.4), on Windows 10 using the following Vagrant file
Vagrant.configure("2") do |config|
config.vm.box = "bento/centos-7"
config.vm.network "private_network", ip: "192.168.56.3"
config.vm.synced_folder "D://SharedWithVM//CentOS7-Work", "/media/sf_CentOS7-Work", type: "virtualbox"
config.vm.provider "virtualbox" do |vb|
vb.name = "Test"
end
config.vm.provision "shell", path: "./scripts/InstallGuestAdditions.sh"
end
and the InstallGuestAdditions.sh shell script is the follow ..
#!/bin/bash
curl -C - -O http://download.virtualbox.org/virtualbox/6.0.4/VBoxGuestAdditions_6.0.4.iso
sudo mkdir /media/VBoxGuestAdditions
sudo mount -o loop,ro VBoxGuestAdditions_6.0.4.iso /media/VBoxGuestAdditions
sudo sh /media/VBoxGuestAdditions/VBoxLinuxAdditions.run
rm VBoxGuestAdditions_6.0.4.iso
sudo umount /media/VBoxGuestAdditions
sudo rmdir /media/VBoxGuestAdditions
All works fine and the CentOS7 VM is created.
If I check the machine properties about shared directories I can see this
So I'm quite surprised about this path \\?\D:\SharedWithVM\CentOS7-Work.
How should I change my Vagrantfile to obtain a right path?
I've tried to connect at my CentOS 7 VM using vagrant ssh command and all works. Also the command cd /media/sf_CentOS7-Work works fine but no file or directory can be listed or shared between the two systems.
I've tried to create files or directories in Windows 10 and also in CentOS7 VM.
Any suggestion or example will be appreciated.

How to Change Document root folder in LAMP to a mounted location (Ubuntu)

I need to change the document root in LAMP, I use Ubuntu 15.
Since I want to have the same www folder for Linux as I have in Windows, I'll be using a mounted location.
To achieve that I ran the following command in Terminal (ALT+SHIFT+T -> to open Terminal):
sudo nano /etc/apache2/apache2.conf
Inside the editor I added the following code to the file:
<Directory /media/my_user_name/WORK/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
Then I ran sudo nano /etc/apache2/sites-available/000-default.conf
and edited the line containing DocumentRoot to:
DocumentRoot /media/my_user_name/WORK/www
In the end I run sudo service apache2 restart
Now everytime I access localhost I get the following error:
Forbidden
You don't have permission to access / on this server.
Apache/2.4.12 (Ubuntu) Server at localhost Port 80
Looks like I was missing 3 more steps:
1. As suggested by #Ferendevelop I should set permission to 755 running:
sudo chmod 755 /media/my_user_name/WORK/www/
2 Do a chmod +x on the user dir by running:
cd /media/
sudo chmod +x my_user_name
3 Restart Apache2 service by running:
sudo service apache2 restart
Now it works!
PS: Thanks!
Run the following command.
chmod 755 /media/my_user_name/WORK/www/

SSH Fails Due to Key File Permissions When I Try to Provision a Vagrant VM with Ansible on Windows/Cygwin

I’m using Cygwin (CYGWIN_NT-6.3-WOW64) under Windows 8. I’m also running Vagrant (1.7.2) and Ansible (1.8.4). To be complete, my Virtualbox is 4.3.22.
Cygwin and Vagrant have been installed from their respective Windows install packages. I’m running Python 2.7.8 under Cygwin and used ‘pip install ansible’ to install Ansible.
All of these applications work fine in their own right. Cygwin works wonderfully; I use it as my shell all day, every day with no problems.
Vagrant and Virtualbox also work with no problems when I run Vagrant under Cygwin. Ansible works fine under Cygwin as well when I run plays or modules against the servers on my network.
The problem I run into is when I try to use Ansible to provision a Vagrant VM running locally.
For example, I vagrant up a VM and then draft a simple playbook to provision it. Following are the Vagrantfile:
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.define :drupal1 do |config|
config.vm.box = "centos65-x86_64-updated"
config.vm.hostname = "drupal1"
config.vm.network "forwarded_port", guest: 80, host: 10080
config.vm.network :private_network, ip: "192.168.56.101"
config.vm.provider "virtualbox" do |v|
v.name = "Drupal Server 1"
v.memory = 1024
end
config.vm.provision :ansible do |ansible|
ansible.playbook = "provisioning/gather_facts.yml"
end
end
and playbook:
---
- hosts: all
gather_facts: yes
However, when I run ‘vagrant provision drupal1’, I get the following error:
vagrant provision drupal1
==> drupal1: Running provisioner: ansible... PYTHONUNBUFFERED=1 ANSIBLE_FORCE_COLOR=true ANSIBLE_HOST_KEY_CHECKING=false
ANSIBLE_SSH_ARGS='-o UserKnownHostsFile=/dev/null -o
ControlMaster=auto -o ControlPersist=60s' ansible-playbook
--private-key=C:/Users/mjenkins/workspace/Vagrant_VMs/Drupal1/.vagrant/machines/drupal1/virtualbox/private_key
--user=vagrant --connection=ssh --limit='drupal1' --inventory-file=C:/Users/mjenkins/workspace/Vagrant_VMs/Drupal1/.vagrant/provisioners/ansible/inventory
provisioning/gather_facts.yml PLAY [all]
GATHERING FACTS
fatal: [drupal1] => private_key_file
(C:/Users/mjenkins/workspace/Vagrant_VMs/Drupal1/.vagrant/machines/drupal1/virtualbox/private_key)
is group-readable or world-readable and thus insecure - you will
probably get an SSH failure PLAY RECAP
to retry, use: --limit #/home/mjenkins/gather_facts.retry
drupal1 : ok=0 changed=0 unreachable=1
failed=0 Ansible failed to complete successfully. Any error output
should be visible above. Please fix these errors and try again.
Looking at the error, its plainly obvious that it has something to do
with Ansible’s interpretation of my key and the file permissions on
either it or the folder its in.
Here are a few observations and steps I’ve tried:
I tried setting the permissions on the file and all the directories leading up to the file in Cygwin. That is chmod -R 700 .vagrant in the project directory. Still got the same error.
The key file is being referenced using a Windows path, not a Cygwin path (odd, though, that the file in the limit output has a Cygwin path). So I checked the permissions from the Windows side and changed it so that ‘Everyone’ has no access to .vagrant and all files/folders under it. Still got the same error.
Then I thought there might still be some problems with the file permissions/paths between my Cygwin based Ansible so I installed Python for Windows; used that pip to install Ansible, set my paths to that location, created an ansible-playbook.bat file, and ran Vagrant from a Windows cmd shell. Glad to say that tool chain worked….but I still got the same problem.
At this point I’m just about out of ideas so I turn to you, friends of Stackoverflow, for your input.
Any thoughts on solving this problem?
Your private key is very open and accessible by anyone. A check in SSH client prevents using such keys.
Try changing permissions with chmod from your cygwin or git bash, on your private and public keys.
On C:/Users/mjenkins/workspace/Vagrant_VMs/Drupal1/.vagrant/machines/drupal1/virtualbox/private_key
with chmod 700 private_key and ensure you have -rwx------ with ls -la
BAAAH! I just commented out the check in lib/ansible/runner/connection.py
Then I had to add in ansible.cfg
[ssh_connection]
control_path = /tmp
My solution to this was to override synced folder's permissions settings in the VagrantFile with the following ones:
Vagrant.configure(2) do |config|
config.vm.synced_folder "./", "/vagrant",
owner: "vagrant",
mount_options: ["dmode=775,fmode=600"]
...
I had similar issue and figured out a solution. I added following entries in my vagrant file
config.ssh.insert_key = false
config.ssh.private_key_path = "~/.vagrant.d/insecure_private_key"
and copied the insecure_private_key from my windows user folder to cygwin home as the path above. afterwards I did a
chmod 700 ~/.vagrant.d/insecure_private_key
and as a last step I removed the content of this file in cygwin home
~/.ssh/known_hosts
once I rerun the ansible-playbook command, I confirmed to add my localhost back to the known_hosts and the ssh connection worked.
truly saying it is much simpler if you understand what is happening.
Vagrant keep one folder for sharing file with host and other VM, that is /vagrant . Anything into that will be having mode 777 nothing can be done for that. sudo chmod too will not help , and you cannot change the mode.
Ansible is asking you to reduce the mode so that is not readable by group or all
so it is as simple as making a copy of the private key from
/vagrant/.vagrant/machines/yourmachine/virtualbox or any provisioner/
to may be home i.e ~ or /root
and then change chmod to 700 and use it in the inventory list in hosts file.
You could use the ansible_local provisioner for Vagrant. That will install Ansible into the VM. If you work with multiple vagrant virtual machines, then is is useful to let one be the ansible controller. This would then need the private SSH key. That can be done in the Vagrantfile with:
config.vm.provision "file", source: "~/.vagrant.d/insecure_private_key", destination: "/home/vagrant/.ssh/id_rsa"
config.vm.provision "shell", inline: "chmod 600 /home/vagrant/.ssh/id_rsa"

Redis running on 6379 even the conf file changed to 7000

I am installing the redis in a Linux Centos by following steps:
mkdir /redis/
cd /redis
wget http://redis.googlecode.com/files/redis-2.6.14.tar.gz
extracted it using tar -xzf redis-2.6.14.tar.gz
make && make install PREFIX=/redis/
Changed the port in redis.conf(/redis/redis.conf) to 7000
Changed the port redis_init_script(/redis/utils/redis_init_script) to 7000
Then issued the command /redis/bin/redis-server
Now when I issue the command I see this,
which says 6379.
:(
You haven't told it which config file to use, so you are starting the server with all defaults. Try instead:
/redis/bin/redis-server /redis/redis.conf

Resources