Homestead Extensions

Add MongoDB to homestead base installation

Lets supose that you have laravel install on your project .

go to vendor/homestead/scripts and create a file with the name "install-mongodb.sh"

install-mongo.sh

#!/usr/bin/env bash
​
echo ">>> Installing MongoDB"
​
# Get key and add to sources
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10
echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' | sudo tee /etc/apt/sources.list.d/mongodb.list
​
\# Update
sudo apt-get update
​
​
# Install MongoDB
# -qq implies -y --force-yes
sudo apt-get install -qq mongodb-org 
​
sudo apt-get install pkg-config
​
# Make MongoDB connectable from outside world without SSH tunnel
if [ $1 == "true" ]; then
    # enable remote access
    # setting the mongodb bind_ip to allow connections from everywhere
    sed -i "s/bind_ip = .*/bind_ip = 0.0.0.0/" /etc/mongod.conf
fi
​
# Test if PHP is installed
php -v > /dev/null 2>&1
PHP_IS_INSTALLED=$?
​
if [ $PHP_IS_INSTALLED -eq 0 ]; then
​
    sudo apt-get install php7.0-fpm
​
    # install dependencies
    sudo apt-get -y install php-pear php-dev
​
    # install php extension
    echo "no" > answers.txt
    sudo pecl install mongodb < answers.txt
    rm answers.txt
​
    # add extension file and restart service
    echo "extension=mongodb.so" >> `php --ini | grep "Loaded Configuration" | sed -e "s|.*:\s*||"`
​
   ln -s /etc/php/mods-available/mongo.ini /etc/php/7.0/fpm/conf.d/mongo.ini
   ln -s /etc/php/mods-available/mongo.ini /etc/php/7.0/cli/conf.d/mongo.ini
fi

edit homestead.rb and add the mongo port to the default port forwarding section

default_ports = { 80 => 8000, 443 => 44300, 3306 => 33060, 5432 => 54320, 27017 => 27017 }

Add :

if settings.has_key?("mongodb") && settings["mongodb"] config.vm.provision "shell" do |s| s.path = scriptDir + "/install-mongo.sh" end end

to the database section

then add to the Homestead.yaml mongodb: true and run vagrant reload --provision

Now ssh into your machine and edit the mongo config file /etc/mongod.conf change the the bind_ip config to 0.0.0.0 so your mongo server can be listen by the outside .

Restart the mongod service and its done . ´´´ sudo service mongod restart ´´´

results matching ""

    No results matching ""