-
Notifications
You must be signed in to change notification settings - Fork 0
/
wp-auto-install.sh
137 lines (103 loc) · 4.17 KB
/
wp-auto-install.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
#!/bin/bash
#installing wordpress on ubuntu 18.04
#1. update system
#2. ask php and wordpress-version,database-name, database-username, database-password
#3. install php, mysql, nginx and other dependencies
#4. fetch wordpress specified version
#5. extract and copy wordpress to /var/www/html/sitename.com
#6. create database and create user with given details in step 2
#7. modify nginx file and restart nginx
print_version_info(){
cat <<END
1. Php version : $1
2. Wordpress version: $2
3. Database name: $3
4. Datbase usernmae: $4
4. Database password: $5
5. Site Domain Name: $6
END
}
run_sql_commands(){
dbname=$1
dbuname=$2
dbpwd=$3
charset="utf8mb4"
collate="utfmb4_general_ci"
echo "Creating new MySQL database..."
mysql -e "CREATE DATABASE ${dbname} /*\!40100 DEFAULT CHARACTER SET ${charset} COLLATE ${collate}; */;"
echo "Database successfully created!"
echo ""
mysql -e "CREATE USER ${dbuname}@localhost IDENTIFIED BY '${dbpwd}';"
echo "User successfully created!"
echo ""
echo "Granting ALL privileges on ${dbname} to ${dbuname}!"
mysql -e "GRANT ALL PRIVILEGES ON ${dbname}.* TO '${dbuname}'@'localhost';"
mysql -e "FLUSH PRIVILEGES;"
}
#
# script start
#
echo -e "\n\n1.) Which php version you want to install? Example: 7.2"
read vphp
echo -e "\n2.) Which wordpress version you want to install? Example: 5.3.2"
read vwp
echo -e "\n3.) Please enter your database name. Example: mywordpresdb"
read dbname
echo -e "\n4.) Please enter database username. Example: amazingdbuser"
read dbuname
echo -e "\n5.) Please enter database password. "
read dbpwd
echo -e "\n6.) Please enter your site domain name. Example: geekconsults.co.in "
read sitename
echo -e "\n\nPlease keep the above entered information safe and keep it handy as it will be required during wordpress setup."
print_version_info $vphp $vwp $dbname $dbuname $dbpwd $sitename
echo -e "\n\nAre you sure you want to continue installation? y/n"
read -n 1 confirm_install
#exit if not confirm installation
if [[ "$confirm_install" != "y" ]]; then
echo -e "\n\nProgram Terminated..."
exit 0
fi
#
#installtion of dependencies
#
# php 7.1 wp 5.2.3 5.3
sudo apt-get -y install software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt -y update
sudo apt -y upgrade
echo "Installing php${vphp}.."
sudo apt -y install php${vphp}-cli php${vphp}-fpm php${vphp}-mysql php${vphp}-json php${vphp}-opcache php${vphp}-mbstring php${vphp}-xml php${vphp}-gd php${vphp}-curl
echo -e "Php installed successfully!\n"
echo "Installing nginx"
sudo apt -y install nginx
echo "Nginx installed successfully!\n"
echo "Installing mysql-server"
sudo apt -y install mysql-server
echo "Mysql installed successfully!\n"
default_dir=$PWD
#creating database
run_sql_commands $dbname $dbuname $dbpwd
#fetching wordpress
cd /tmp
wget https://wordpress.org/wordpress-$vwp.tar.gz
tar -xzvf wordpress-$vwp.tar.gz
sudo mkdir /var/www/html/$sitename
sudo mv /tmp/wordpress/* /var/www/html/$sitename
sudo chown -R www-data: /var/www/html/$sitename
#Note that Nginx and PHP run as the www-data user and group, hence this is used in the above command.
#Reason : If it were run under root, then all the files would have to be accessible by root and the user would need to be root to access the files. With root being the owner, a compromised web server would have access to your entire system. By specifying a specific ID a compromised web server would only have full access to its files and not the entire server.
#creating nginx site and updating nginx conf file
cd $default_dir
cp nginx.conf /tmp/$sitename
sed -i "s/domain.tld/$sitename/g" /tmp/$sitename
sed -i "s/_vphp_/$vphp/g" /tmp/$sitename
sudo mv /tmp/$sitename /etc/nginx/sites-available/
# cd /etc/nginx/sites-available
sudo ln -s /etc/nginx/sites-available/$sitename /etc/nginx/sites-enabled/
echo "Hurray!! All done. Restarting server..."
sudo systemctl restart nginx
echo -e "\nWordpress installation completed successfully!"
echo -e "\n\nPlease keep the below information safe for future reference."
print_version_info $vphp $vwp $dbname $dbuname $dbpwd $sitename
#copy all creds and version in a text file and tell about that to user