initiate vagrant project

This commit is contained in:
Omair Saleh
2019-01-23 23:29:57 +08:00
commit f0c760539c
12 changed files with 386 additions and 0 deletions
+6
View File
@@ -0,0 +1,6 @@
PROJECT_SYNC=sync
ENABLE_SHARED_PROJECT_FOLDERS=true
PRIVATE_KEY_PATH=~/.ssh/id_rsa
PUBLIC_KEY_PATH=~/.ssh/id_rsa.pub
+5
View File
@@ -0,0 +1,5 @@
* text=auto
*.sh eol=lf
*.conf eol=lf
*.ini eol=lf
*.sql eol=lf
+3
View File
@@ -0,0 +1,3 @@
.vagrant
.env
.idea
+22
View File
@@ -0,0 +1,22 @@
### Vagrant for Development
Ensure that Virtualbox is installed, with host only network enabled and the adapter address set to 10.0.0.1 and the mask set to 255.255.255.0.
Install requisite vagrant plugins with:
```
vagrant plugin install vagrant-env
vagrant plugin install vagrant-vbguest
```
Copy the .env.example file to .env and change variables as needed.
To start the virtual machines, run the following:
```
vagrant up <db|exchange|izyim>
```
### Private Key
To use your own private key, ensure that the .env file variable PRIVATE_KEY_PATH is set.
Vendored
+59
View File
@@ -0,0 +1,59 @@
Vagrant.configure(2) do |config|
# enable env plugin
config.env.enable
# base box
config.vm.box = "centos/7"
# add synced host folder with guest folder
config.vm.synced_folder ".", "/vagrant", type: "virtualbox"
# ssh configuration
config.ssh.insert_key = false
config.ssh.private_key_path = [ENV['PRIVATE_KEY_PATH'], "~/.vagrant.d/insecure_private_key"]
machines = {
'izyim' => {
:ip => '10.0.0.20',
:provision => './scripts/izyim.sh',
:cores => '2',
:memory => '1024',
:guest_port => '22',
:host_port => '2201'
},
'exchange' => {
:ip => '10.0.0.21',
:provision => './scripts/exchange.sh',
:cores => '2',
:memory => '1024',
:guest_port => '22',
:host_port => '2202'
}
}
machines.each do |hostname, attrs|
config.vm.define hostname do |machine|
# set up the hostname
machine.vm.hostname = hostname
# set up private network
machine.vm.network "private_network", ip: attrs[:ip]
# enable port forwarding
machine.vm.network :forwarded_port, host_ip: '127.0.0.1', id: 'ssh', guest: attrs[:guest_port], host: attrs[:host_port], protocol: 'tcp'
# provision scripts
machine.vm.provision "file", source: ENV['PUBLIC_KEY_PATH'], destination: '~/.ssh/authorized_keys'
machine.vm.provision :shell do |provision|
provision.path = attrs[:provision]
end
# virtualbox specific settings
machine.vm.provider "virtualbox" do |v|
v.memory = attrs[:memory]
v.cpus = attrs[:cores]
end
end
end
end
+10
View File
@@ -0,0 +1,10 @@
CREATE DATABASE DATABASE_NAME;
CREATE USER 'DATABASE_NAME'@'%' IDENTIFIED BY 'DATABASE_PASSWORD';
CREATE USER 'DATABASE_NAME'@'localhost' IDENTIFIED BY 'DATABASE_PASSWORD';
GRANT ALL PRIVILEGES ON DATABASE_NAME.* TO 'DATABASE_NAME'@'%';
GRANT ALL PRIVILEGES ON DATABASE_NAME.* TO 'DATABASE_NAME'@'localhost';
FLUSH PRIVILEGES;
+39
View File
@@ -0,0 +1,39 @@
server {
listen 80;
listen 443 default_server ssl;
root /var/www/html/VAGRANT_SERVER_NAME/public;
index index.php index.html index.htm;
ssl_certificate /etc/nginx/ssl/self-ssl.crt;
ssl_certificate_key /etc/nginx/ssl/self-ssl.key;
server_name VAGRANT_SERVER_NAME;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
# PHP-FPM Configuration Nginx
location ~ [^/]\.php(/|$) {
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
if (!-f $document_root$fastcgi_script_name) {
return 404;
}
# Mitigate https://httpoxy.org/ vulnerabilities
fastcgi_param HTTP_PROXY "";
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
# include the fastcgi_param setting
include fastcgi_params;
# SCRIPT_FILENAME parameter is used for PHP FPM determining
# the script name. If it is not set in fastcgi_params file,
# i.e. /etc/nginx/fastcgi_params or in the parent contexts,
# please comment off following line:
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
+2
View File
@@ -0,0 +1,2 @@
*
!.gitignore
+2
View File
@@ -0,0 +1,2 @@
*
!.gitignore
+2
View File
@@ -0,0 +1,2 @@
*
!.gitignore
+118
View File
@@ -0,0 +1,118 @@
#!/bin/bash
VAGRANT_NAME="exchange"
VAGRANT_SERVER_NAME="exchange.localhost"
VAGRANT_CONFIG=/vagrant/config
VAGRANT_LOGS=/vagrant/logs
VAGRANT_PROJECT=/vagrant/project
NETWORK_INTERFACE="$(route | grep '^10\.0\.0\.0' | grep -o '[^ ]*$')"
DATABASE_NAME=exchange
DATABASE_PASSWORD=123456abcabc
sudo su
cd ~
# update and install the basics
yum -y update && yum -y upgrade
yum -y install vim wget curl
# set timezone to local time
timedatectl set-timezone Asia/Kuala_Lumpur
# create aliases
echo "alias ${VAGRANT_NAME}='cd /var/www/html/${VAGRANT_SERVER_NAME}'" >> /home/vagrant/.bashrc
echo "alias lastlog='tail -Fn 50 /var/www/html/${VAGRANT_SERVER_NAME}/storage/logs/laravel-'\$(date +"%Y-%m-%d")'.log'" >> /home/vagrant/.bashrc
# install nginx
yum -y install epel-release
yum -y install nginx
yum -y install net-tools
# start nginx
systemctl start nginx
systemctl enable nginx
# copy the nginx configuration
cp ${VAGRANT_CONFIG}/nginx/default.conf /etc/nginx/conf.d/${VAGRANT_NAME}.conf
# replace the VAGRANT_LOG_DIRECTORY variable in the configuration file with the log directory
sed -i 's|VAGRANT_LOG_DIRECTORY|'${VAGRANT_LOGS}'|g' /etc/nginx/conf.d/${VAGRANT_NAME}.conf
sed -i 's|VAGRANT_SERVER_NAME|'${VAGRANT_SERVER_NAME}'|g' /etc/nginx/conf.d/${VAGRANT_NAME}.conf
sed -i 's|VAGRANT_NAME|'${VAGRANT_NAME}'|g' /etc/nginx/conf.d/${VAGRANT_NAME}.conf
# symlink the project files
mkdir -p /var/www/html
ln -s ${VAGRANT_PROJECT}/${VAGRANT_NAME} /var/www/html/${VAGRANT_SERVER_NAME}
# set up a self signed cert
mkdir /etc/nginx/ssl/
openssl req -new -x509 -days 3650 -nodes -out /etc/nginx/ssl/self-ssl.crt -keyout /etc/nginx/ssl/self-ssl.key -subj "/C=MY/ST=WP/L=KL/O=IPSO/CN=${VAGRANT_SERVER_NAME}"
openssl rsa -in /etc/nginx/ssl/self-ssl.key -out /etc/nginx/ssl/self-ssl.key
openssl req -new -key /etc/nginx/ssl/self-ssl.key -out /etc/nginx/ssl/self-ssl.csr -subj "/C=MY/ST=Selangor/L=Cyberjaya/O=CIEF Malaysia/OU=IT Department/CN=izyim.com"
openssl x509 -noout -modulus -in /etc/nginx/ssl/self-ssl.crt| openssl md5
openssl rsa -noout -modulus -in /etc/nginx/ssl/self-ssl.key| openssl md5
# enable repo for webtatic
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
# install PHP
yum -y install php72w php72w-curl php72w-common php72w-cli php72w-mysql php72w-mbstring php72w-fpm php72w-xml php72w-pdo php72w-zip php72w-gd
# install and enable php-fpm
yum -y install php72w-fpm
systemctl start php-fpm
systemctl enable php-fpm
# restart ngnix
systemctl restart nginx
systemctl restart php-fpm
#disable SELiunx
sed -i 's|SELINUX=enforcing|'SELINUX=disabled'|g' /etc/selinux/config
setenforce 0
# make a copy of the default sql files for processing
cp ${VAGRANT_CONFIG}/db/default.sql ~
# replace the database name and password tokens in the setup file
sed -i 's|DATABASE_PASSWORD|'${DATABASE_PASSWORD}'|g' ~/default.sql
sed -i 's|DATABASE_NAME|'${DATABASE_NAME}'|g' ~/default.sql
# install db
yum -y install mariadb mariadb-server
# start and enable the db
systemctl start mariadb
systemctl enable mariadb
# create the database, users, assign permissions
mysql -u root < ~/default.sql
# remove the sql files
rm -rf ~/*.sql
# display mysql version
mysql --version
# install composer and global dependencies
wget https://raw.githubusercontent.com/composer/getcomposer.org/1b137f8bf6db3e79a38a5bc45324414a6b1f9df2/web/installer -O - -q | php -- --quiet
mv composer.phar /usr/bin/composer
chmod +x /usr/bin/composer
composer self-update
composer global require hirak/prestissimo
# install nodeJS and global dependencies
curl --silent --location https://rpm.nodesource.com/setup_8.x | bash -
yum -y install nodejs
npm install -g gulp yarn n
# display apache, php, node, npm versions
nginx -v
php -v
echo "Node Version: "$(node -v)
echo "NPM Version: "$(npm -v)
# display ip address
echo "IP Address: "$(ip addr show ${NETWORK_INTERFACE} | grep "inet\b" | awk '{print $2}' | cut -d/ -f1)
+118
View File
@@ -0,0 +1,118 @@
#!/bin/bash
VAGRANT_NAME="izyim"
VAGRANT_SERVER_NAME="izyim.localhost"
VAGRANT_CONFIG=/vagrant/config
VAGRANT_LOGS=/vagrant/logs
VAGRANT_PROJECT=/vagrant/project
NETWORK_INTERFACE="$(route | grep '^10\.0\.0\.0' | grep -o '[^ ]*$')"
DATABASE_NAME=izyim
DATABASE_PASSWORD=123456abcabc
sudo su
cd ~
# update and install the basics
yum -y update && yum -y upgrade
yum -y install vim wget curl
# set timezone to local time
timedatectl set-timezone Asia/Kuala_Lumpur
# create aliases
echo "alias ${VAGRANT_NAME}='cd /var/www/html/${VAGRANT_SERVER_NAME}'" >> /home/vagrant/.bashrc
echo "alias lastlog='tail -Fn 50 /var/www/html/${VAGRANT_SERVER_NAME}/storage/logs/laravel-'\$(date +"%Y-%m-%d")'.log'" >> /home/vagrant/.bashrc
# install nginx
yum -y install epel-release
yum -y install nginx
yum -y install net-tools
# start nginx
systemctl start nginx
systemctl enable nginx
# copy the nginx configuration
cp ${VAGRANT_CONFIG}/nginx/default.conf /etc/nginx/conf.d/${VAGRANT_NAME}.conf
# replace the VAGRANT_LOG_DIRECTORY variable in the configuration file with the log directory
sed -i 's|VAGRANT_LOG_DIRECTORY|'${VAGRANT_LOGS}'|g' /etc/nginx/conf.d/${VAGRANT_NAME}.conf
sed -i 's|VAGRANT_SERVER_NAME|'${VAGRANT_SERVER_NAME}'|g' /etc/nginx/conf.d/${VAGRANT_NAME}.conf
sed -i 's|VAGRANT_NAME|'${VAGRANT_NAME}'|g' /etc/nginx/conf.d/${VAGRANT_NAME}.conf
# symlink the project files
mkdir -p /var/www/html
ln -s ${VAGRANT_PROJECT}/${VAGRANT_NAME} /var/www/html/${VAGRANT_SERVER_NAME}
# set up a self signed cert
mkdir /etc/nginx/ssl/
openssl req -new -x509 -days 3650 -nodes -out /etc/nginx/ssl/self-ssl.crt -keyout /etc/nginx/ssl/self-ssl.key -subj "/C=MY/ST=WP/L=KL/O=IPSO/CN=${VAGRANT_SERVER_NAME}"
openssl rsa -in /etc/nginx/ssl/self-ssl.key -out /etc/nginx/ssl/self-ssl.key
openssl req -new -key /etc/nginx/ssl/self-ssl.key -out /etc/nginx/ssl/self-ssl.csr -subj "/C=MY/ST=Selangor/L=Cyberjaya/O=CIEF Malaysia/OU=IT Department/CN=izyim.com"
openssl x509 -noout -modulus -in /etc/nginx/ssl/self-ssl.crt| openssl md5
openssl rsa -noout -modulus -in /etc/nginx/ssl/self-ssl.key| openssl md5
# enable repo for webtatic
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
# install PHP
yum -y install php72w php72w-curl php72w-common php72w-cli php72w-mysql php72w-mbstring php72w-fpm php72w-xml php72w-pdo php72w-zip
# install and enable php-fpm
yum -y install php72w-fpm
systemctl start php-fpm
systemctl enable php-fpm
# restart ngnix
systemctl restart nginx
systemctl restart php-fpm
#disable SELiunx
sed -i 's|SELINUX=enforcing|'SELINUX=disabled'|g' /etc/selinux/config
setenforce 0
# make a copy of the default sql files for processing
cp ${VAGRANT_CONFIG}/db/default.sql ~
# replace the database name and password tokens in the setup file
sed -i 's|DATABASE_PASSWORD|'${DATABASE_PASSWORD}'|g' ~/default.sql
sed -i 's|DATABASE_NAME|'${DATABASE_NAME}'|g' ~/default.sql
# install db
yum -y install mariadb mariadb-server
# start and enable the db
systemctl start mariadb
systemctl enable mariadb
# create the database, users, assign permissions
mysql -u root < ~/default.sql
# remove the sql files
rm -rf ~/*.sql
# display mysql version
mysql --version
# install composer and global dependencies
wget https://raw.githubusercontent.com/composer/getcomposer.org/1b137f8bf6db3e79a38a5bc45324414a6b1f9df2/web/installer -O - -q | php -- --quiet
mv composer.phar /usr/bin/composer
chmod +x /usr/bin/composer
composer self-update
composer global require hirak/prestissimo
# install nodeJS and global dependencies
curl --silent --location https://rpm.nodesource.com/setup_8.x | bash -
yum -y install nodejs
npm install -g gulp yarn n
# display apache, php, node, npm versions
nginx -v
php -v
echo "Node Version: "$(node -v)
echo "NPM Version: "$(npm -v)
# display ip address
echo "IP Address: "$(ip addr show ${NETWORK_INTERFACE} | grep "inet\b" | awk '{print $2}' | cut -d/ -f1)