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
#!/bin/bash
# Update package list
sudo apt update
# Install NGINX
sudo apt install -y nginx
# Install MySQL and secure installation
sudo apt install -y mysql-server
sudo mysql_secure_installation
# Install PHP and required extensions
sudo apt install -y php-fpm php-mysql
# Configure NGINX to use PHP
sudo mv /etc/nginx/sites-available/default /etc/nginx/sites-available/default_backup
sudo bash -c 'cat > /etc/nginx/sites-available/default <<EOF
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
index index.php index.html index.htm index.nginx-debian.html;
server_name _;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}
EOF'
# Reload NGINX to apply changes
sudo systemctl reload nginx
# Create a test PHP file
echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/info.php
# Install WordPress
sudo apt install -y unzip
wget https://wordpress.org/latest.zip
unzip latest.zip
sudo mv wordpress/* /var/www/html/
sudo chown -R www-data:www-data /var/www/html/
# Cleanup
rm -rf wordpress latest.zip
# Provide instructions to the user
echo "NGINX, MySQL, PHP, and WordPress have been installed successfully."