Skip to content

Commit b8c07b8

Browse files
committed
Add Vagrantfile
1 parent ade0846 commit b8c07b8

1 file changed

Lines changed: 112 additions & 0 deletions

File tree

Vagrantfile

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
# -*- mode: ruby -*-
2+
# vi: set ft=ruby :
3+
4+
# https://github.com/hashicorp/vagrant/issues/9442#issuecomment-374785457
5+
unless Vagrant::DEFAULT_SERVER_URL.frozen?
6+
Vagrant::DEFAULT_SERVER_URL.replace('https://vagrantcloud.com')
7+
end
8+
9+
Vagrant.configure("2") do |config|
10+
# VM Box
11+
#config.vm.box = "debian/testing64"
12+
config.vm.box = "ubuntu/bionic64"
13+
14+
# Automatic box update checking
15+
config.vm.box_check_update = true
16+
17+
# CodeIgniter virtual host
18+
config.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "127.0.0.1"
19+
# Code Coverage virtual host
20+
config.vm.network "forwarded_port", guest: 8080, host: 8081, host_ip: "127.0.0.1"
21+
22+
# virtualbox type allow auto-sync host to guest and guest to host
23+
# VAGRANT_DISABLE_STRICT_DEPENDENCY_ENFORCEMENT=1 vagrant plugin install vagrant-vbguest
24+
config.vm.synced_folder ".", "/var/www/codeigniter", type: "rsync"
25+
26+
# Provider-specific configuration
27+
config.vm.provider "virtualbox" do |vb|
28+
# Display the VirtualBox GUI when booting the machine
29+
vb.gui = false
30+
# Customize the amount of memory on the VM:
31+
vb.memory = "512"
32+
end
33+
34+
# Provision
35+
config.vm.provision "shell", inline: <<-SHELL
36+
MYSQL_ROOT_PASS="password"
37+
VIRTUALHOST="localhost"
38+
PHP_VERSION=7.2
39+
PGSQL_VERSION=11
40+
41+
echo "127.0.0.1 ${VIRTUALHOST}" >> /etc/hosts
42+
43+
export DEBIAN_FRONTEND=noninteractive
44+
45+
echo "Updating and installing required packages..."
46+
47+
apt-get update
48+
49+
debconf-set-selections <<< "mysql-server mysql-server/root_password password ${MYSQL_ROOT_PASS}"
50+
debconf-set-selections <<< "mysql-server mysql-server/root_password_again password ${MYSQL_ROOT_PASS}"
51+
52+
apt-get install -y \
53+
php$PHP_VERSION apache2 curl composer \
54+
php-intl php-mbstring php-curl php-gd php-xdebug \
55+
php-mysql mysql-server mysql-client \
56+
php-pgsql postgresql-$PGSQL_VERSION postgresql-client-$PGSQL_VERSION \
57+
php-sqlite3 sqlite3 \
58+
php-memcached memcached \
59+
php-redis redis-server
60+
61+
apt-get autoclean
62+
63+
echo "Configuring databases..."
64+
65+
mysql -e "CREATE DATABASE IF NOT EXISTS codeigniter;" -uroot -p$MYSQL_ROOT_PASS
66+
mysql -e "SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = 'codeigniter';" -uroot -p$MYSQL_ROOT_PASS
67+
mysql -e "GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION; FLUSH PRIVILEGES;" -uroot -p$MYSQL_ROOT_PASS
68+
sed -i "s/^bind-address/#bind-address/" /etc/mysql/my.cnf
69+
systemctl restart mysql
70+
71+
72+
sed -i "s/#listen_addresses = 'localhost'/listen_addresses = '*'/" /etc/postgresql/$PGSQL_VERSION/main/postgresql.conf
73+
echo "host all all all md5" >> /etc/postgresql/$PGSQL_VERSION/main/pg_hba.conf
74+
sudo -u postgres psql -c 'CREATE DATABASE codeigniter;'
75+
sudo -u postgres psql -c "alter user postgres with password 'password';"
76+
systemctl restart postgresql
77+
78+
echo "Configuring virtual hosts..."
79+
80+
mkdir -p /var/www/codeigniter/builds/coverage-html
81+
mkdir -p /var/www/codeigniter/public
82+
mkdir -p /var/www/codeigniter/writable/apache
83+
84+
sed -i "s/APACHE_RUN_USER=www-data/APACHE_RUN_USER=vagrant/" /etc/apache2/envvars
85+
sed -i "s/APACHE_RUN_GROUP=www-data/APACHE_RUN_GROUP=vagrant/" /etc/apache2/envvars
86+
87+
echo "
88+
<VirtualHost *:80>
89+
ServerAdmin webmaster@${VIRTUALHOST}
90+
ServerName ${VIRTUALHOST}
91+
ServerAlias www.${VIRTUALHOST}
92+
DirectoryIndex index.php
93+
DocumentRoot /var/www/codeigniter/public
94+
LogLevel warn
95+
ErrorLog /var/www/codeigniter/writable/apache/error.log
96+
CustomLog /var/www/codeigniter/writable/apache/custom.log combined
97+
</VirtualHost>
98+
<VirtualHost *:8080>
99+
ServerName ${VIRTUALHOST}
100+
ServerAlias www.${VIRTUALHOST}
101+
DirectoryIndex index.html
102+
DocumentRoot /var/www/codeigniter/builds/coverage-html
103+
</VirtualHost>
104+
" > /etc/apache2/sites-available/codeigniter.conf
105+
106+
a2enmod rewrite
107+
a2dissite 000-default.conf
108+
a2ensite codeigniter.conf
109+
systemctl restart apache2
110+
111+
SHELL
112+
end

0 commit comments

Comments
 (0)