Skip to content

Instantly share code, notes, and snippets.

@Ravaelles
Last active October 21, 2024 07:23
Show Gist options
  • Save Ravaelles/f20bd2ce034f8874b43c4f2f3c15adb0 to your computer and use it in GitHub Desktop.
Save Ravaelles/f20bd2ce034f8874b43c4f2f3c15adb0 to your computer and use it in GitHub Desktop.
PHP 5.6 + nginx + MongoDB driver for PHP
#!/bin/bash
######################################################
### README ###########################################
######################################################
###
### One-line server install script for Ubuntu.
### Installs Nginx + PHP5.6 + MongoDB for PHP driver.
###
### Removes previous Apache, PHP, nginx installations.
### What it installs:
### - latest nginx with production-ready config
### - PHP 5.6 with mbstring, mcrypt, ext-dom
### - MongoDB driver for PHP 5.6
### - composer
### - unzip and p7zip-full
###
### USAGE: ###########################################
### wget ubuntu-script.tk -O ubuntu-script.sh && sudo chmod +x ubuntu-script.sh && sudo ./ubuntu-script.sh && rm ubuntu-script.sh
###
### Last updated: Jan 05, 2017
### Let's roll!
#####################################################
### Fix host problem that occurs by default #########
clear
sudo echo -n "127.0.0.1 " > _tmp
sudo cat /etc/hostname >> _tmp
cat /etc/hosts >> _tmp
sudo mv _tmp /etc/hosts
### Force removal of old Apache, PHP, nginx #########
sudo apt-get remove apache* php* nginx* -y
### Add all repositories ############################
echo -e "\n### Adding nginx repository #############\n";
sudo add-apt-repository ppa:nginx/stable -y
echo -e "\n### Adding PHP repository ###############\n";
sudo add-apt-repository ppa:ondrej/php -y
sudo apt-get update && sudo apt-get upgrade -y
### Install nginx ###################################
echo -e "\n### Installing nginx #############\n";
sudo apt-get update
sudo apt-get install nginx -y
### Use proper nginx config file ####################
### Automatically inserts server IP address #########
echo -e "\n### Setting up nginx config ######\n";
sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/_original
wget nginx-default.tk -O _nginx_default
currentip=$(wget http://ipinfo.io/ip -qO -)
sed -i s/1.2.3.4/${currentip}/g _nginx_default
sudo cp _nginx_default /etc/nginx/sites-available/default
sudo service nginx restart
### Install PHP 5.6 #################################
echo -e "\n### Installing PHP 5.6 #############\n";
sudo apt-get install php5.6 php5.6-fpm -y
### Install PHP extensions required by Laravel
echo -e "\n### Installing PHP extensions ######\n";
sudo apt-get install php5.6-curl php5.6-mbstring php5.6-mcrypt php5.6-xml -y
### Install MongoDB driver for PHP 5.6 ##############
echo -e "\n### Installing MongoDB PHP driver ##\n";
sudo apt-get install php-mongodb -y
# Make sure extension=mongodb.so is present
PhpConfigFile="/etc/php/5.6/fpm/php.ini"
if grep -q mongodb.so "$PhpConfigFile"; then
echo "extension=mongodb.so already found, dont add."
else
echo "extension=mongodb.so" | sudo tee "$PhpConfigFile"
echo "Added extension=mongodb.so to $PhpConfigFile"
fi
### Install composer ################################
echo -e "\n### Installing composer ##\n";
sudo apt-get install composer -y
### Create shortcut to www directory in home ########
sudo ln -s /var/www/html www
### Ensure www is fully writable ####################
currentuser=$(whoami)
sudo chmod 777 -R /var/www
sudo chown ${currentuser}:${currentuser} -R /var/www
### Install unzip and 7zip ##########################
sudo apt install p7zip-full unzip -y
### Clean up ########################################
rm _tmp
rm _nginx_default
### 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 "\n### Finished ###"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment