56 lines
1.6 KiB
Bash
56 lines
1.6 KiB
Bash
#!/bin/bash
|
|
|
|
# ====== CONFIGURATION ======
|
|
DB_NAME="wordpress"
|
|
DB_USER="wordpressuser"
|
|
DB_PASSWORD="Change-me123@!"
|
|
|
|
# ====== Update & Install Packages ======
|
|
apt update && apt upgrade -y
|
|
apt install -y apache2 mysql-server php libapache2-mod-php php-mysql curl rsync unzip expect
|
|
|
|
mysql_secure_installation
|
|
|
|
systemctl restart apache2
|
|
# ====== Create WordPress Database and User ======
|
|
mysql <<MYSQL_SCRIPT
|
|
CREATE DATABASE ${DB_NAME};
|
|
CREATE USER '${DB_USER}'@'localhost' IDENTIFIED BY '${DB_PASSWORD}';
|
|
GRANT ALL PRIVILEGES ON ${DB_NAME}.* TO '${DB_USER}'@'localhost';
|
|
FLUSH PRIVILEGES;
|
|
MYSQL_SCRIPT
|
|
|
|
# ====== Download and Configure WordPress ======
|
|
cd /tmp
|
|
curl -LO https://wordpress.org/latest.tar.gz
|
|
tar xzvf latest.tar.gz
|
|
cp /tmp/wordpress/wp-config-sample.php /tmp/wordpress/wp-config.php
|
|
|
|
# Replace DB credentials in wp-config.php
|
|
#nano /tmp/wordpress/wp-config.php
|
|
CONFIG_FILE="/tmp/wordpress/wp-config.php"
|
|
|
|
# Backup the original file
|
|
cp "$CONFIG_FILE" "$CONFIG_FILE.bak"
|
|
|
|
# Replace DB_NAME
|
|
sed -i "s/define( 'DB_NAME', '.*' );/define( 'DB_NAME', '$DB_NAME' );/" "$CONFIG_FILE"
|
|
|
|
# Replace DB_USER
|
|
sed -i "s/define( 'DB_USER', '.*' );/define( 'DB_USER', '$DB_USER' );/" "$CONFIG_FILE"
|
|
|
|
# Replace DB_PASSWORD
|
|
sed -i "s/define( 'DB_PASSWORD', '.*' );/define( 'DB_PASSWORD', '$DB_PASSWORD' );/" "$CONFIG_FILE"
|
|
|
|
echo "wp-config.php has been updated."
|
|
# ====== Deploy WordPress ======
|
|
rsync -avP /tmp/wordpress/ /var/www/html/
|
|
chown -R www-data:www-data /var/www/html/
|
|
chmod -R 755 /var/www/html/
|
|
rm -f /var/www/html/index.html
|
|
|
|
# ====== Restart Apache ======
|
|
systemctl restart apache2
|
|
|
|
echo "✅ WordPress installation completed successfully."
|