wp-server is a command-line tool for managing common server and site-specific operations. It provides "site" users with simple CLI tools for tasks such as restarting services, managing caches and adjusting timeouts and max upload limits.
-
Clone the repository:
# Login as root or a sudo user cd /opt git clone git@github.com:wpnet/wp-server.git cd wp-server
-
Run the setup script: The setup script will guide you through creating the
api.conffile, which stores the necessary API credentials.bash setup.sh
If you prefer to create the configuration file manually, you can do so by creating a file named
api.confin the/opt/wp-serverdirectory with the following content:API_KEY={YOUR_API_KEY} API_URL={YOUR_API_URL}
To see the list of available commands, run the script with no arguments:
wp-serverThis command restarts a specified service on the server.
Usage:
wp-server restart <service>Available Services:
php: Restarts all PHP-FPM versions.nginxorweb: Restarts the Nginx web server.mysqlordb: Restarts the MySQL database server.redis: Restarts the Redis server.
Example:
# Restart the PHP service
wp-server restart phpThis command sets the PHP max_execution_time and Nginx fastcgi_read_timeout for the current site.
Usage:
wp-server timeout [-s <seconds>]Options:
-s, --set <seconds>: (Optional) Specify the timeout value in seconds. If this option is not provided, the script will attempt to read the existing value from the site's.user.inifile. If no value is found, it will prompt the user to enter one.
Examples:
# Set the timeout to 300 seconds
wp-server timeout -s 300
# Run in interactive mode to view the current timeout or set a new one
wp-server timeoutThis command sets the maximum upload size for PHP and Nginx on the current site.
Behavior:
- If
.user.inicontainsupload_max_filesize, that value is authoritative. - The script will ensure
post_max_sizeis set toupload_max_filesize + 2 MB(updating.user.iniif necessary). - Configuration is written to
/etc/nginx/sites-available/${current_site}/server/client-max-body-size.conf.
Usage:
wp-server max-upload [-m <megabytes>]Options:
-m, --mb <megabytes>: (Optional) Specify the upload size in megabytes. If this option is not provided, the script will attempt to read the existing value from the site's.user.inifile. If no value is found, it will prompt the user to enter one.
Examples:
# Set the max upload size to 256 MB
wp-server max-upload -m 256
# Run in interactive mode to view the current upload size or set a new one
wp-server max-uploadThis command group is for managing the site's cache. These commands are only available if the site has the Cache Control plugin active.
Usage:
wp-server cache <sub-command>Available Sub-commands:
status: Displays the status of the Nginx page cache and the object cache.purge-page: Purges the Nginx page cache for the entire site.purge-object: Flushes the object cache (equivalent towp cache flush).
Example:
# Purge the Nginx page cache
wp-server cache purge-pageDisplays the current version of the wp-server script.
Usage:
wp-server version