Skip to content

Commit 163343e

Browse files
committed
Add Vagrant from main repo
1 parent 2fe2b8f commit 163343e

File tree

1 file changed

+203
-0
lines changed

1 file changed

+203
-0
lines changed

src/Vagrantfile.dist

Lines changed: 203 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
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 = "ubuntu/bionic64"
12+
# Automatic box update checking
13+
config.vm.box_check_update = true
14+
15+
# CodeIgniter virtual host
16+
config.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "127.0.0.1"
17+
# Code Coverage virtual host
18+
config.vm.network "forwarded_port", guest: 81, host: 8081, host_ip: "127.0.0.1"
19+
# User Guide virtual host
20+
config.vm.network "forwarded_port", guest: 82, host: 8082, host_ip: "127.0.0.1"
21+
# MySQL server
22+
#config.vm.network "forwarded_port", guest: 3306, host: 3307, host_ip: "127.0.0.1"
23+
# PostgreSQL server
24+
#config.vm.network "forwarded_port", guest: 5432, host: 5433, host_ip: "127.0.0.1"
25+
# Memcached server
26+
#config.vm.network "forwarded_port", guest: 11211, host: 11212, host_ip: "127.0.0.1"
27+
# Redis server
28+
#config.vm.network "forwarded_port", guest: 6379, host: 6380, host_ip: "127.0.0.1"
29+
30+
# Add "192.168.10.10 ${VIRTUALHOST}" in your host file to access by domain
31+
#config.vm.network "private_network", ip: "192.168.10.10"
32+
33+
# Same path set in the $CODEIGNITER_PATH Provision
34+
# "virtualbox" type allow auto-sync host to guest and guest to host
35+
# but chmod does not work... tests will fail.
36+
# Default rsync__args except "--copy-links", to allow phpunit correctly works by symlink
37+
config.vm.synced_folder ".", "/var/www/codeigniter", type: "rsync", rsync__args: ["--verbose", "--archive", "--delete", "-z"]
38+
39+
# Provider-specific configuration
40+
config.vm.provider "virtualbox" do |vb|
41+
# Display the VirtualBox GUI when booting the machine
42+
vb.gui = false
43+
# Customize the amount of memory on the VM:
44+
vb.memory = "1024"
45+
end
46+
47+
# Provision
48+
config.vm.provision "shell", inline: <<-SHELL
49+
MYSQL_ROOT_PASS="password"
50+
PGSQL_ROOT_PASS="password"
51+
VIRTUALHOST="localhost"
52+
CODEIGNITER_PATH="/var/www/codeigniter"
53+
PHP_VERSION=7.3
54+
PGSQL_VERSION=10
55+
#APT_PROXY="192.168.10.1:3142"
56+
57+
grep -q "127.0.0.1 ${VIRTUALHOST}" /etc/hosts || echo "127.0.0.1 ${VIRTUALHOST}" >> /etc/hosts
58+
59+
# Creates a swap file if necessary
60+
RAM=`awk '/MemTotal/ {print $2}' /proc/meminfo`
61+
if [ $RAM -lt 1000000 ] && [ ! -f /swap/swapfile ]; then
62+
echo "================================================================================"
63+
echo "Adding swap"
64+
echo "================================================================================"
65+
echo "This process may take a few minutes. Please wait..."
66+
mkdir /swap
67+
dd if=/dev/zero of=/swap/swapfile bs=1024 count=1000000
68+
chmod 600 /swap/swapfile
69+
mkswap /swap/swapfile
70+
swapon /swap/swapfile
71+
echo "/swap/swapfile swap swap defaults 0 0" >> /etc/fstab
72+
echo "Done."
73+
fi
74+
75+
# Prepare to use APT Proxy
76+
if [ ! -z $APT_PROXY ]; then
77+
if [ ! -f /etc/apt/sources.list-origin ]; then
78+
cp /etc/apt/sources.list /etc/apt/sources.list-origin
79+
fi
80+
sed -i "s/archive.ubuntu.com/${APT_PROXY}/" /etc/apt/sources.list
81+
sed -i "s/security.ubuntu.com/${APT_PROXY}/" /etc/apt/sources.list
82+
fi
83+
84+
export DEBIAN_FRONTEND=noninteractive
85+
86+
echo "================================================================================"
87+
echo "Updating and Installing Required Packages"
88+
echo "================================================================================"
89+
90+
add-apt-repository ppa:ondrej/php
91+
92+
apt-get update
93+
94+
debconf-set-selections <<< "mysql-server mysql-server/root_password password ${MYSQL_ROOT_PASS}"
95+
debconf-set-selections <<< "mysql-server mysql-server/root_password_again password ${MYSQL_ROOT_PASS}"
96+
97+
apt-get install -y \
98+
php$PHP_VERSION apache2 composer \
99+
php-intl php-mbstring php-xml php-zip php-xdebug \
100+
php-mysql mysql-server mysql-client \
101+
php-pgsql postgresql-$PGSQL_VERSION \
102+
php-sqlite3 sqlite3 \
103+
php-memcached memcached \
104+
php-redis redis-server \
105+
php-curl curl \
106+
php-gd php-imagick \
107+
python-pip
108+
109+
pip install sphinx sphinxcontrib-phpdomain
110+
111+
apt-get autoclean
112+
113+
echo "================================================================================"
114+
echo "Preparing User Guide"
115+
echo "================================================================================"
116+
117+
cd "${CODEIGNITER_PATH}/user_guide_src/cilexer"
118+
python setup.py install
119+
cd ..
120+
make html
121+
122+
echo "================================================================================"
123+
echo "Configuring Databases"
124+
echo "================================================================================"
125+
126+
sed -i "s/^bind-address/#bind-address/" /etc/mysql/mysql.conf.d/mysqld.cnf
127+
mysql -e "CREATE DATABASE IF NOT EXISTS codeigniter COLLATE 'utf8_general_ci';
128+
UPDATE mysql.user SET Host='%' WHERE user='root';
129+
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;
130+
FLUSH PRIVILEGES;" -uroot -p$MYSQL_ROOT_PASS
131+
systemctl restart mysql
132+
133+
sed -i "s/^#listen_addresses = 'localhost'/listen_addresses = '*'/" /etc/postgresql/$PGSQL_VERSION/main/postgresql.conf
134+
grep -q "host all root all md5" /etc/postgresql/$PGSQL_VERSION/main/pg_hba.conf || echo "host all root all md5" >> /etc/postgresql/$PGSQL_VERSION/main/pg_hba.conf
135+
sudo -u postgres psql -tc "SELECT 1 FROM pg_roles WHERE rolname='root'" | grep -q 1 || sudo -u postgres psql -c "CREATE ROLE root WITH SUPERUSER CREATEDB CREATEROLE INHERIT LOGIN"
136+
sudo -u postgres psql -c "ALTER ROLE root WITH PASSWORD '${PGSQL_ROOT_PASS}'"
137+
sudo -u postgres psql -tc "SELECT 1 FROM pg_database WHERE datname='codeigniter'" | grep -q 1 ||sudo -u postgres psql -c "CREATE DATABASE codeigniter"
138+
sudo -u postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE codeigniter TO root"
139+
systemctl restart postgresql
140+
141+
echo "================================================================================"
142+
echo "Configuring Memcached and Redis"
143+
echo "================================================================================"
144+
145+
sed -i "s/^bind 127.0.0.1/#bind 127.0.0.1/" /etc/redis/redis.conf
146+
sed -i "s/^protected-mode yes/protected-mode no/" /etc/redis/redis.conf
147+
sed -i "s/^-l 127.0.0.1/#-l 127.0.0.1/" /etc/memcached.conf
148+
systemctl restart redis
149+
systemctl restart memcached
150+
151+
echo "================================================================================"
152+
echo "Configuring Virtual Hosts"
153+
echo "================================================================================"
154+
155+
mkdir -p "${CODEIGNITER_PATH}/build/coverage-html"
156+
mkdir -p "${CODEIGNITER_PATH}/public"
157+
mkdir -p "${CODEIGNITER_PATH}/user_guide_src/build/html"
158+
mkdir -p "${CODEIGNITER_PATH}/writable/apache"
159+
chown -R vagrant:vagrant $CODEIGNITER_PATH
160+
161+
# Creates a symlink in the user home
162+
if [ ! -d /home/vagrant/codeigniter ]; then
163+
ln -s $CODEIGNITER_PATH /home/vagrant/codeigniter
164+
fi
165+
166+
sed -i "s/APACHE_RUN_USER=www-data/APACHE_RUN_USER=vagrant/" /etc/apache2/envvars
167+
sed -i "s/APACHE_RUN_GROUP=www-data/APACHE_RUN_GROUP=vagrant/" /etc/apache2/envvars
168+
grep -q "Listen 81" /etc/apache2/ports.conf || sed -i "s/^Listen 80/Listen 80\\nListen 81\\nListen 82/" /etc/apache2/ports.conf
169+
sed -i "s/^display_errors = Off/display_errors = On/" /etc/php/7.3/apache2/php.ini
170+
sed -i "s/^display_startup_errors = Off/display_startup_errors = On/" /etc/php/7.3/apache2/php.ini
171+
172+
echo "ServerName ${VIRTUALHOST}
173+
<Directory ${CODEIGNITER_PATH}>
174+
DirectoryIndex index.html index.php
175+
Options All
176+
AllowOverride All
177+
</Directory>
178+
<VirtualHost *:80>
179+
ServerAdmin vagrant@localhost
180+
DocumentRoot ${CODEIGNITER_PATH}/public
181+
ErrorLog ${CODEIGNITER_PATH}/writable/apache/error.log
182+
CustomLog ${CODEIGNITER_PATH}/writable/apache/custom.log combined
183+
</VirtualHost>
184+
<VirtualHost *:81>
185+
DocumentRoot ${CODEIGNITER_PATH}/build/coverage-html
186+
</VirtualHost>
187+
<VirtualHost *:82>
188+
DocumentRoot ${CODEIGNITER_PATH}/user_guide_src/build/html
189+
</VirtualHost>
190+
" > /etc/apache2/sites-available/codeigniter.conf
191+
192+
a2enmod rewrite
193+
a2dissite 000-default.conf
194+
a2ensite codeigniter.conf
195+
systemctl restart apache2
196+
197+
echo "================================================================================"
198+
echo "Services Status"
199+
echo "================================================================================"
200+
service --status-all
201+
202+
SHELL
203+
end

0 commit comments

Comments
 (0)