Updated WP Installer Command

main
Anthony 2025-04-04 22:59:03 +08:00
parent 088e1a08e2
commit 82dc2aad6d
1 changed files with 23 additions and 17 deletions

View File

@ -238,19 +238,18 @@ fi
# Create wp-config.php with the new database credentials
echo -e "${YELLOW}Creating wp-config.php...${NC}"
wp config create \
--dbname="$DB_NAME" \
--dbuser="$DB_USER" \
--dbpass="$DB_PASSWORD" \
--dbhost="$DB_HOST" \
--allow-root
echo -e "${YELLOW}Attempting to use WP-CLI to create config with these parameters:${NC}"
echo -e "Database: $DB_NAME"
echo -e "User: $DB_USER"
echo -e "Password: $DB_PASSWORD"
echo -e "Host: $DB_HOST"
# Verify that wp-config.php was created successfully
if [ ! -f "wp-config.php" ]; then
echo -e "${RED}Failed to create wp-config.php. Attempting alternative method...${NC}"
# Try to create wp-config.php with WP-CLI first (with error output captured)
wp config create --dbname="$DB_NAME" --dbuser="$DB_USER" --dbpass="$DB_PASSWORD" --dbhost="$DB_HOST" --allow-root --debug || {
echo -e "${RED}WP-CLI config create failed. Error code: $?${NC}"
# Try alternative method using direct file creation
echo -e "${YELLOW}Attempting to create wp-config.php manually...${NC}"
# Create wp-config.php manually regardless of whether WP-CLI command succeeded
echo -e "${YELLOW}Creating wp-config.php manually as a fallback...${NC}"
cat > wp-config.php <<EOF
<?php
define( 'DB_NAME', '${DB_NAME}' );
@ -279,13 +278,20 @@ if ( ! defined( 'ABSPATH' ) ) {
require_once ABSPATH . 'wp-settings.php';
EOF
}
# Check if manual creation was successful
if [ ! -f "wp-config.php" ]; then
echo -e "${RED}Failed to create wp-config.php manually. Installation cannot continue.${NC}"
exit 1
fi
echo -e "${GREEN}Successfully created wp-config.php manually.${NC}"
# Verify that wp-config.php was created successfully (either method)
if [ ! -f "wp-config.php" ]; then
echo -e "${RED}CRITICAL ERROR: wp-config.php could not be created by either method.${NC}"
echo -e "${YELLOW}Checking directory permissions:${NC}"
ls -la
echo -e "${YELLOW}Checking if we can write to the directory:${NC}"
touch test_write_access && echo "Write access confirmed" && rm test_write_access
exit 1
else
echo -e "${GREEN}wp-config.php exists. Continuing with installation.${NC}"
# Just to make sure, set the right permissions
chmod 644 wp-config.php
fi
# Set proper permissions