Last active
July 4, 2025 16:50
-
-
Save faermanj/758755a0977341619c0ff52f6711e780 to your computer and use it in GitHub Desktop.
Descomplicando AWS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# sudo -s | |
# This script installs WordPress on an EC2 Amazon Linux 2 instance. | |
yum update -y | |
# Install Apache, MySQL, PHP, and other required packages | |
yum install -y httpd php mariadb1011 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -euxo pipefail | |
### --- CONFIGURATION VARIABLES --- | |
WP_DB_NAME="wordpress_db" | |
WP_DB_USER="wp_user" | |
WP_DB_PASSWORD="wp_pass" | |
WP_DB_HOST="mariadb.example.internal" # Use RDS endpoint or internal IP if on same VPC | |
WP_URL="https://wordpress.org/latest.tar.gz" | |
WP_DIR="/var/www/html" | |
WP_ADMIN_EMAIL="[email protected]" | |
### --- SYSTEM PREPARATION --- | |
yum update -y | |
# Install Apache, PHP, and required modules | |
amazon-linux-extras enable php8.2 | |
yum clean metadata | |
yum install -y httpd php php-mysqlnd php-fpm php-cli php-gd php-json php-mbstring php-xml mariadb curl rsync | |
# Enable and start Apache | |
systemctl enable httpd | |
systemctl start httpd | |
### --- INSTALL WORDPRESS --- | |
# Download and extract latest WordPress | |
curl -L -o /tmp/wordpress.tar.gz $WP_URL | |
tar -xzf /tmp/wordpress.tar.gz -C /tmp | |
rsync -av /tmp/wordpress/ $WP_DIR/ | |
# Set proper ownership | |
chown -R apache:apache $WP_DIR | |
chmod -R 755 $WP_DIR | |
### --- CONFIGURE WORDPRESS (TEMPLATE APPROACH) --- | |
# Remove any existing wp-config and use a template | |
rm -f $WP_DIR/wp-config.php | |
cat <<EOF > $WP_DIR/wp-config.php | |
<?php | |
define( 'DB_NAME', '$WP_DB_NAME' ); | |
define( 'DB_USER', '$WP_DB_USER' ); | |
define( 'DB_PASSWORD', '$WP_DB_PASSWORD' ); | |
define( 'DB_HOST', '$WP_DB_HOST' ); | |
define( 'DB_CHARSET', 'utf8' ); | |
define( 'DB_COLLATE', '' ); | |
/**#@+ | |
* Authentication Unique Keys and Salts. | |
*/ | |
EOF | |
# Fetch and append WordPress secret keys securely | |
curl -s https://api.wordpress.org/secret-key/1.1/salt/ >> $WP_DIR/wp-config.php | |
cat <<'EOF' >> $WP_DIR/wp-config.php | |
$table_prefix = 'wp_'; | |
define( 'WP_DEBUG', false ); | |
/* That's all, stop editing! Happy publishing. */ | |
if ( ! defined( 'ABSPATH' ) ) { | |
define( 'ABSPATH', dirname( __FILE__ ) . '/' ); | |
} | |
require_once ABSPATH . 'wp-settings.php'; | |
EOF | |
# Secure wp-config.php | |
chown apache:apache $WP_DIR/wp-config.php | |
chmod 640 $WP_DIR/wp-config.php | |
### --- ENABLE WORDPRESS ON BOOT --- | |
cat <<EOF > /etc/systemd/system/wordpress-ensure.service | |
[Unit] | |
Description=Ensure WordPress (Apache) is running | |
After=network.target | |
[Service] | |
Type=oneshot | |
ExecStart=/bin/systemctl restart httpd | |
RemainAfterExit=true | |
[Install] | |
WantedBy=multi-user.target | |
EOF | |
systemctl daemon-reexec | |
systemctl daemon-reload | |
systemctl enable wordpress-ensure.service | |
### --- FINAL CHECK --- | |
systemctl restart httpd |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment