-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwp-lemp.sh
259 lines (227 loc) · 9.46 KB
/
wp-lemp.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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
#!/bin/bash
# Author - rootsin
# Version - 1.0.0
installations() {
if [ $(date | awk '{print $2 $3}') != $(ls -al /var/lib/apt/periodic/update-success-stamp | awk '{print $6 $7}') ]
then
apt update -y
fi
apt install -y software-properties-common;
add-apt-repository -y ppa:ondrej/php;
apt update -y;
apt install nginx -y;
apt install php7.4-common php7.4-intl php7.4-curl php7.4-xsl php7.4-mbstring php7.4-xsl php7.4-zip php7.4-soap php7.4-gd php7.4-bcmath php7.4-mysql php7.4-fpm -y;
apt install mysql-server mysql-client -y;
apt install composer -y;
}
conf_php() {
sed -i 's/memory_limit = -1/memory_limit = 2G/g' /etc/php/7.4/cli/php.ini
sed -i 's/max_execution_time = 30/max_execution_time = 1800/g' /etc/php/7.4/cli/php.ini
sed -i 's/zlib.output_compression = Off/zlib.output_compression = On/g' /etc/php/7.4/cli/php.ini
cat /etc/php/7.4/cli/php.ini | grep memory_limit
cat /etc/php/7.4/cli/php.ini | grep max_execution_time
cat /etc/php/7.4/cli/php.ini | grep 'zlib.output_compression ='
sed -i 's/memory_limit = 128M/memory_limit = 2G/g' /etc/php/7.4/fpm/php.ini
sed -i 's/max_execution_time = 30/max_execution_time = 1800/g' /etc/php/7.4/fpm/php.ini
sed -i 's/zlib.output_compression = Off/zlib.output_compression = On/g' /etc/php/7.4/fpm/php.ini
cat /etc/php/7.4/fpm/php.ini | grep memory_limit
cat /etc/php/7.4/fpm/php.ini | grep max_execution_time
cat /etc/php/7.4/fpm/php.ini | grep 'zlib.output_compression ='
service php7.4-fpm restart
}
conf_nginx() {
mkdir -p $root_dir;
if [[ ! -e /etc/nginx/php_loc.conf ]]; then
cat >> /etc/nginx/php_loc.conf << PHP_BLOCK
# pass PHP scripts to FastCGI server
location ~ \.php$ {
root $root_dir;
fastcgi_index index.php;
try_files \$uri =404;
# With php-fpm (or other unix sockets):
fastcgi_pass fastcgi_backend;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
}
PHP_BLOCK
fi
if [[ ! -e /etc/nginx/sites-available/$nginx_conf ]]; then
cp /etc/nginx/sites-available/default /etc/nginx/sites-available/$nginx_conf;
# converting /dir1/dir2/ to \/dir1\/dir2\/, so that it can be added properly in /etc/nginx/sites-available/website conf file
root_dir2=${root_dir////\\/}
cat >> /etc/nginx/sites-available/$nginx_conf.tmp << UPSTREAM
upstream fastcgi_backend {
server unix:/run/php/php7.4-fpm.sock;
}
UPSTREAM
cat /etc/nginx/sites-available/$nginx_conf.tmp /etc/nginx/sites-available/$nginx_conf > /etc/nginx/sites-available/$nginx_conf.new;
mv /etc/nginx/sites-available/$nginx_conf.new /etc/nginx/sites-available/$nginx_conf;
rm -rf /etc/nginx/sites-available/$nginx_conf.tmp;
sed -i "s/fastcgi_pass 127.0.0.1:9000/fastcgi_pass 127.0.0.1:9000;\
\ninclude \/etc\/nginx\/php_loc.conf/g" /etc/nginx/sites-available/$nginx_conf;
sed -i "s/root \/var\/www\/html/root $root_dir2/g" /etc/nginx/sites-available/$nginx_conf;
sed -i "s/index index.html index.htm index.nginx-debian.html/index index.php index.html index.htm index.nginx-debian.html/g" /etc/nginx/sites-available/$nginx_conf;
sed -i "s/\include \/etc\/nginx\/sites-enabled\//include \/etc\/nginx\/sites-enabled\/$nginx_conf;\
\n#/g" /etc/nginx/nginx.conf;
fi
if [[ ! -e /etc/nginx/sites-enabled/$nginx_conf ]]; then
ln -s /etc/nginx/sites-available/$nginx_conf /etc/nginx/sites-enabled/;
fi
if [[ ! -e $root_dir/test.php ]]; then
echo '<?php phpinfo(); ?>' > $root_dir/test.php;
fi
service nginx restart
}
conf_db() {
mysql -h $host -u $rt_user --password=$rt_pw -e "
CREATE DATABASE $db_name;
CREATE USER '$user_name'@'%' IDENTIFIED BY '$pw';
GRANT ALL PRIVILEGES ON $db_name.* TO '$user_name'@'%';
FLUSH PRIVILEGES;"
}
conf_wp() {
cd /root/
if [[ ! -e latest.tar.gz ]]; then
wget http://wordpress.org/latest.tar.gz -O latest.tar.gz
fi
if [[ ! -d wordpress ]]; then
tar xzf latest.tar.gz
fi
cd wordpress
if [[ ! -e wp-config.php ]]; then
cp wp-config-sample.php wp-config.php
sed -i "s/define( 'DB_NAME', 'database_name_here' )/define( 'DB_NAME', '$db_name' )/g" wp-config.php
sed -i "s/define( 'DB_USER', 'username_here' )/define( 'DB_USER', '$user_name' )/g" wp-config.php
sed -i "s/define( 'DB_PASSWORD', 'password_here' )/define( 'DB_PASSWORD', '$pw' )/g" wp-config.php
sed -i "s/define( 'DB_HOST', 'localhost' )/define( 'DB_PASSWORD', '$host' )/g" wp-config.php
# To give permissions to wp-content to install plugins/themes etc
echo "define('FS_METHOD', 'direct');" >> wp-config.php
fi
cd /root/
cp wordpress/* $root_dir -r
mkdir -p $root_dir/wp-content/uploads
chown -R www-data:www-data $root_dir/*
find $root_dir -type d -exec chmod 755 {} \;
find $root_dir -type f -exec chmod 644 {} \;
rm -rf /etc/nginx/sites-enabled/$nginx_conf;
ln -s /etc/nginx/sites-available/$nginx_conf /etc/nginx/sites-enabled/;
service nginx restart;
}
echo "1. To perform all steps 01 to 05 with CUSTOM inputs. (without any reboot)."
echo "2. To perform all steps 01 to 05 quietly with DEFAULT inputs and all log in /root/wordpress_lemp_stack_setup.log (without any reboot)."
echo -e "\nDefault Choice is 2."
if [ -z $1 ]; then
read choice
fi
if [ -z $choice ]; then
choice="$1"
fi
case $choice in
1)
clear
echo "=====================START==========================" > /root/wordpress_lemp_stack_setup.log 2>&1
echo "Updates, Upgrades and Distribution Upgrades" >> /root/wordpress_lemp_stack_setup.log 2>&1
echo "Updating, Upgrading and Installing Distribution Upgrades"
installations >> /root/wordpress_lemp_stack_setup.log 2>&1
echo "Configuring php.ini for nginx and Wordpress" >> /root/wordpress_lemp_stack_setup.log 2>&1
echo "Configuring php.ini for nginx and Wordpress"
conf_php >> /root/wordpress_lemp_stack_setup.log 2>&1
echo "Configuring nginx.conf and sites-available/website for php and Wordpress" >> /root/wordpress_lemp_stack_setup.log 2>&1
echo "Configuring nginx.conf and sites-available/website for php and Wordpress"
echo "Enter location of www-data root directory. . (Default: /var/www/html/website)"
read root_dir
if [ -z $root_dir ]; then
root_dir='/var/www/html/website'
fi
echo "Enter name (only name not location) of configuration file under /etc/nginx/sites-available/. (Default: website)"
read nginx_conf
if [ -z $nginx_conf ]; then
nginx_conf='website'
fi
conf_nginx >> /root/wordpress_lemp_stack_setup.log 2>&1
echo "Creating DB and User" >> /root/wordpress_lemp_stack_setup.log 2>&1
echo "Creating DB and User"
echo "Enter host IP/Endpoint/DNS: (Default: localhost)"
read host
if [ -z $host ]; then
host='localhost'
fi
echo "Enter Master username to make connection to MySQL: (Default: root)"
read rt_user
if [ -z $rt_user ]; then
rt_user='root'
fi
echo "Enter Password of Master username to make connection to MySQL: (Default: NULL/EMPTY)"
read rt_pw
if [ -z $rt_pw ]; then
rt_pw=''
fi
echo 'Enter name of Database you want to be created: (Default: websiteDB)'
read db_name
if [ -z $db_name ]; then
db_name='websiteDB'
fi
echo 'Enter name of User you want to be created: (Default: admin)'
read user_name
if [ -z $user_name ]; then
user_name='admin'
fi
echo "Enter Password for $user_name: (Default: password)"
read pw
if [ -z $pw ]; then
pw='password'
fi
conf_db >> /root/wordpress_lemp_stack_setup.log 2>&1
echo "Downloading and setting up latest Wordpress version" >> /root/wordpress_lemp_stack_setup.log 2>&1
echo "Downloading and setting up latest Wordpress version"
conf_wp >> /root/wordpress_lemp_stack_setup.log 2>&1
echo "======================END===========================" >> /root/wordpress_lemp_stack_setup.log 2>&1
echo "root Directory: $root_dir"
echo "Website's nginx Configuration File: $nginx_conf"
echo "Database Name: $db_name"
echo "Username: $user_name"
echo "Password: $pw"
echo "Database Host: $host"
exit
;;
2)
clear
root_dir='/var/www/html/website'
nginx_conf='website'
db_name='websiteDB'
user_name='admin'
pw='password'
host='localhost'
rt_user='root'
echo "=====================START==========================" > /root/wordpress_lemp_stack_setup.log 2>&1
echo "Updates, Upgrades and Distribution Upgrades" >> /root/wordpress_lemp_stack_setup.log 2>&1
echo "Updating, Upgrading and Installing Distribution Upgrades"
installations >> /root/wordpress_lemp_stack_setup.log 2>&1
echo "Configuring php.ini for nginx and Wordpress" >> /root/wordpress_lemp_stack_setup.log 2>&1
echo "Configuring php.ini for nginx and Wordpress"
conf_php >> /root/wordpress_lemp_stack_setup.log 2>&1
echo "Configuring nginx.conf and sites-available/website for php and Wordpress" >> /root/wordpress_lemp_stack_setup.log 2>&1
echo "Configuring nginx.conf and sites-available/website for php and Wordpress"
conf_nginx >> /root/wordpress_lemp_stack_setup.log 2>&1
echo "Creating DB and User" >> /root/wordpress_lemp_stack_setup.log 2>&1
echo "Creating DB and User"
conf_db >> /root/wordpress_lemp_stack_setup.log 2>&1
echo "Downloading and setting up latest Wordpress version" >> /root/wordpress_lemp_stack_setup.log 2>&1
echo "Downloading and setting up latest Wordpress version"
conf_wp >> /root/wordpress_lemp_stack_setup.log 2>&1
echo "======================END===========================" >> /root/wordpress_lemp_stack_setup.log 2>&1
echo "root Directory: $root_dir"
echo "Website's nginx Configuration File: $nginx_conf"
echo "Database Name: $db_name"
echo "Username: $user_name"
echo "Password: $pw"
echo "Database Host: $host"
exit
;;
*)
loc="$(readlink -f ${BASH_SOURCE[0]})"
echo "Running $loc with Choice 2"
read -p "Press Enter to continue" </dev/tty
bash $loc 2
;;
esac