From b8c07b8e63db83a5bb95f3ed31fde66e20f7b10c Mon Sep 17 00:00:00 2001 From: Natan Felles Date: Sun, 11 Nov 2018 19:28:44 -0200 Subject: [PATCH 01/12] Add Vagrantfile --- Vagrantfile | 112 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 Vagrantfile diff --git a/Vagrantfile b/Vagrantfile new file mode 100644 index 000000000000..9a5914539c26 --- /dev/null +++ b/Vagrantfile @@ -0,0 +1,112 @@ +# -*- mode: ruby -*- +# vi: set ft=ruby : + +# https://github.com/hashicorp/vagrant/issues/9442#issuecomment-374785457 +unless Vagrant::DEFAULT_SERVER_URL.frozen? + Vagrant::DEFAULT_SERVER_URL.replace('https://vagrantcloud.com') +end + +Vagrant.configure("2") do |config| + # VM Box + #config.vm.box = "debian/testing64" + config.vm.box = "ubuntu/bionic64" + + # Automatic box update checking + config.vm.box_check_update = true + + # CodeIgniter virtual host + config.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "127.0.0.1" + # Code Coverage virtual host + config.vm.network "forwarded_port", guest: 8080, host: 8081, host_ip: "127.0.0.1" + + # virtualbox type allow auto-sync host to guest and guest to host + # VAGRANT_DISABLE_STRICT_DEPENDENCY_ENFORCEMENT=1 vagrant plugin install vagrant-vbguest + config.vm.synced_folder ".", "/var/www/codeigniter", type: "rsync" + + # Provider-specific configuration + config.vm.provider "virtualbox" do |vb| + # Display the VirtualBox GUI when booting the machine + vb.gui = false + # Customize the amount of memory on the VM: + vb.memory = "512" + end + + # Provision + config.vm.provision "shell", inline: <<-SHELL + MYSQL_ROOT_PASS="password" + VIRTUALHOST="localhost" + PHP_VERSION=7.2 + PGSQL_VERSION=11 + + echo "127.0.0.1 ${VIRTUALHOST}" >> /etc/hosts + + export DEBIAN_FRONTEND=noninteractive + + echo "Updating and installing required packages..." + + apt-get update + + debconf-set-selections <<< "mysql-server mysql-server/root_password password ${MYSQL_ROOT_PASS}" + debconf-set-selections <<< "mysql-server mysql-server/root_password_again password ${MYSQL_ROOT_PASS}" + + apt-get install -y \ + php$PHP_VERSION apache2 curl composer \ + php-intl php-mbstring php-curl php-gd php-xdebug \ + php-mysql mysql-server mysql-client \ + php-pgsql postgresql-$PGSQL_VERSION postgresql-client-$PGSQL_VERSION \ + php-sqlite3 sqlite3 \ + php-memcached memcached \ + php-redis redis-server + + apt-get autoclean + + echo "Configuring databases..." + + mysql -e "CREATE DATABASE IF NOT EXISTS codeigniter;" -uroot -p$MYSQL_ROOT_PASS + mysql -e "SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = 'codeigniter';" -uroot -p$MYSQL_ROOT_PASS + mysql -e "GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION; FLUSH PRIVILEGES;" -uroot -p$MYSQL_ROOT_PASS + sed -i "s/^bind-address/#bind-address/" /etc/mysql/my.cnf + systemctl restart mysql + + + sed -i "s/#listen_addresses = 'localhost'/listen_addresses = '*'/" /etc/postgresql/$PGSQL_VERSION/main/postgresql.conf + echo "host all all all md5" >> /etc/postgresql/$PGSQL_VERSION/main/pg_hba.conf + sudo -u postgres psql -c 'CREATE DATABASE codeigniter;' + sudo -u postgres psql -c "alter user postgres with password 'password';" + systemctl restart postgresql + + echo "Configuring virtual hosts..." + + mkdir -p /var/www/codeigniter/builds/coverage-html + mkdir -p /var/www/codeigniter/public + mkdir -p /var/www/codeigniter/writable/apache + + sed -i "s/APACHE_RUN_USER=www-data/APACHE_RUN_USER=vagrant/" /etc/apache2/envvars + sed -i "s/APACHE_RUN_GROUP=www-data/APACHE_RUN_GROUP=vagrant/" /etc/apache2/envvars + + echo " + + ServerAdmin webmaster@${VIRTUALHOST} + ServerName ${VIRTUALHOST} + ServerAlias www.${VIRTUALHOST} + DirectoryIndex index.php + DocumentRoot /var/www/codeigniter/public + LogLevel warn + ErrorLog /var/www/codeigniter/writable/apache/error.log + CustomLog /var/www/codeigniter/writable/apache/custom.log combined + + + ServerName ${VIRTUALHOST} + ServerAlias www.${VIRTUALHOST} + DirectoryIndex index.html + DocumentRoot /var/www/codeigniter/builds/coverage-html + +" > /etc/apache2/sites-available/codeigniter.conf + + a2enmod rewrite + a2dissite 000-default.conf + a2ensite codeigniter.conf + systemctl restart apache2 + + SHELL +end From bc8ecf1e4f0f781d290d3f64da89116577455a19 Mon Sep 17 00:00:00 2001 From: Natan Felles Date: Wed, 14 Nov 2018 01:12:59 -0200 Subject: [PATCH 02/12] Makes Vagrantfile workable --- Vagrantfile | 100 ++++++++++++++++++++++++++++++++-------------------- 1 file changed, 61 insertions(+), 39 deletions(-) diff --git a/Vagrantfile b/Vagrantfile index 9a5914539c26..8bee8df805d7 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -8,41 +8,50 @@ end Vagrant.configure("2") do |config| # VM Box - #config.vm.box = "debian/testing64" config.vm.box = "ubuntu/bionic64" - # Automatic box update checking config.vm.box_check_update = true # CodeIgniter virtual host config.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "127.0.0.1" # Code Coverage virtual host - config.vm.network "forwarded_port", guest: 8080, host: 8081, host_ip: "127.0.0.1" + config.vm.network "forwarded_port", guest: 81, host: 8081, host_ip: "127.0.0.1" + # MySQL server + #config.vm.network "forwarded_port", guest: 3306, host: 3307, host_ip: "127.0.0.1" + # PostgreSQL server + #config.vm.network "forwarded_port", guest: 5432, host: 5433, host_ip: "127.0.0.1" + + # Add "192.168.10.10 ${VIRTUALHOST}" in your host file to access by domain + #config.vm.network "private_network", ip: "192.168.10.10" - # virtualbox type allow auto-sync host to guest and guest to host - # VAGRANT_DISABLE_STRICT_DEPENDENCY_ENFORCEMENT=1 vagrant plugin install vagrant-vbguest - config.vm.synced_folder ".", "/var/www/codeigniter", type: "rsync" + # Same path set in the $CODEIGNITER_PATH Provision + # "virtualbox" type allow auto-sync host to guest and guest to host + config.vm.synced_folder ".", "/var/www/codeigniter", type: "virtualbox" # Provider-specific configuration config.vm.provider "virtualbox" do |vb| # Display the VirtualBox GUI when booting the machine vb.gui = false # Customize the amount of memory on the VM: - vb.memory = "512" + vb.memory = "768" end # Provision config.vm.provision "shell", inline: <<-SHELL MYSQL_ROOT_PASS="password" + POSTGRES_USER_PASS="password" VIRTUALHOST="localhost" + CODEIGNITER_PATH="/var/www/codeigniter" PHP_VERSION=7.2 - PGSQL_VERSION=11 + POSTGRES_VERSION=10 - echo "127.0.0.1 ${VIRTUALHOST}" >> /etc/hosts + grep -q "127.0.0.1 ${VIRTUALHOST}" /etc/hosts || echo "127.0.0.1 ${VIRTUALHOST}" >> /etc/hosts export DEBIAN_FRONTEND=noninteractive - echo "Updating and installing required packages..." + echo "================================================================================" + echo "Updating and Installing Required Packages" + echo "================================================================================" apt-get update @@ -50,56 +59,64 @@ Vagrant.configure("2") do |config| debconf-set-selections <<< "mysql-server mysql-server/root_password_again password ${MYSQL_ROOT_PASS}" apt-get install -y \ - php$PHP_VERSION apache2 curl composer \ - php-intl php-mbstring php-curl php-gd php-xdebug \ + php$PHP_VERSION apache2 composer \ + php-intl php-mbstring php-xml php-xdebug \ php-mysql mysql-server mysql-client \ - php-pgsql postgresql-$PGSQL_VERSION postgresql-client-$PGSQL_VERSION \ + php-pgsql postgresql-$POSTGRES_VERSION \ php-sqlite3 sqlite3 \ php-memcached memcached \ - php-redis redis-server + php-redis redis-server \ + php-curl curl \ + php-gd php-imagick apt-get autoclean - echo "Configuring databases..." + echo "================================================================================" + echo "Configuring Databases" + echo "================================================================================" - mysql -e "CREATE DATABASE IF NOT EXISTS codeigniter;" -uroot -p$MYSQL_ROOT_PASS - mysql -e "SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = 'codeigniter';" -uroot -p$MYSQL_ROOT_PASS - mysql -e "GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION; FLUSH PRIVILEGES;" -uroot -p$MYSQL_ROOT_PASS - sed -i "s/^bind-address/#bind-address/" /etc/mysql/my.cnf + mysql -e "CREATE DATABASE IF NOT EXISTS codeigniter COLLATE 'utf8_general_ci';; + UPDATE mysql.user SET Host='%' WHERE user='root'; + GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION; + FLUSH PRIVILEGES;" -uroot -p$MYSQL_ROOT_PASS + sed -i "s/^bind-address/#bind-address/" /etc/mysql/mysql.conf.d/mysqld.cnf systemctl restart mysql - - sed -i "s/#listen_addresses = 'localhost'/listen_addresses = '*'/" /etc/postgresql/$PGSQL_VERSION/main/postgresql.conf - echo "host all all all md5" >> /etc/postgresql/$PGSQL_VERSION/main/pg_hba.conf - sudo -u postgres psql -c 'CREATE DATABASE codeigniter;' - sudo -u postgres psql -c "alter user postgres with password 'password';" + sed -i "s/#listen_addresses = 'localhost'/listen_addresses = '*'/" /etc/postgresql/$POSTGRES_VERSION/main/postgresql.conf + grep -q "host all all all md5" /etc/postgresql/$POSTGRES_VERSION/main/pg_hba.conf || echo "host all all all md5" >> /etc/postgresql/$POSTGRES_VERSION/main/pg_hba.conf + sudo -u postgres psql -tc "SELECT 1 FROM pg_database WHERE datname = 'codeigniter';" | grep -q 1 || sudo -u postgres psql -c "CREATE DATABASE codeigniter;" + sudo -u postgres psql -c "ALTER USER postgres WITH PASSWORD '${POSTGRES_USER_PASS}';" systemctl restart postgresql - echo "Configuring virtual hosts..." + echo "================================================================================" + echo "Configuring Virtual Hosts" + echo "================================================================================" - mkdir -p /var/www/codeigniter/builds/coverage-html - mkdir -p /var/www/codeigniter/public - mkdir -p /var/www/codeigniter/writable/apache + mkdir -p "${CODEIGNITER_PATH}/build/coverage-html" + mkdir -p "${CODEIGNITER_PATH}/public" + mkdir -p "${CODEIGNITER_PATH}/writable/apache" + chown -R vagrant:vagrant $CODEIGNITER_PATH + + if [ ! -d /home/vagrant/codeigniter ]; then ln -s $CODEIGNITER_PATH /home/vagrant/codeigniter; fi sed -i "s/APACHE_RUN_USER=www-data/APACHE_RUN_USER=vagrant/" /etc/apache2/envvars sed -i "s/APACHE_RUN_GROUP=www-data/APACHE_RUN_GROUP=vagrant/" /etc/apache2/envvars + grep -q "Listen 81" /etc/apache2/ports.conf || sed -i "s/Listen 80/Listen 80\\nListen 81/" /etc/apache2/ports.conf echo " - ServerAdmin webmaster@${VIRTUALHOST} - ServerName ${VIRTUALHOST} - ServerAlias www.${VIRTUALHOST} + ServerAdmin vagrant@localhost DirectoryIndex index.php - DocumentRoot /var/www/codeigniter/public - LogLevel warn - ErrorLog /var/www/codeigniter/writable/apache/error.log - CustomLog /var/www/codeigniter/writable/apache/custom.log combined + DocumentRoot ${CODEIGNITER_PATH}/public + ErrorLog ${CODEIGNITER_PATH}/writable/apache/error.log + CustomLog ${CODEIGNITER_PATH}/writable/apache/custom.log combined - - ServerName ${VIRTUALHOST} - ServerAlias www.${VIRTUALHOST} + + ServerAdmin vagrant@localhost DirectoryIndex index.html - DocumentRoot /var/www/codeigniter/builds/coverage-html + DocumentRoot ${CODEIGNITER_PATH}/build/coverage-html + ErrorLog ${CODEIGNITER_PATH}/writable/apache/coverage-error.log + CustomLog ${CODEIGNITER_PATH}/writable/apache/coverage-custom.log combined " > /etc/apache2/sites-available/codeigniter.conf @@ -108,5 +125,10 @@ Vagrant.configure("2") do |config| a2ensite codeigniter.conf systemctl restart apache2 + echo "================================================================================" + echo "Services Status" + echo "================================================================================" + service --status-all + SHELL end From 826a5dd37eb7d07005a28f39a598a710a364fb3d Mon Sep 17 00:00:00 2001 From: Natan Felles Date: Wed, 14 Nov 2018 10:07:57 -0200 Subject: [PATCH 03/12] Back synced_folder type to rsync --- Vagrantfile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Vagrantfile b/Vagrantfile index 8bee8df805d7..66078bf0314d 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -26,7 +26,8 @@ Vagrant.configure("2") do |config| # Same path set in the $CODEIGNITER_PATH Provision # "virtualbox" type allow auto-sync host to guest and guest to host - config.vm.synced_folder ".", "/var/www/codeigniter", type: "virtualbox" + # but chmod does not work... tests will fail. + config.vm.synced_folder ".", "/var/www/codeigniter", type: "rsync" # Provider-specific configuration config.vm.provider "virtualbox" do |vb| @@ -84,7 +85,7 @@ Vagrant.configure("2") do |config| sed -i "s/#listen_addresses = 'localhost'/listen_addresses = '*'/" /etc/postgresql/$POSTGRES_VERSION/main/postgresql.conf grep -q "host all all all md5" /etc/postgresql/$POSTGRES_VERSION/main/pg_hba.conf || echo "host all all all md5" >> /etc/postgresql/$POSTGRES_VERSION/main/pg_hba.conf - sudo -u postgres psql -tc "SELECT 1 FROM pg_database WHERE datname = 'codeigniter';" | grep -q 1 || sudo -u postgres psql -c "CREATE DATABASE codeigniter;" + sudo -u postgres psql -tc "SELECT 1 FROM pg_database WHERE datname = 'codeigniter';" | grep -q 1 || sudo -u postgres psql -c "CREATE DATABASE codeigniter;" sudo -u postgres psql -c "ALTER USER postgres WITH PASSWORD '${POSTGRES_USER_PASS}';" systemctl restart postgresql From f3d47935ae084a9f7de3edc61dcd2859cffc47f1 Mon Sep 17 00:00:00 2001 From: Natan Felles Date: Wed, 14 Nov 2018 10:49:33 -0200 Subject: [PATCH 04/12] Add Directory section --- Vagrantfile | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Vagrantfile b/Vagrantfile index 66078bf0314d..3e638eea3a80 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -105,16 +105,19 @@ Vagrant.configure("2") do |config| grep -q "Listen 81" /etc/apache2/ports.conf || sed -i "s/Listen 80/Listen 80\\nListen 81/" /etc/apache2/ports.conf echo " + + DirectoryIndex index.html index.php + Options All + AllowOverride All + ServerAdmin vagrant@localhost - DirectoryIndex index.php DocumentRoot ${CODEIGNITER_PATH}/public ErrorLog ${CODEIGNITER_PATH}/writable/apache/error.log CustomLog ${CODEIGNITER_PATH}/writable/apache/custom.log combined ServerAdmin vagrant@localhost - DirectoryIndex index.html DocumentRoot ${CODEIGNITER_PATH}/build/coverage-html ErrorLog ${CODEIGNITER_PATH}/writable/apache/coverage-error.log CustomLog ${CODEIGNITER_PATH}/writable/apache/coverage-custom.log combined From 1712ae9fb50eb1400c200b59e9a46f323de39f94 Mon Sep 17 00:00:00 2001 From: Natan Felles Date: Wed, 14 Nov 2018 13:46:12 -0200 Subject: [PATCH 05/12] Allow rsync use symlinks and prepare user guide requirements --- Vagrantfile | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/Vagrantfile b/Vagrantfile index 3e638eea3a80..68482d9561ec 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -16,6 +16,8 @@ Vagrant.configure("2") do |config| config.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "127.0.0.1" # Code Coverage virtual host config.vm.network "forwarded_port", guest: 81, host: 8081, host_ip: "127.0.0.1" + # User Guide virtual host + config.vm.network "forwarded_port", guest: 82, host: 8082, host_ip: "127.0.0.1" # MySQL server #config.vm.network "forwarded_port", guest: 3306, host: 3307, host_ip: "127.0.0.1" # PostgreSQL server @@ -27,7 +29,8 @@ Vagrant.configure("2") do |config| # Same path set in the $CODEIGNITER_PATH Provision # "virtualbox" type allow auto-sync host to guest and guest to host # but chmod does not work... tests will fail. - config.vm.synced_folder ".", "/var/www/codeigniter", type: "rsync" + # Default rsync__args except "--copy-links", to allow phpunit correctly works by symlink + config.vm.synced_folder ".", "/var/www/codeigniter", type: "rsync", rsync__args: ["--verbose", "--archive", "--delete", "-z"] # Provider-specific configuration config.vm.provider "virtualbox" do |vb| @@ -68,7 +71,12 @@ Vagrant.configure("2") do |config| php-memcached memcached \ php-redis redis-server \ php-curl curl \ - php-gd php-imagick + php-gd php-imagick \ + python-pip + + pip install sphinx sphinxcontrib-phpdomain + python "${CODEIGNITER_PATH}/user_guide_src/cilexer/setup.py" install + pygmentize -L apt-get autoclean @@ -76,7 +84,7 @@ Vagrant.configure("2") do |config| echo "Configuring Databases" echo "================================================================================" - mysql -e "CREATE DATABASE IF NOT EXISTS codeigniter COLLATE 'utf8_general_ci';; + mysql -e "CREATE DATABASE IF NOT EXISTS codeigniter COLLATE 'utf8_general_ci'; UPDATE mysql.user SET Host='%' WHERE user='root'; GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION; FLUSH PRIVILEGES;" -uroot -p$MYSQL_ROOT_PASS @@ -95,6 +103,7 @@ Vagrant.configure("2") do |config| mkdir -p "${CODEIGNITER_PATH}/build/coverage-html" mkdir -p "${CODEIGNITER_PATH}/public" + mkdir -p "${CODEIGNITER_PATH}/user_guide_src/build/html" mkdir -p "${CODEIGNITER_PATH}/writable/apache" chown -R vagrant:vagrant $CODEIGNITER_PATH @@ -102,7 +111,7 @@ Vagrant.configure("2") do |config| sed -i "s/APACHE_RUN_USER=www-data/APACHE_RUN_USER=vagrant/" /etc/apache2/envvars sed -i "s/APACHE_RUN_GROUP=www-data/APACHE_RUN_GROUP=vagrant/" /etc/apache2/envvars - grep -q "Listen 81" /etc/apache2/ports.conf || sed -i "s/Listen 80/Listen 80\\nListen 81/" /etc/apache2/ports.conf + grep -q "Listen 81" /etc/apache2/ports.conf || sed -i "s/Listen 80/Listen 80\\nListen 81\\nListen 82/" /etc/apache2/ports.conf echo " @@ -117,10 +126,10 @@ Vagrant.configure("2") do |config| CustomLog ${CODEIGNITER_PATH}/writable/apache/custom.log combined - ServerAdmin vagrant@localhost DocumentRoot ${CODEIGNITER_PATH}/build/coverage-html - ErrorLog ${CODEIGNITER_PATH}/writable/apache/coverage-error.log - CustomLog ${CODEIGNITER_PATH}/writable/apache/coverage-custom.log combined + + + DocumentRoot ${CODEIGNITER_PATH}/user_guide_src/build/html " > /etc/apache2/sites-available/codeigniter.conf From e0e99b199d1c58486c059d804869b10d2aba54ae Mon Sep 17 00:00:00 2001 From: Natan Felles Date: Thu, 15 Nov 2018 10:23:26 -0200 Subject: [PATCH 06/12] Add php-zip --- Vagrantfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Vagrantfile b/Vagrantfile index 68482d9561ec..1de097cfbaa5 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -64,7 +64,7 @@ Vagrant.configure("2") do |config| apt-get install -y \ php$PHP_VERSION apache2 composer \ - php-intl php-mbstring php-xml php-xdebug \ + php-intl php-mbstring php-xml php-zip php-xdebug \ php-mysql mysql-server mysql-client \ php-pgsql postgresql-$POSTGRES_VERSION \ php-sqlite3 sqlite3 \ From 0e710601aedc19a3667c2a7a6a39185beb164e69 Mon Sep 17 00:00:00 2001 From: Natan Felles Date: Thu, 15 Nov 2018 15:03:09 -0200 Subject: [PATCH 07/12] Update Vagrantfile --- Vagrantfile | 42 ++++++++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/Vagrantfile b/Vagrantfile index 1de097cfbaa5..d8cc3f04a296 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -22,6 +22,10 @@ Vagrant.configure("2") do |config| #config.vm.network "forwarded_port", guest: 3306, host: 3307, host_ip: "127.0.0.1" # PostgreSQL server #config.vm.network "forwarded_port", guest: 5432, host: 5433, host_ip: "127.0.0.1" + # Memcached server + #config.vm.network "forwarded_port", guest: 11211, host: 11212, host_ip: "127.0.0.1" + # Redis server + #config.vm.network "forwarded_port", guest: 6379, host: 6380, host_ip: "127.0.0.1" # Add "192.168.10.10 ${VIRTUALHOST}" in your host file to access by domain #config.vm.network "private_network", ip: "192.168.10.10" @@ -43,11 +47,11 @@ Vagrant.configure("2") do |config| # Provision config.vm.provision "shell", inline: <<-SHELL MYSQL_ROOT_PASS="password" - POSTGRES_USER_PASS="password" + PGSQL_ROOT_PASS="password" VIRTUALHOST="localhost" CODEIGNITER_PATH="/var/www/codeigniter" PHP_VERSION=7.2 - POSTGRES_VERSION=10 + PGSQL_VERSION=10 grep -q "127.0.0.1 ${VIRTUALHOST}" /etc/hosts || echo "127.0.0.1 ${VIRTUALHOST}" >> /etc/hosts @@ -66,7 +70,7 @@ Vagrant.configure("2") do |config| php$PHP_VERSION apache2 composer \ php-intl php-mbstring php-xml php-zip php-xdebug \ php-mysql mysql-server mysql-client \ - php-pgsql postgresql-$POSTGRES_VERSION \ + php-pgsql postgresql-$PGSQL_VERSION \ php-sqlite3 sqlite3 \ php-memcached memcached \ php-redis redis-server \ @@ -75,28 +79,38 @@ Vagrant.configure("2") do |config| python-pip pip install sphinx sphinxcontrib-phpdomain - python "${CODEIGNITER_PATH}/user_guide_src/cilexer/setup.py" install - pygmentize -L apt-get autoclean + echo "================================================================================" + echo "Preparing User Guide" + echo "================================================================================" + + cd "${CODEIGNITER_PATH}/user_guide_src/cilexer" + python setup.py install + cd .. + make html + echo "================================================================================" echo "Configuring Databases" echo "================================================================================" + sed -i "s/^bind-address/#bind-address/" /etc/mysql/mysql.conf.d/mysqld.cnf mysql -e "CREATE DATABASE IF NOT EXISTS codeigniter COLLATE 'utf8_general_ci'; UPDATE mysql.user SET Host='%' WHERE user='root'; GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION; FLUSH PRIVILEGES;" -uroot -p$MYSQL_ROOT_PASS - sed -i "s/^bind-address/#bind-address/" /etc/mysql/mysql.conf.d/mysqld.cnf systemctl restart mysql - sed -i "s/#listen_addresses = 'localhost'/listen_addresses = '*'/" /etc/postgresql/$POSTGRES_VERSION/main/postgresql.conf - grep -q "host all all all md5" /etc/postgresql/$POSTGRES_VERSION/main/pg_hba.conf || echo "host all all all md5" >> /etc/postgresql/$POSTGRES_VERSION/main/pg_hba.conf - sudo -u postgres psql -tc "SELECT 1 FROM pg_database WHERE datname = 'codeigniter';" | grep -q 1 || sudo -u postgres psql -c "CREATE DATABASE codeigniter;" - sudo -u postgres psql -c "ALTER USER postgres WITH PASSWORD '${POSTGRES_USER_PASS}';" + sed -i "s/^#listen_addresses = 'localhost'/listen_addresses = '*'/" /etc/postgresql/$PGSQL_VERSION/main/postgresql.conf + 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 + 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" + sudo -u postgres psql -c "ALTER ROLE root WITH PASSWORD '${PGSQL_ROOT_PASS}'" + sudo -u postgres psql -tc "SELECT 1 FROM pg_database WHERE datname='codeigniter'" | grep -q 1 ||sudo -u postgres psql -c "CREATE DATABASE codeigniter" + sudo -u postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE codeigniter TO root" systemctl restart postgresql + echo "================================================================================" echo "Configuring Virtual Hosts" echo "================================================================================" @@ -109,11 +123,11 @@ Vagrant.configure("2") do |config| if [ ! -d /home/vagrant/codeigniter ]; then ln -s $CODEIGNITER_PATH /home/vagrant/codeigniter; fi - sed -i "s/APACHE_RUN_USER=www-data/APACHE_RUN_USER=vagrant/" /etc/apache2/envvars - sed -i "s/APACHE_RUN_GROUP=www-data/APACHE_RUN_GROUP=vagrant/" /etc/apache2/envvars - grep -q "Listen 81" /etc/apache2/ports.conf || sed -i "s/Listen 80/Listen 80\\nListen 81\\nListen 82/" /etc/apache2/ports.conf + sed -i "s/^APACHE_RUN_USER=www-data/APACHE_RUN_USER=vagrant/" /etc/apache2/envvars + sed -i "s/^APACHE_RUN_GROUP=www-data/APACHE_RUN_GROUP=vagrant/" /etc/apache2/envvars + grep -q "Listen 81" /etc/apache2/ports.conf || sed -i "s/^Listen 80/Listen 80\\nListen 81\\nListen 82/" /etc/apache2/ports.conf - echo " + echo "ServerName ${VIRTUALHOST} DirectoryIndex index.html index.php Options All From 4426258b0b409322c72ef186d878fb3afedf2962 Mon Sep 17 00:00:00 2001 From: Natan Felles Date: Mon, 19 Nov 2018 01:20:11 -0200 Subject: [PATCH 08/12] Allow external access to Memcached and Redis --- Vagrantfile | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Vagrantfile b/Vagrantfile index d8cc3f04a296..3c92c29cb68a 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -110,6 +110,15 @@ Vagrant.configure("2") do |config| sudo -u postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE codeigniter TO root" systemctl restart postgresql + echo "================================================================================" + echo "Configuring Memcached and Redis" + echo "================================================================================" + + sed -i "s/^bind 127.0.0.1 ::1/#bind 127.0.0.1 ::1/" /etc/redis/redis.conf + sed -i "s/^protected-mode yes/protected-mode no/" /etc/redis/redis.conf + sed -i "s/^-l 127.0.0.1/#-l 127.0.0.1/" /etc/memcached.conf + systemctl restart redis + systemctl restart memcached echo "================================================================================" echo "Configuring Virtual Hosts" From 3bf49714e736d990050d4f94bc09e5ef6181852e Mon Sep 17 00:00:00 2001 From: Natan Felles Date: Mon, 19 Nov 2018 11:34:01 -0200 Subject: [PATCH 09/12] Update Apache config and add optional APT Proxy --- Vagrantfile | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/Vagrantfile b/Vagrantfile index 3c92c29cb68a..b8426935e4da 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -52,9 +52,19 @@ Vagrant.configure("2") do |config| CODEIGNITER_PATH="/var/www/codeigniter" PHP_VERSION=7.2 PGSQL_VERSION=10 + #APT_PROXY="192.168.10.1:3142" grep -q "127.0.0.1 ${VIRTUALHOST}" /etc/hosts || echo "127.0.0.1 ${VIRTUALHOST}" >> /etc/hosts + # Prepare to use APT Proxy + if [ ! -z $APT_PROXY ]; then + if [ ! -f /etc/apt/sources.list-origin ]; then + cp /etc/apt/sources.list /etc/apt/sources.list-origin + fi + sed -i "s/archive.ubuntu.com/${APT_PROXY}/" /etc/apt/sources.list + sed -i "s/security.ubuntu.com/${APT_PROXY}/" /etc/apt/sources.list + fi + export DEBIAN_FRONTEND=noninteractive echo "================================================================================" @@ -114,11 +124,11 @@ Vagrant.configure("2") do |config| echo "Configuring Memcached and Redis" echo "================================================================================" - sed -i "s/^bind 127.0.0.1 ::1/#bind 127.0.0.1 ::1/" /etc/redis/redis.conf - sed -i "s/^protected-mode yes/protected-mode no/" /etc/redis/redis.conf - sed -i "s/^-l 127.0.0.1/#-l 127.0.0.1/" /etc/memcached.conf - systemctl restart redis - systemctl restart memcached + sed -i "s/^bind 127.0.0.1/#bind 127.0.0.1/" /etc/redis/redis.conf + sed -i "s/^protected-mode yes/protected-mode no/" /etc/redis/redis.conf + sed -i "s/^-l 127.0.0.1/#-l 127.0.0.1/" /etc/memcached.conf + systemctl restart redis + systemctl restart memcached echo "================================================================================" echo "Configuring Virtual Hosts" @@ -130,10 +140,13 @@ Vagrant.configure("2") do |config| mkdir -p "${CODEIGNITER_PATH}/writable/apache" chown -R vagrant:vagrant $CODEIGNITER_PATH - if [ ! -d /home/vagrant/codeigniter ]; then ln -s $CODEIGNITER_PATH /home/vagrant/codeigniter; fi + # Creates a symlink in the user home + if [ ! -d /home/vagrant/codeigniter ]; then + ln -s $CODEIGNITER_PATH /home/vagrant/codeigniter + fi - sed -i "s/^APACHE_RUN_USER=www-data/APACHE_RUN_USER=vagrant/" /etc/apache2/envvars - sed -i "s/^APACHE_RUN_GROUP=www-data/APACHE_RUN_GROUP=vagrant/" /etc/apache2/envvars + sed -i "s/APACHE_RUN_USER=www-data/APACHE_RUN_USER=vagrant/" /etc/apache2/envvars + sed -i "s/APACHE_RUN_GROUP=www-data/APACHE_RUN_GROUP=vagrant/" /etc/apache2/envvars grep -q "Listen 81" /etc/apache2/ports.conf || sed -i "s/^Listen 80/Listen 80\\nListen 81\\nListen 82/" /etc/apache2/ports.conf echo "ServerName ${VIRTUALHOST} From a395dd96e7a2088bf0469a6e97f919d522692608 Mon Sep 17 00:00:00 2001 From: Natan Felles Date: Thu, 22 Nov 2018 14:42:01 -0200 Subject: [PATCH 10/12] Display PHP errors --- Vagrantfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Vagrantfile b/Vagrantfile index b8426935e4da..71a71c1910b9 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -148,6 +148,8 @@ Vagrant.configure("2") do |config| sed -i "s/APACHE_RUN_USER=www-data/APACHE_RUN_USER=vagrant/" /etc/apache2/envvars sed -i "s/APACHE_RUN_GROUP=www-data/APACHE_RUN_GROUP=vagrant/" /etc/apache2/envvars grep -q "Listen 81" /etc/apache2/ports.conf || sed -i "s/^Listen 80/Listen 80\\nListen 81\\nListen 82/" /etc/apache2/ports.conf + sed -i "s/^display_errors = Off/display_errors = On/" /etc/php/7.2/apache2/php.ini + sed -i "s/^display_startup_errors = Off/display_startup_errors = On/" /etc/php/7.2/apache2/php.ini echo "ServerName ${VIRTUALHOST} From 73450c83eceb7fe0b061c18cc5dd6d94183fb62a Mon Sep 17 00:00:00 2001 From: Natan Felles Date: Thu, 22 Nov 2018 17:39:04 -0200 Subject: [PATCH 11/12] Up memory to 1024 and add swap to low-memory systems --- Vagrantfile | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/Vagrantfile b/Vagrantfile index 71a71c1910b9..d98a5bbddab0 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -41,7 +41,7 @@ Vagrant.configure("2") do |config| # Display the VirtualBox GUI when booting the machine vb.gui = false # Customize the amount of memory on the VM: - vb.memory = "768" + vb.memory = "1024" end # Provision @@ -56,6 +56,22 @@ Vagrant.configure("2") do |config| grep -q "127.0.0.1 ${VIRTUALHOST}" /etc/hosts || echo "127.0.0.1 ${VIRTUALHOST}" >> /etc/hosts + # Creates a swap file if necessary + RAM=`awk '/MemTotal/ {print $2}' /proc/meminfo` + if [ $RAM -lt 1000000 ] && [ ! -f /swap/swapfile ]; then + echo "================================================================================" + echo "Adding swap" + echo "================================================================================" + echo "This process may take a few minutes. Please wait..." + mkdir /swap + dd if=/dev/zero of=/swap/swapfile bs=1024 count=1000000 + chmod 600 /swap/swapfile + mkswap /swap/swapfile + swapon /swap/swapfile + echo "/swap/swapfile swap swap defaults 0 0" >> /etc/fstab + echo "Done." + fi + # Prepare to use APT Proxy if [ ! -z $APT_PROXY ]; then if [ ! -f /etc/apt/sources.list-origin ]; then From 22775322697c8c336013dbada1a6f72f0ae31bba Mon Sep 17 00:00:00 2001 From: Natan Felles Date: Thu, 6 Dec 2018 06:34:01 -0200 Subject: [PATCH 12/12] Rename Vagrantfile to Vagrantfile.dist --- Vagrantfile => Vagrantfile.dist | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Vagrantfile => Vagrantfile.dist (100%) diff --git a/Vagrantfile b/Vagrantfile.dist similarity index 100% rename from Vagrantfile rename to Vagrantfile.dist