-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweb-install.sh
217 lines (164 loc) · 5.57 KB
/
web-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
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
#!/bin/bash
# Update and upgrade Ubuntu
sudo apt update
sudo apt -y upgrade
sudo apt -y dist-upgrade
sudo apt -y autoremove
sleep 0.5
# Again :D
sudo apt -y autoclean
sudo apt -y clean
sudo apt update
sudo apt -y upgrade
sudo apt -y dist-upgrade
sudo apt -y autoremove
# Install Apache2 and its dependencies
sudo apt install -y apache2 php libapache2-mod-php php-mysql php-cli php-common php-curl php-gd php-json php-mbstring php-xml php-zip
sleep 1
# System utilities
sudo apt -y install apt-utils bash-completion busybox ca-certificates cron curl gnupg2 locales lsb-release nano preload screen software-properties-common ufw unzip vim wget xxd zip
sleep 1
# Install MySQL
#sudo apt-get install mysql-server -y
# Enable Apache2 service
sudo systemctl enable apache2
# Start Apache2 service
sudo systemctl start apache2
# Download and extract WordPress
wget https://wordpress.org/latest.tar.gz
tar -xzvf latest.tar.gz
# Stop Apache service
sudo systemctl stop apache2
# Backup default Apache website
sudo mv /var/www/html /var/www/html_backup
# Create a new directory for the WordPress installation
sudo mkdir /var/www/html
# Move WordPress files to web root
#sudo mv ./wordpress/* /var/www/html/
sleep 0.5
# Define the source and destination folders
SRC_FOLDER='./wordpress/*'
DEST_FOLDER='/var/www/html/'
# Move all files and folders in the source folder to the destination folder
sudo mv -f $SRC_FOLDER/* $DEST_FOLDER
cp /var/www/html/wp-config-sample.php /var/www/html/wp-config.php
# Change ownership of web root to www-data
sudo chown -R www-data:www-data /var/www/html/
sudo chmod -R 755 /var/www/html/
#sudo mysql
# ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password by 'password';
# Secure the installation of MySQL
sudo mysql_secure_installation
# Create a new MySQL user for WordPress
# sudo mysql -u root -p
# CREATE DATABASE wordpress;
# CREATE USER 'daniel'@'localhost' IDENTIFIED BY 'password';
# GRANT ALL PRIVILEGES ON *.* TO 'daniel'@'localhost';
# FLUSH PRIVILEGES;
# exit;
# Create a new MySQL database for WordPress
#sudo mysql -u root -p
#CREATE DATABASE wordpress;
#exit;
sleep 0.5
# Define variables for the database name, username, and password
DB_NAME=''
DB_USER=''
DB_PASSWORD=''
# Prompt the user for input
read -p "Enter the WordPress database name: " DB_NAME
read -p "Enter the database username: " DB_USER
#read -s -p "Enter the database password: " DB_PASSWORD
echo # Add a newline after the password input for better formatting
# Check if the user provided values
if [[ -z "$DB_NAME" || -z "$DB_USER" ]]; then
echo "Error: Please provide values for all required fields."
exit 1
fi
sleep 0.5
# Prompt the user to enter the database password twice
while true; do
read -s -p "Enter the database password: " DB_PASSWORD
echo
read -s -p "Confirm the database password: " DB_PASSWORD_CONFIRM
echo
# Check if the passwords match
if [ "$DB_PASSWORD" = "$DB_PASSWORD_CONFIRM" ]; then
break
else
echo "Error: Passwords do not match. Please try again."
fi
done
# You can use these variables in further configuration or installation steps.
echo "Database name: $DB_NAME"
echo "Database username: $DB_USER"
# For security reasons, we won't display the password.
# Define the path to the wp-config.php file
WP_CONFIG_PATH='/var/www/html/wp-config.php'
# Replace the database name, username, and password in the wp-config.php file
#sed -i "s/'DB_NAME', '.*'/'DB_NAME', '$DB_NAME'/" $WP_CONFIG_PATH
#sed -i "s/'DB_USER', '.*'/'DB_USER', '$DB_USER'/" $WP_CONFIG_PATH
#sed -i "s/'DB_PASSWORD', '.*'/'DB_PASSWORD', '$DB_PASSWORD'/" $WP_CONFIG_PATH
# Start Apache2 service
sudo systemctl start apache2
# Check if Apache2 is running
if systemctl is-active --quiet apache2; then
echo "Apache2 is running."
else
echo "Apache2 is not running."
fi
# Check if MySQL is running
if systemctl is-active --quiet mysql; then
echo "MySQL is running."
else
echo "MySQL is not running."
fi
sleep 0.5
# Check if UFW is installed
if ! command -v ufw &> /dev/null; then
echo "UFW is not installed. Attempting to install..."
if [[ $(lsb_release -rs) == "22.04" ]]; then
sudo apt update
sudo apt install ufw
elif [[ $(lsb_release -rs) == "20.04" ]]; then
sudo apt update
sudo apt install ufw
elif [[ $(lsb_release -rs) == "18.04" ]]; then
sudo apt update
sudo apt install ufw
elif [[ -f /etc/redhat-release ]]; then
sudo yum install -y ufw
else
echo "Unsupported Linux distribution. Please install UFW manually."
exit 1
fi
# Enable UFW
sudo ufw enable
echo "UFW has been installed and enabled."
else
echo "UFW is already installed."
fi
# Enable the Uncomplicated Firewall (UFW)
#sudo ufw enable
# Allow SSH (port 22) for remote access
sudo ufw allow 22/tcp comment 'Allow SSH Access'
# Allow HTTP (port 80) for web traffic
sudo ufw allow 80/tcp comment 'Allow HTTP Access'
# Allow HTTPS (port 443) for secure web traffic
sudo ufw allow 443/tcp comment 'Allow HTTPS Access'
# Display the list of rules to confirm the configuration
sudo ufw status
sleep 0.5
# Check if the system needs to reboot
if [ -f /var/run/reboot-required ]; then
echo "The system needs to reboot."
# Ask for confirmation to reboot
read -p "Do you want to reboot now? (y/n) " choice
case "$choice" in
y|Y ) echo "Rebooting now..."; sudo reboot;;
n|N ) echo "Reboot cancelled.";;
* ) echo "Invalid input.";;
esac
else
echo "The system does not need to reboot."
fi