Update updated_install1.sh

This commit is contained in:
RomanNum3ral 2025-05-29 20:03:13 +00:00
parent c18c93c4af
commit 16d2f47818
1 changed files with 21 additions and 56 deletions

View File

@ -1,69 +1,34 @@
#!/bin/bash
# ====== CONFIGURATION ======
HOSTNAME="10.28.24.47" # IP-based access
SITE_CONF="/etc/apache2/sites-available/wordpress.conf"
WEB_ROOT="/srv/www/wordpress"
DB_PASSWORD="changeme123"
# ============================
# Update system
apt update
apt upgrade -y
# Install required packages
apt install -y apache2 ghostscript libapache2-mod-php mysql-server php php-bcmath php-curl php-imagick php-intl php-json php-mbstring php-mysql php-xml php-zip
# Create WordPress directory and download
mkdir -p /srv/www
chown www-data: /srv/www
curl https://wordpress.org/latest.tar.gz | sudo -u www-data tar zx -C /srv/www
apt update && apt upgrade -y
# Configure Apache VirtualHost
cat << EOF | sudo tee "$SITE_CONF" > /dev/null
<VirtualHost *:80>
ServerName $HOSTNAME
DocumentRoot $WEB_ROOT
<Directory $WEB_ROOT>
Options FollowSymLinks
AllowOverride Limit Options FileInfo
DirectoryIndex index.php
Require all granted
</Directory>
<Directory $WEB_ROOT/wp-content>
Options FollowSymLinks
Require all granted
</Directory>
</VirtualHost>
EOF
apt install -y apache2
# Enable site and modules, disable default
a2ensite wordpress.conf
a2enmod rewrite
a2dissite 000-default.conf
systemctl reload apache2
apt install -y mysql-server
# Create WordPress database and user
sudo mysql -u root <<EOF
CREATE DATABASE IF NOT EXISTS wordpress;
CREATE USER IF NOT EXISTS 'wordpress'@'localhost' IDENTIFIED BY '$DB_PASSWORD';
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, ALTER ON wordpress.* TO 'wordpress'@'localhost';
mysql_secure_installation
apt install -y php libapache2-mod-php php-mysql
systemctl restart apache2
mysql
mysql <<EOF
CREATE DATABASE wordpress;
CREATE USER 'wordpressuser'@'localhost' IDENTIFIED BY '$DB_PASSWORD';
GRANT ALL PRIVILEGES ON wordpress.* TO 'wordpressuser'@'localhost';
FLUSH PRIVILEGES;
-- Update WordPress site URLs
USE wordpress;
UPDATE wp_options SET option_value = 'http://$HOSTNAME' WHERE option_name = 'siteurl';
UPDATE wp_options SET option_value = 'http://$HOSTNAME' WHERE option_name = 'home';
EXIT;
EOF
# Create wp-config.php from the sample
sudo -u www-data cp /srv/www/wordpress/wp-config-sample.php /srv/www/wordpress/wp-config.php
cd /tmp
curl -LO https://wordpress.org/latest.tar.gz
tar xzvf latest.tar.gz
# Replace database settings in wp-config.php
sudo -u www-data sed -i "s/database_name_here/wordpress/" /srv/www/wordpress/wp-config.php
sudo -u www-data sed -i "s/username_here/wordpress/" /srv/www/wordpress/wp-config.php
sudo -u www-data sed -i "s/password_here/${DB_PASSWORD}/" /srv/www/wordpress/wp-config.php
# Replace salts in wp-config.php
WP_CONFIG="/srv/www/wordpress/wp-config.php"
sed -i "/AUTH_KEY/d;/SECURE_AUTH_KEY/d;/LOGGED_IN_KEY/d;/NONCE_KEY/d;/AUTH_SALT/d;/SECURE_AUTH_SALT/d;/LOGGED_IN_SALT/d;/NONCE_SALT/d" "$WP_CONFIG"
curl -s https://api.wordpress.org/secret-key/1.1/salt/ >> "$WP_CONFIG"
cp /tmp/wordpress/wp-config-sample.php /tmp/wordpress/wp-config.php
nano /tmp/wordpress/wp-config.php