노하우 공유

노하우 공유

워드프레스 오토 빌드 스크립트


#!/bin/bash

# Variables (Customize these)
SITE_DOMAIN="example.com"         # Replace with your site domain
DB_NAME="wordpress_db"            # Replace with your database name
DB_USER="wordpress_user"          # Replace with your database username
DB_PASSWORD="securepassword123"   # Replace with your database password
THEME_URL="https://example.com/theme.zip" # Replace with the URL of your WordPress theme
SITE_ROOT="/var/www/$SITE_DOMAIN" # Root directory for your WordPress site

# Update the system
echo "Updating system..."
sudo apt update -y && sudo apt upgrade -y

# Install necessary packages
echo "Installing required packages..."
sudo apt install -y nginx mysql-server php-fpm php-mysql php-cli php-mbstring php-xml php-curl php-zip php-intl unzip curl software-properties-common

# Add PHP repository (for PHP 7.4)
echo "Adding PHP repository..."
sudo add-apt-repository -y ppa:ondrej/php
sudo apt update -y
sudo apt install -y php7.4 php7.4-fpm php7.4-mysql

# Enable and start services
echo "Starting and enabling services..."
sudo systemctl enable nginx
sudo systemctl start nginx
sudo systemctl enable mysql
sudo systemctl start mysql
sudo systemctl enable php7.4-fpm
sudo systemctl start php7.4-fpm

# Secure MySQL Installation
echo "Securing MySQL installation..."
sudo mysql_secure_installation EOF

Y
$DB_PASSWORD
$DB_PASSWORD
Y
Y
Y
Y
EOF

# Create MySQL Database and User
echo "Setting up MySQL database and user..."
sudo mysql -u root -p$DB_PASSWORD <<MYSQL_SCRIPT
CREATE DATABASE $DB_NAME CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
CREATE USER '$DB_USER'@'%' IDENTIFIED BY '$DB_PASSWORD';
GRANT ALL PRIVILEGES ON $DB_NAME.* TO '$DB_USER'@'%';
FLUSH PRIVILEGES;
MYSQL_SCRIPT

# Set up Nginx server block
echo "Configuring Nginx..."
sudo mkdir -p $SITE_ROOT
cat <<EOL | sudo tee /etc/nginx/sites-available/$SITE_DOMAIN
server {
    listen 80;
    server_name $SITE_DOMAIN;

    root $SITE_ROOT;
    index index.php index.html index.htm;

    location / {
        try_files \$uri \$uri/ /index.php?\$args;
    }

    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;
    }
}
EOL

# Enable Nginx site and restart
sudo ln -s /etc/nginx/sites-available/$SITE_DOMAIN /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl restart nginx

# Configure Firewall
echo "Configuring Firewall..."
sudo ufw allow 'Nginx Full'
sudo ufw enable -y

# Download and configure WordPress
echo "Downloading and configuring WordPress..."
curl -o latest.tar.gz https://wordpress.org/latest.tar.gz
tar -xzf latest.tar.gz
sudo mv wordpress/* $SITE_ROOT
rm -rf wordpress latest.tar.gz

# Set WordPress permissions
echo "Setting permissions..."
sudo chown -R www-data:www-data $SITE_ROOT
sudo find $SITE_ROOT -type d -exec chmod 755 {} \;
sudo find $SITE_ROOT -type f -exec chmod 644 {} \;

# Configure wp-config.php
echo "Configuring WordPress wp-config.php..."
sudo cp $SITE_ROOT/wp-config-sample.php $SITE_ROOT/wp-config.php
sudo sed -i "s/database_name_here/$DB_NAME/" $SITE_ROOT/wp-config.php
sudo sed -i "s/username_here/$DB_USER/" $SITE_ROOT/wp-config.php
sudo sed -i "s/password_here/$DB_PASSWORD/" $SITE_ROOT/wp-config.php

# Generate security keys
echo "Generating security keys..."
KEYS=$(curl -s https://api.wordpress.org/secret-key/1.1/salt/)
sudo sed -i "/AUTH_KEY/c\\$KEYS" $SITE_ROOT/wp-config.php

# Download and install WordPress theme
echo "Installing theme..."
curl -o theme.zip $THEME_URL
sudo unzip theme.zip -d $SITE_ROOT/wp-content/themes/
rm theme.zip

# Final restart
echo "Restarting services..."
sudo systemctl restart nginx php7.4-fpm

# Installation Complete
echo "WordPress installation completed!"
echo "Visit: http://$SITE_DOMAIN to finish the WordPress setup through the web interface."
뭐든지 물어보세요.
Select the fields to be shown. Others will be hidden. Drag and drop to rearrange the order.
  • Image
  • SKU
  • Rating
  • Price
  • Stock
  • Availability
  • Add to cart
  • Description
  • Content
  • Weight
  • Dimensions
  • Additional information
Click outside to hide the comparison bar
Compare