What this bash script does
- Installs apache2 webserver, mysql-server and PHP required for wordpress
- Enables Apache2 webserver to autostart
- Enables mysql-server to autostart
- Creates a randomly generated mysql DB name
- Creates and randomly generated mysql username and password
- Creates a randomly generated mysql root user password
- Downloads and installs wordpress
- Writes the usernames and passwords to local files /var/log/wpinstall.log
Copy to Clipboard
x
1
#/bin/sh
2
3
install_dir="/var/www/html"
4
#Creating Random WP Database Credenitals
5
db_name="wp`date +%s`"
6
db_user=$db_name
7
db_password=`date |md5sum |cut -c '1-12'`
8
sleep 1
9
mysqlrootpass=`date |md5sum |cut -c '1-12'`
10
sleep 1
11
12
#### Install Packages for https and mysql
13
apt -y install lynx
14
apt -y install apache2
15
apt -y install mysql-server
16
17
####Install PHP
18
apt -y install php
19
apt -y install php-mysql
20
apt -y install php-gd
21
apt -y install php-curl
22
apt -y install php-zip
23
apt -y install php-xml
24
25
26
#### Start http
27
rm /var/www/html/index.html
28
systemctl enable apache2
29
systemctl start apache2
30
31
#### Start mysql and set root password
32
33
systemctl enable mysql
34
systemctl start mysql
35
36
/usr/bin/mysql -e "USE mysql;"
37
/usr/bin/mysql -e "UPDATE user SET Password=PASSWORD($mysqlrootpass) WHERE user='root';"
38
/usr/bin/mysql -e "FLUSH PRIVILEGES;"
39
touch /root/.my.cnf
40
chmod 640 /root/.my.cnf
41
echo "[client]">>/root/.my.cnf
42
echo "user=root">>/root/.my.cnf
43
echo "password="$mysqlrootpass>>/root/.my.cnf
44
45
46
sed -i '0,/AllowOverride\ None/! {0,/AllowOverride\ None/ s/AllowOverride\ None/AllowOverride\ All/}' /etc/apache2/apache2.conf #Allow htaccess usage
47
48
systemctl restart apache2
49
50
####Download and extract latest WordPress Package
51
if test -f /tmp/latest.tar.gz
52
then
53
echo "WP is already downloaded."
54
else
55
echo "Downloading WordPress"
56
cd /tmp/ && wget "http://wordpress.org/latest.tar.gz";
57
fi
58
59
/bin/tar -C $install_dir -zxf /tmp/latest.tar.gz --strip-components=1
60
chown www-data: $install_dir -R
61
62
#### Create WP-config and set DB credentials
63
/bin/mv $install_dir/wp-config-sample.php $install_dir/wp-config.php
64
65
/bin/sed -i "s/database_name_here/$db_name/g" $install_dir/wp-config.php
66
/bin/sed -i "s/username_here/$db_user/g" $install_dir/wp-config.php
67
/bin/sed -i "s/password_here/$db_password/g" $install_dir/wp-config.php
68
69
cat << EOF >> $install_dir/wp-config.php
70
define('FS_METHOD', 'direct');
71
EOF
72
73
cat << EOF >> $install_dir/.htaccess
74
# BEGIN WordPress
75
<IfModule mod_rewrite.c>
76
RewriteEngine On
77
RewriteBase /
78
RewriteRule ^index.php$ – [L]
79
RewriteCond %{REQUEST_FILENAME} !-f
80
RewriteCond %{REQUEST_FILENAME} !-d
81
RewriteRule . /index.php [L]
82
</IfModule>
83
# END WordPress
84
EOF
85
86
chown www-data: $install_dir -R
87
88
##### Set WP Salts
89
grep -A50 'table_prefix' $install_dir/wp-config.php > /tmp/wp-tmp-config
90
/bin/sed -i '/**#@/,/$p/d' $install_dir/wp-config.php
91
/usr/bin/lynx --dump -width 200 https://api.wordpress.org/secret-key/1.1/salt/ >> $install_dir/wp-config.php
92
/bin/cat /tmp/wp-tmp-config >> $install_dir/wp-config.php && rm /tmp/wp-tmp-config -f
93
/usr/bin/mysql -u root -e "CREATE DATABASE $db_name"
94
/usr/bin/mysql -u root -e "CREATE USER '$db_name'@'localhost' IDENTIFIED WITH mysql_native_password BY '$db_password';"
95
/usr/bin/mysql -u root -e "GRANT ALL PRIVILEGES ON $db_name.* TO '$db_user'@'localhost';"
96
97
######Display generated passwords to log file.
98
echo "Database Name: " $db_name
99
echo "Database User: " $db_user
100
echo "Database Password: " $db_password
101
echo "Mysql root password: " $mysqlrootpass
102
103
Github
Download
Copy to Clipboard
1
1
git clone https://github.com/ionos-seth/wp-install