Files
2019-01-23 23:29:57 +08:00

118 lines
3.8 KiB
Bash

#!/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)