-
Notifications
You must be signed in to change notification settings - Fork 14
/
bootstrap.sh
executable file
·148 lines (128 loc) · 11.2 KB
/
bootstrap.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#!/usr/bin/env bash
echo "────────────────────────────────────────────────────────────────────────────────────────────────────────
__________ ___ _____________ _________ ___ __ __ _
\______ \/ | \______ \ / _____/ __________\_ |__ |__|____ _______ __ __| | ________ | |
| ___/ ~ \ ___/ \_____ \ / __ \_ __ \ __ \| \__ \ \_ __ \ | \ | \___ / | |
| | \ Y / | / \ ___/| | \/ \_\ \ |/ __ \_ | | \/ | / |__/ / \|
|____| \___|_ /|____| /_______ /\___ |__| |___ /__(____ / |__| |____/|____/_____ \ __
\/ \/ \/ \/ \/ \/ \/"
echo "────────────────────────────────────────────────────────────────────────────────────────────────────────"
echo "
────────────────────────────────────────────────────────────────────────────────────────────────────────
Sit back, this may take a while: installing PHP7, update and install all tools
────────────────────────────────────────────────────────────────────────────────────────────────────────"
sudo add-apt-repository ppa:ondrej/php >> /dev/null 2>&1
sudo apt-get update >> /dev/null 2>&1
echo "
────────────────────────────────────────────────────────────────────────────────────────────────────────
Installing MySql 5.6 - DB name: unfinished | user:root | password:12345
────────────────────────────────────────────────────────────────────────────────────────────────────────"
sudo debconf-set-selections <<< "mysql-server mysql-server/root_password password 12345"
sudo debconf-set-selections <<< "mysql-server mysql-server/root_password_again password 12345"
sudo apt-get install -y mysql-common mysql-server-5.6 mysql-client-5.6 >> /dev/null 2>&1
mysql -u root -p12345 -e "CREATE DATABASE unfinished;" >> /dev/null 2>&1
echo "
────────────────────────────────────────────────────────────────────────────────────────────────────────
Install PHP 7.0 and rest packages
────────────────────────────────────────────────────────────────────────────────────────────────────────"
sudo apt-get install -y zip unzip >> /dev/null 2>&1
sudo apt-get install -y nginx >> /dev/null 2>&1
sudo apt-get install -y curl git >> /dev/null 2>&1
sudo apt-get install -y php7.0-zip php7.0-fpm php7.0-mcrypt php7.0-curl php7.0-cli php7.0-mysql php7.0-gd php7.0-intl php7.0-xsl php7.0-mbstring >> /dev/null 2>&1
sudo apt-get install -y php-xdebug >> /dev/null 2>&1
echo "
────────────────────────────────────────────────────────────────────────────────────────────────────────
Create appropriate app config: /config/autoload/local.php - change it for local needs
────────────────────────────────────────────────────────────────────────────────────────────────────────"
if [ ! -f /var/www/unfinished/data/phinx/phinx.php ]; then
cp /var/www/unfinished/data/phinx/phinx.php.dist /var/www/unfinished/data/phinx/phinx.php
fi
if [ ! -f /var/www/unfinished/config/autoload/local.php ]; then
cp /var/www/unfinished/config/autoload/local.php.dist /var/www/unfinished/config/autoload/local.php
fi
echo "
────────────────────────────────────────────────────────────────────────────────────────────────────────
Install and run composer
────────────────────────────────────────────────────────────────────────────────────────────────────────"
sudo /bin/dd if=/dev/zero of=/var/swap.1 bs=1M count=1024 >> /dev/null 2>&1
sudo /sbin/mkswap /var/swap.1 >> /dev/null 2>&1
sudo /sbin/swapon /var/swap.1 >> /dev/null 2>&1
cd /tmp/
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" >> /dev/null 2>&1
php composer-setup.php >> /dev/null 2>&1
php -r "unlink('composer-setup.php');"
sudo mv composer.phar /usr/local/bin/composer
cd /var/www/unfinished/
if [ -d "vendor" ]; then
composer update >> /dev/null 2>&1
else
composer install >> /dev/null 2>&1
fi
echo "
────────────────────────────────────────────────────────────────────────────────────────────────────────
Create DB tables and populate it with fake data
────────────────────────────────────────────────────────────────────────────────────────────────────────"
cd /var/www/unfinished/
vendor/bin/phinx migrate -c data/phinx/phinx.php
vendor/bin/phinx seed:run -c data/phinx/phinx.php
# During development log every query in /tmp/mysql.log .. thanks me later
echo "
general_log = on
general_log_file=/tmp/mysql.log
" >> /etc/mysql/my.cnf
# mysql does not need to use that much ram for dev environment
sudo sed -i '/\[mysqld\]/a table_definition_cache=200' /etc/mysql/my.cnf >> /dev/null 2>&1
sudo service mysql restart >> /dev/null 2>&1
echo "
────────────────────────────────────────────────────────────────────────────────────────────────────────
Setup Nginx vhost and change config
────────────────────────────────────────────────────────────────────────────────────────────────────────"
sudo php -r '$f = file_get_contents("/etc/nginx/nginx.conf"); $new_f = str_replace("sendfile on;", "sendfile off; client_max_body_size 12M;", $f); file_put_contents("/etc/nginx/nginx.conf", $new_f);'
sudo touch /etc/nginx/sites-available/unfinished.conf
sudo bash -c "echo 'server {
listen 80;
listen [::]:80;
root /var/www/unfinished/public;
index index.php index.html index.htm;
server_name unfinished.test;
location / {
root /var/www/unfinished/public;
index index.html index.htm index.php;
try_files \$uri \$uri/ /index.php?\$args;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
try_files \$uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
include fastcgi_params;
}
}' > /etc/nginx/sites-available/unfinished.conf"
sudo cp /etc/nginx/sites-available/unfinished.conf /etc/nginx/sites-enabled/
sudo service nginx restart >> /dev/null 2>&1
sudo service php7.0-fpm restart >> /dev/null 2>&1
echo "
────────────────────────────────────────────────────────────────────────────────────────────────────────
change php.ini config
────────────────────────────────────────────────────────────────────────────────────────────────────────"
echo "
error_reporting = E_ALL
display_errors = On
log_errors = On
html_errors = On
error_log = /tmp/php_errors.log
" >> /etc/php/7.0/fpm/php.ini
sudo service nginx restart >> /dev/null 2>&1
sudo service php7.0-fpm restart >> /dev/null 2>&1
echo "
────────────────────────────────────────────────────────────────────────────────────────────────────────
Almost done,
In your /etc/hosts file add line
192.168.33.3 unfinished.test
────────────────────────────────────────────────────────────────────────────────────────────────────────"