commit f0c760539c9a46e8d4007e2f71ac2d3395f61490 Author: Omair Saleh Date: Wed Jan 23 23:29:57 2019 +0800 initiate vagrant project diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..d0c77ca --- /dev/null +++ b/.env.example @@ -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 diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..f40258e --- /dev/null +++ b/.gitattributes @@ -0,0 +1,5 @@ +* text=auto +*.sh eol=lf +*.conf eol=lf +*.ini eol=lf +*.sql eol=lf diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1027f15 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.vagrant +.env +.idea \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..b6f3b9b --- /dev/null +++ b/README.md @@ -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 +``` + +### Private Key + +To use your own private key, ensure that the .env file variable PRIVATE_KEY_PATH is set. \ No newline at end of file diff --git a/Vagrantfile b/Vagrantfile new file mode 100644 index 0000000..72b1401 --- /dev/null +++ b/Vagrantfile @@ -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 \ No newline at end of file diff --git a/config/db/default.sql b/config/db/default.sql new file mode 100644 index 0000000..aefccbb --- /dev/null +++ b/config/db/default.sql @@ -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; \ No newline at end of file diff --git a/config/nginx/default.conf b/config/nginx/default.conf new file mode 100644 index 0000000..7721786 --- /dev/null +++ b/config/nginx/default.conf @@ -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; + } +} \ No newline at end of file diff --git a/logs/.gitignore b/logs/.gitignore new file mode 100644 index 0000000..c96a04f --- /dev/null +++ b/logs/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore \ No newline at end of file diff --git a/project/exchange/.gitignore b/project/exchange/.gitignore new file mode 100644 index 0000000..c96a04f --- /dev/null +++ b/project/exchange/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore \ No newline at end of file diff --git a/project/izyim/.gitignore b/project/izyim/.gitignore new file mode 100644 index 0000000..c96a04f --- /dev/null +++ b/project/izyim/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore \ No newline at end of file diff --git a/scripts/exchange.sh b/scripts/exchange.sh new file mode 100644 index 0000000..df1981c --- /dev/null +++ b/scripts/exchange.sh @@ -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) \ No newline at end of file diff --git a/scripts/izyim.sh b/scripts/izyim.sh new file mode 100644 index 0000000..33deb0f --- /dev/null +++ b/scripts/izyim.sh @@ -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) \ No newline at end of file