Question

Maybe it's just because it's a Friday and it's after closing time but I've been stuck on this for an hour and can't quite get it working. I'm using Vagrant with an application we're building - the git repo contains the Vagrantfile and a Laravel application. We have /deploy, /tests, and /src directories; the actual Laravel framework lives in /src. On my local machine, I have set up a VirtualHost that let's me access the application by browsing to localhost:9000:

Listen 8081
<VirtualHost *:8081>
    DocumentRoot "/Application/mamp/apache2/htdocs/myapp/src/public"
    ServerName localhost
    <Directory "/Application/mamp/apache2/htdocs/myapp/src/public">
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

Works like a charm. So I copied the relevant bits to my Vagrant setup:

Listen 8081
<VirtualHost *:8081>
    DocumentRoot "/var/www/src/public"
    ServerName localhost
    <Directory "/var/www/src/public">
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

My Vagrantfile looks like this:

# -*- mode: ruby -*-
# vi: set ft=ruby :

# 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 = "hashicorp/precise64"
    config.vm.provision :shell, :path => "vagrant/main.sh"
    config.vm.network "private_network", ip: "192.168.100.101", virtualbox__intnet: true
end

And my vagrant/main.sh file looks like this:

#!/usr/bin/env bash

apt-get update

echo mysql-server-5.5 mysql-server/root_password password notthepassword | debconf-set-selections
echo mysql-server-5.5 mysql-server/root_password_again password notthepassword | debconf-set-selections

apt-get install -y mysql-common mysql-server mysql-client

apt-get install -y apache2

apt-get install -y php5 libapache2-mod-php5
apt-get install -y php5-mysql php5-curl php-pear php5-imagick php5-mcrypt php5-memcache

apt-get install -y vim

a2enmod rewrite
sed -i -e 's/AllowOverride None/AllowOverride All/g' /etc/apache2/sites-available/default
cp /vagrant/vagrant/bgs /etc/apache2/sites-available
a2ensite bgs
/etc/init.d/apache2 restart

rm -rf /var/www
ln -fs /vagrant /var/www

Once it's all up and running I can ping 192.168.100.101. But it's not serving any HTML - if I browse to that address in Chrome, I get a "no data received" error. If I go to 192.168.100.101:8081 Chrome says it can't find the address. How can I configure everything to play nice together and let me clone my repo, run vagrant up, and browse to 192.168.100.101:8081 and see my app?

(Also: I even added a port forwarding line in there to go from guest:8081 to host:8081. That generated an HTTP 500 error ("The server encountered an internal error or misconfiguration and was unable to complete your request."). Not sure if that's progress or not.

Était-ce utile?

La solution

Turns out there was a number of things happening all at once:

  • I was using Ubuntu 12 LTS, which had a version of PHP a little to old to run the edge release of Laravel. Installing an upgraded version of PHP fixed that.
  • The virtualbox__intnet directive was...wrong. Somehow. Changed that whole Vagrantfile line to: config.vm.network "private_network", :ip => "192.168.100.101", :auto_network => true
  • The different ports, mucking about in the various symlinked directories vs. apache config directories...needlessly complicated.

Here's my final setup, in case anyone else has this exact, specific problem:

Vagrantfile:

# -*- mode: ruby -*-
# vi: set ft=ruby :

# 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 = "puppetlabs/ubuntu-13.10-64-puppet"
    config.vm.provision :shell, :path => "vagrant/main.sh"
    config.vm.network "private_network", :ip => "192.168.100.101", :auto_network => true
end

main.sh:

#!/usr/bin/env bash

apt-get update

echo mysql-server-5.5 mysql-server/root_password password f6b6rWixbu99CtQ | debconf-set-selections
echo mysql-server-5.5 mysql-server/root_password_again password f6b6rWixbu99CtQ | debconf-set-selections

apt-get install -y mysql-common mysql-server mysql-client apache2 php5 libapache2-mod-php5 php5-mysql php5-curl php-pear php5-imagick php5-mcrypt php5-memcache php5-json

a2enmod rewrite
sed -i -e 's/AllowOverride None/AllowOverride All/g' /etc/apache2/sites-available/default
cp /vagrant/vagrant/app.conf /etc/apache2/sites-available
a2ensite app.conf

#fix for ubuntu 13.10: http://stackoverflow.com/questions/19446679/mcrypt-not-present-after-ubuntu-upgrade-to-13-10
ln -s /etc/php5/conf.d/mcrypt.ini /etc/php5/mods-available/mcrypt.ini
php5enmod mcrypt
#/fix

#json licensing snafu: http://stackoverflow.com/questions/18239405/php-fatal-error-call-to-undefined-function-json-decode
php5enmod json
#/snafu

#may need to be done on the host OS, not the guest: http://stackoverflow.com/questions/17954625/services-json-failed-to-open-stream-permission-denied-in-laravel-4
chmod -R 0777 /vagrant/src/app/storage

rm -rf /var/www
ln -fs /vagrant/src/public /var/www

/etc/init.d/apache2 restart

Apache site configuration copied in:

<VirtualHost *:80>
    DocumentRoot "/var/www"
    ServerName localhost
    <Directory "/var/www">
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

(BTW, though this config looks very similar to the default apache configuration, I found it was easier and more extensible to create a config for whatever project I happen to be working on, and if I need to expand on the options for a future project, I can.)

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top