admin管理员组

文章数量:1125941

I have been looking for automation of a routine task for a long time: deploying a customized WP server with a pre-installed theme and plugins. The server must be on Nginx (optional OpenLightSpeed) + PHP-FPM + MySQL + Redis for caching, etc., in general, everything is according to the manuals, so that a large site (hundreds of thousands of pages) works quickly and without glitches. Well, in theory I can deploy WP with pluging like Duplicator.

Yes, I know about the panels (CyberPanel, Vesta, etc), but I still need to poke around, change something, this takes time and the likelihood of an error if you deploy such sites every day.

For example, I bought a VDS, set the root password, loaded this distribution onto it with my settings and pressed one button in the console and WP ready for add a content.

I have been looking for automation of a routine task for a long time: deploying a customized WP server with a pre-installed theme and plugins. The server must be on Nginx (optional OpenLightSpeed) + PHP-FPM + MySQL + Redis for caching, etc., in general, everything is according to the manuals, so that a large site (hundreds of thousands of pages) works quickly and without glitches. Well, in theory I can deploy WP with pluging like Duplicator.

Yes, I know about the panels (CyberPanel, Vesta, etc), but I still need to poke around, change something, this takes time and the likelihood of an error if you deploy such sites every day.

For example, I bought a VDS, set the root password, loaded this distribution onto it with my settings and pressed one button in the console and WP ready for add a content.

Share Improve this question asked Jan 26, 2024 at 8:17 AstraportAstraport 1215 bronze badges 1
  • Recently started using instawp.io and that should have something you can use to spin up sites from a template. – helgatheviking Commented Jan 30, 2024 at 2:53
Add a comment  | 

1 Answer 1

Reset to default 1

For something like this I would use bash scripting, it works great and will do anything for you.

If we assume that the server environment (Nginx, MySQL, PHP) is already set up and configured, the bash script will focus solely on downloading, installing, and configuring WordPress.

Here's a simplified script for that purpose:

WordPress Installation Bash Script

#!/bin/bash

# Variables
DBNAME='wordpress_db'           # Database name
DBUSER='wordpress_user'         # Database user
DBPASS='your_password'          # Database password
WP_DIR='/var/www/wordpress'     # Directory to install WordPress
URL='http://example.com'        # URL of your WordPress site

# Ensure script is run as root
if [ "$(id -u)" != "0" ]; then
   echo "This script must be run as root" 1>&2
   exit 1
fi

# Download and Extract WordPress
wget https://wordpress.org/latest.tar.gz -O /tmp/latest.tar.gz
tar -xzf /tmp/latest.tar.gz -C /tmp
mv /tmp/wordpress/* $WP_DIR/
rm /tmp/latest.tar.gz
rm -rf /tmp/wordpress

# Set Permissions
chown -R www-data:www-data $WP_DIR
find $WP_DIR -type d -exec chmod 750 {} \;
find $WP_DIR -type f -exec chmod 640 {} \;

# Create WordPress Config
cp $WP_DIR/wp-config-sample.php $WP_DIR/wp-config.php
sed -i "s/database_name_here/$DBNAME/g" $WP_DIR/wp-config.php
sed -i "s/username_here/$DBUSER/g" $WP_DIR/wp-config.php
sed -i "s/password_here/$DBPASS/g" $WP_DIR/wp-config.php

# Set WordPress Salts
SALTS=$(curl -s https://api.wordpress.org/secret-key/1.1/salt/)
printf '%s\n' "g/$put_your_unique_phrase_here/d" a "$SALTS" . w | ed -s $WP_DIR/wp-config.php

# Complete the Installation
echo "WordPress installed successfully. Please complete the installation through the web interface."

# Open the web interface to complete the installation
xdg-open $URL/wp-admin/install.php

Notes:

Modify Variables: Change DBNAME, DBUSER, DBPASS, WP_DIR, and URL according to your setup.

Running the Script: Run this script as root or with sudo privileges. Directory Permissions: The script sets permissions for security. Adjust them if needed.

Completion: The installation is completed through the WordPress web interface.

Execution: Save the script as install_wordpress.sh.

Make it executable: chmod +x install_wordpress.sh.

Run the script: sudo ./install_wordpress.sh.

Always test the script in a non-production environment first to ensure it works as expected with your configuration. This script is a basic guideline and might need adjustments based on your specific server setup.

本文标签: phpHow to create a build for quickly deploying a server with WP