Skip to content

Instantly share code, notes, and snippets.

@toonvandenbos
Last active February 19, 2016 16:56
Show Gist options
  • Save toonvandenbos/9378376 to your computer and use it in GitHub Desktop.
Save toonvandenbos/9378376 to your computer and use it in GitHub Desktop.
nginx - mariaDB - PHP5-FPM | ready for laravel 4 usage !
$script = <<SCRIPT
START_TIME=$SECONDS
# ------------------ ESSENTIALS
apt-get update
apt-get install -y unzip vim git-core curl wget build-essential python-software-properties
# ------------------ INSTALL NGINX
apt-get install -y nginx
sudo service nginx start
# ------------------ CONFIGURING NGINX
echo "user www-data;
worker_processes 4;
pid /var/run/nginx.pid;
events {
worker_connections 768;
# multi_accept on;
}
http {
##
# Basic Settings
##
sendfile off;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;
# server_names_hash_bucket_size 64;
# server_name_in_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
##
# Gzip Settings
##
gzip on;
gzip_disable "msie6";
# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
##
# nginx-naxsi config
##
# Uncomment it if you installed nginx-naxsi
##
#include /etc/nginx/naxsi_core.rules;
##
# nginx-passenger config
##
# Uncomment it if you installed nginx-passenger
##
#passenger_root /usr;
#passenger_ruby /usr/bin/ruby;
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}" > /etc/nginx/nginx.conf
# ------------------ RELOADING NGINX
sudo service nginx restart
# ------------------ CONFIGURING NGINX (step 2)
echo "server{
listen 80;
server_name 10.0.1.50;
root /vagrant/public;
error_log /var/log/nginx/laravel.error.log;
access_log /var/log/nginx/laravel.access.log;
# strip index.php/ prefix if it is present
rewrite ^/index.php/?(.*)$ / permanent;
location / {
index index.php;
try_files $uri @rewriteapp;
}
location @rewriteapp {
rewrite ^(.*)$ /index.php/ last;
}
# pass the PHP scripts to FastCGI server
location ~ ^/(index).php(/|$) {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_split_path_info ^(.+.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTPS off;
}
}" > /etc/nginx/sites-available/default
# ------------------ TESTING NGINX
sudo nginx -t
sudo service nginx restart
# ------------------ INSTALL MARIADB
sudo apt-get purge mysql*
sudo apt-get autoremove
#fixing : E: Unmet dependencies
touch /etc/apt/preferences.d/50_mariadb
echo "Package: *
Pin: origin mariadb.mirror.nucleus.be
Pin-Priority: 1000" > /etc/apt/preferences.d/50_mariadb
sudo apt-get install software-properties-common
sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xcbcb082a1bb943db
sudo add-apt-repository 'deb http://mariadb.mirror.nucleus.be//repo/5.5/ubuntu saucy main' -y
apt-get update
sudo debconf-set-selections <<< 'mysql-server mysql-server/root_password password root'
sudo debconf-set-selections <<< 'mysql-server mysql-server/root_password_again password root'
apt-get install mariadb-server mariadb-client -y
# ------------------ INSTALL PHP5
sudo apt-get install php5 php5-fpm php5-mysql php5-mcrypt php5-json php5-cli -y php5-curl
# ------------------ CONFIGURING PHP5-FPM
sed -i 's/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/g' /etc/php5/fpm/php.ini
# Fixing Ubuntu 13.10 bug with php5-mcrypt
# If not running this Ubuntu version, this is not necessary
sudo ln -s /etc/php5/conf.d/mcrypt.ini /etc/php5/mods-available/mcrypt.ini
sudo php5enmod mcrypt
# ------------------ RELOAD PHP5-FPM
sudo service php5-fpm restart
# ------------------ CONFIGURING MARIADB (making it accessible for a mysql-client and adding database called "abcarrosserie")
touch /etc/mysql/mysql_bootstrap.sql
echo "CREATE USER 'root'@'%' IDENTIFIED BY '';
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;
CREATE DATABASE IF NOT EXISTS name_of_your_database CHARACTER SET = utf8 COLLATE = utf8_unicode_ci;" > /etc/mysql/mysql_bootstrap.sql
mysql --user=root --password=root mysql< /etc/mysql/mysql_bootstrap.sql
sed -i 's/# skip-external-locking/skip-external-locking/g' /etc/mysql/my.cnf
sed -i 's/^# bind-address.*/bind-address = 10.0.1.50/g' /etc/mysql/my.cnf
sed -i 's/^bind-address.*/bind-address = 10.0.1.50/g' /etc/mysql/my.cnf
sudo service mysql restart
# ------------------ TEST PHP WITH INFO.PHP
touch /usr/share/nginx/html/info.php
echo "<?php phpinfo();?>" > /usr/share/nginx/html/info.php
# ------------------ RELOADING NGINX
sudo service nginx restart
# ------------------ END
ELAPSED_TIME=$(($SECONDS - $START_TIME))
# clear
echo "------------------------"
echo "- Provisionning ended. -"
echo "------------------------"
echo "Duration : $(($ELAPSED_TIME/60)) min $(($ELAPSED_TIME%60)) sec"
echo "------------------------"
/etc/init.d/nginx status
sudo service mysql status
echo "------------------------"
SCRIPT
Vagrant.configure("2") do |config|
config.vm.box = "saucy32"
config.vm.box_url = "http://cloud-images.ubuntu.com/vagrant/saucy/current/saucy-server-cloudimg-i386-vagrant-disk1.box"
config.vm.provision :shell, :inline => $script
config.vm.hostname = "project.vm"
config.vm.network :forwarded_port, guest: 3306, host: 3309
config.vm.network :private_network, ip: "10.0.1.50"
config.vm.network :public_network
config.vm.provider "virtualbox" do |v|
v.name = "project"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment