Skip to content

Instantly share code, notes, and snippets.

@Ravaelles
Last active July 4, 2018 13:51
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ravaelles/966f12189da65a1f8089b875e84f6b41 to your computer and use it in GitHub Desktop.
Save Ravaelles/966f12189da65a1f8089b875e84f6b41 to your computer and use it in GitHub Desktop.
Laravel Homestead + MongoDB PHP 7.1 driver installer
#!/bin/bash
######################################################
### README ###########################################
######################################################
###
### One-line Laravel Homestead MongoDB driver PHP installer.
###
### What it does:
### - installs some MongoDB PHP driver dependencies
### - installs MongoDB driver for PHP 7.1 using PECL
### - adds extension=mongodb.so to both cli and npm php.ini files
### - removes any apache* packages
### - restarts PHP
###
### USAGE: ###########################################
### wget homestead-script.tk -O homestead-script.sh && sudo chmod +x homestead-script.sh && sudo ./homestead-script.sh && rm homestead-script.sh
###
### Last updated: Jun 27, 2017
clear
### Install nginx ###################################
echo -e "\n### Updating and upgrading ########\n";
sudo apt-get update && sudo apt-get upgrade -y
### Install dependencies ############################
sudo apt-get install pkg-config libssl-dev libsslcommon2-dev -y
### Install MongoDB driver for PHP 7 ################
echo -e "\n### Installing MongoDB PHP driver ##\n";
sudo pecl install mongodb -y
# Make sure extension=mongodb.so is present in CLI
PhpConfigFile="/etc/php/7.1/cli/php.ini"
if grep -q mongodb.so "$PhpConfigFile"; then
echo "extension=mongodb.so already found in CLI, dont add."
else
echo "extension=mongodb.so" | sudo tee "$PhpConfigFile"
echo "Added extension=mongodb.so to $PhpConfigFile"
fi
# Make sure extension=mongodb.so is present in FPM
PhpConfigFile="/etc/php/7.1/fpm/php.ini"
if grep -q mongodb.so "$PhpConfigFile"; then
echo "extension=mongodb.so already found in FPM, dont add."
else
echo "extension=mongodb.so" | sudo tee "$PhpConfigFile"
echo "Added extension=mongodb.so to $PhpConfigFile"
fi
#echo "extension=mongodb.so" >> `php --ini | grep "Loaded Configuration" | sed -e "s|.*:\s*||"`
sudo service php7.1-fpm restart
### Force removing Apache ###########################
sudo apt-get remove apache* -y
### Update and upgrade ##############################
sudo apt-get update && sudo apt-get upgrade -y
### Verify installs #################################
echo -e ""
echo -e "###############################"
echo -e "### VERIFY THE OUTPUT BELOW ###"
echo -e "###############################"
echo -e "\n### nginx #############\n"
sudo service nginx restart && sudo service nginx configtest
echo -e "$(nginx -v)"
echo -e "\n### PHP ###############\n"
echo -e "$(php -v)"
echo -e "\n### MongoDB for PHP ###\n"
echo -e "$(php -i | grep mongo)\n"
echo -e "### Finished ###"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment