Skip to content

Commit

Permalink
Vagrant box to run Titan Framework's instance on PHP 7.0.
Browse files Browse the repository at this point in the history
Ubuntu 16.04 (Xenial) + Nginx + PostgreSQL 9.5 + PHP 7.0 FPM.
  • Loading branch information
carromeu committed Sep 19, 2016
1 parent 363ed7a commit b177043
Show file tree
Hide file tree
Showing 18 changed files with 4,819 additions and 9 deletions.
14 changes: 14 additions & 0 deletions box-php7/Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Vagrant.configure("2") do |config|
config.vm.box = "bento/ubuntu-16.04"

config.vm.network "forwarded_port", guest: 80, host: 8090
config.vm.network "forwarded_port", guest: 5432, host: 5431

config.vm.network "private_network", ip: "192.168.33.10"

config.vm.synced_folder "../app", "/var/www/app", type: "virtualbox"
config.vm.synced_folder "../db", "/var/lib/postgresql/db", type: "virtualbox"
config.vm.synced_folder ".", "/vagrant", type: "virtualbox"

config.vm.provision "shell", path: "bootstrap.sh"
end
148 changes: 148 additions & 0 deletions box-php7/bootstrap.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
#!/bin/bash

echo "Start provisioner script..."

echo "Changing root password to 'vagrant'..."

passwd <<EOF
vagrant
vagrant
EOF

echo "Done!"

export DEBIAN_FRONTEND=noninteractive

echo "Updating, upgrading and dist upgrading..."

apt-get -y update

apt-get -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" dist-upgrade

apt-get -y upgrade

echo "Done!"

echo "Install a lot of dependencies..."

echo "postfix postfix/mailname string localhost" | debconf-set-selections
echo "postfix postfix/main_mailer_type string 'Internet Site'" | debconf-set-selections

apt-get install -y antiword aptitude build-essential bzip2 curl git locales locate mailutils nginx ntpdate openjdk-9-jre php7.0-fpm php7.0-cli php7.0-curl php7.0-dev php7.0-gd php-imagick php7.0-ldap php7.0-mcrypt php-pear php7.0-pgsql php7.0-sqlite postfix subversion xpdf-utils unzip vim

echo "Done!"

echo "Configuring locales..."

locale-gen "en_US.UTF-8"
locale-gen "es_ES.UTF-8"
locale-gen "pt_BR.UTF-8"

echo -e 'LANG="en_US.UTF-8"\nLANGUAGE="en_US:en"\n' > /etc/default/locale

dpkg-reconfigure --frontend=noninteractive locales

echo "Done!"

echo "Installing PostgreSQL..."

apt-get install -y postgresql-9.5

echo "Done!"

echo "Installing PHP Composer..."

curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer

echo "Done!"

echo "Cleaning apt-get..."

apt-get autoremove
apt-get clean -y
apt-get autoclean -y

find /var/lib/apt -type f | xargs rm -f

find /var/lib/doc -type f | xargs rm -f

echo "Done!"

echo "Creating folders to instance (file, backup and cache)..."

mkdir -p /var/www/app/file
mkdir -p /var/www/app/cache
mkdir -p /var/www/app/backup

echo "Done!"

echo "Configuring services..."

echo "PostgreSQL..."

cp -f /vagrant/settings/pg_hba.conf /etc/postgresql/9.5/main/pg_hba.conf

cp -f /vagrant/settings/postgresql.conf /etc/postgresql/9.5/main/postgresql.conf

/etc/init.d/postgresql restart

echo "Done!"

echo "Nginx and PHP..."

cp -f /vagrant/settings/php-fpm.ini /etc/php/7.0/fpm/php.ini

cp -f /vagrant/settings/php-cli.ini /etc/php/7.0/cli/php.ini

rm -rf /var/www/html

mkdir -p /var/www/log

cp -f /vagrant/settings/nginx-default /etc/nginx/sites-available/default

/etc/init.d/nginx restart

echo "Done!"

echo "SSH..."

cp -f /vagrant/settings/sshd_config /etc/ssh/sshd_config

/etc/init.d/ssh restart

echo "Done!"

echo "CRON..."

cp /vagrant/settings/cron /etc/cron.d/titan

/etc/init.d/cron reload
/etc/init.d/cron restart

echo "Done!"

echo "Getting Titan Framework..."

composer create-project titan-framework/install /var/www/titan

chown -R root:staff /var/www/titan
find /var/www/titan -type d -exec chmod 775 {} \;
find /var/www/titan -type f -exec chmod 664 {} \;

echo "Done!"

echo "Creating DB and importing 'last.db'..."

su - postgres -c "createuser -E titan" > /vagrant/vagrant.log

su - postgres -c "createdb -E utf8 -O titan -T template0 instance" > /vagrant/vagrant.log

su - postgres -c "psql -d instance -U titan < db/last.sql" > /vagrant/vagrant.log

echo "Done!"

echo "Making updatedb command..."

updatedb

echo "All done!"
File renamed without changes.
71 changes: 71 additions & 0 deletions box-php7/settings/nginx-default
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
server {
listen 80 default_server;
listen [::]:80 default_server;

root /var/www/app;

index index.html index.htm index.nginx-debian.html index.php;

server_name _;

location / {
try_files $uri $uri/ =404;
}

location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_buffers 48 4k;
fastcgi_buffer_size 32k;
}

location ~ /(cache/parsed|cache/log|extra|update|configure) {
deny all;
return 403;
}

location ~* \.(git|svn|db|rb|lock|pem|pub|rsa|key|json|log|db|monolog|env|sh|conf|ini|yml|xml|vagrant)$ {
deny all;
return 403;
}

location /password {
rewrite ^/password\/([^\/]+)\/([0-9a-zA-Z_\-]+)\/?$ /titan.php?target=redirect&url=titan.php?target=remakePasswd&login=$1&hash=$2 last;
}

location /alert {
rewrite ^/alert\/([^\/]+)\/([0-9a-zA-Z_\-]+)\/?$ /titan.php?target=redirect&url=titan.php?target=disableAlerts&login=$1&hash=$2 last;
}

location /go {
rewrite ^/go\/([a-zA-Z0-9_\-\.]+)\/?([a-zA-Z0-9_\-\.]*)\/?([0-9]*)\/?$ /titan.php?target=redirect&url=titan.php?toSection=$1&toAction=$2&itemId=$3 last;
}

location /download {
rewrite ^/download\/([0-9]+)\/?$ /titan.php?target=openFile&fileId=$1 last;
}

location /image {
rewrite ^/image\/([0-9]+).png$ /titan.php?target=openFile&fileId=$1 last;
}

location /photo {
rewrite ^/photo\/([0-9]+)_([0-9]+)x([0-9]+)_(0|1).jpg$ /titan.php?target=openFile&fileId=$1&width=$2&height=$3&bw=$4 last;
}

location /thumb {
rewrite ^/thumb\/([0-9]+)_([0-9]+)x([0-9]+).jpg$ /titan.php?target=viewThumb&fileId=$1&width=$2&height=$3 last;
}

location /resource {
rewrite ^/resource\/([a-zA-Z0-9_\-\.]+)\/([a-zA-Z0-9_\-\.\/]+).(css|jpg|jpeg|gif|png|js|ico)$ /titan.php?target=resource&toSection=$1&file=$2.$3 last;
}

location /api {
rewrite ^/api\/([a-zA-Z0-9_\-\.\/\%]+)$ /titan.php?target=api&uri=$1 last;
}

location /rss {
rewrite ^/rss\/([a-zA-Z0-9_\-\.]+)\/?$ /titan.php?target=rss&toSection=$1 last;
}
}
File renamed without changes.
Loading

0 comments on commit b177043

Please sign in to comment.