ApisCP Notes and Cheats
website·Indexed 33 days ago
https://notes.apiscp.com/A collection of administration notes, cheatsheets, and guides for ApisCP. Covers topics including PHP memory and PECL module configuration, MariaDB and PostgreSQL upgrades, Podman and Docker container routing, Apache .htaccess rules, and general system administration tasks using cpcmd and Ansible.
What's inside ApisCP
- Xdebug generates profiling data compatible with the Cachegrind format. This data can be analyzed using tools such as KCacheGrind (Linux/KDE), QCacheGrind (Windows), or WebGrind.
Configure WordPress Redis Object Cache plugin for Unix sockets
After creating a Redis instance, install and configure theredis-cacheplugin via WP-CLI. To use a Unix socket instead of a TCP connection, set theWP_REDIS_SCHEMEtounixand provide the absolute path to the socket file inWP_REDIS_PATH.# Switch to the site account and directory su benchmark.test cd /var/www/html # Install and activate the plugin wp-cli plugin install --activate redis-cache # Configure the plugin to use the Unix socket wp-cli config set WP_REDIS_SCHEME unix wp-cli config set WP_REDIS_PATH /var/www/redis.sock # Enable and verify the Redis cache wp-cli redis enable wp-cli redis statusAnalyze site storage and inode usage
You can analyze storage usage using either the system
repquotatool or the ApisCPadmin:get-usage('storage')command.When using
admin:get-usage('storage'), the following keys are used in the output:qused: Storage blocks used, measured in 4 KB units.fused: Inode usage.
# Option 1: Using repquota for virtual home directory repquota -g $(findmnt -no SOURCE --target /home/virtual) | sort -n --key=3 # Option 2: Using cpcmd to sort by storage used (qused) cpcmd -o json admin:get-usage storage | jq 'to_entries | sort_by(.value.qused)'Monitor resource usage by control group with systemd-cgtop
Use
systemd-cgtopto view a top-like interface for all control groups. This is particularly useful for monitoring processes spawned within the context of a site, as they are governed by resource limits assigned in thecgroupservice class. Use the following hotkeys to sort the view:m: Sort by Memoryc: Sort by CPUt: Sort by Tasks (PID count)
Update user preferences without jq using PHP serialization
Ifjqis not installed and cannot be added to the system, you can manipulate preferences by switching the input/output format fromjsontoserialize. This allows you to use a PHP one-liner to unserialize the preferences, modify the array, and re-serialize the data before saving.# Example: set nexus.notify-create value to 1 using PHP serialization cpcmd -i serialize common:save-preferences "$(cpcmd -o serialize common:load-preferences | php -r '$prefs = unserialize(file_get_contents("php://stdin")); $prefs["nexus"]["notify-create"] = 1; echo serialize($prefs);')"Install Podman on ApisCP
Podman is the supported drop-in replacement for RHEL 8+ on ApisCP. Note that Podman may interfere with typical ApisCP behavior by changing firewall rules to accommodate container routing; these rules may be refreshed by the panel, potentially making containers unresponsive when accessing exposed ports from the host or external network.dnf install -y podman /usr/local/apnscp/bin/scripts/yum-post.php install -d podman siteinfo systemctl reload fsmountUpdate user preferences using cpcmd and jq
To modify user preferences, usecpcmdto load preferences in JSON format, manipulate the JSON using thejqutility, and save the modified JSON back. You can masquerade as a specific site using-d domainand/or a specific user using-u userto target the correct preferences.# Install jq if not present yum install -y jq # Example: set nexus.notify-create value to 1 cpcmd -i json common:save-preferences "$(cpcmd -o json common:load-preferences | jq -r '.nexus["notify-create"]=1')"Install Yarn on apiSCP using the apiscp-yarn addin
Yarn can be installed on apiSCP by cloning theapiscp-yarnplaybook addin into the resources directory and executing theaddin.ymlAnsible playbook with the appropriate extra variable.cd /usr/local/apnscp/resources/playbooks git clone https://github.com/thundersquared/apiscp-yarn.git addins/apiscp-yarn ansible-playbook addin.yml --extra-vars=addin=apiscp-yarnCreate a shell shortcut for cross-node command execution
You can create a shell function (e.g., in
~/.bashrc,~/.zshrc, or a separate~/.functionsfile) to wrap the Ansible shell module. This allows you to run a command across all nodes in your inventory by simply calling the function name.Note: The command passed to the function must be a string; any quotes within the command must be escaped to ensure correct execution.
function apiscps() { cd /path/to/panel-management # Replace with your absolute project path echo "ansible all -m shell -a $@" ansible all -m shell -a "$@" } # Usage examples: # Get all panels' version apiscps 'cpcmd misc:cp_version' # Query borg status apiscps 'borgmatic info' # Escape quoted values apiscps "cpcmd scope:set cp.nightly-updates 'Mon..Fri 20:00'" # Shell interpolation apiscps 'dnf remove $(rpm -qa kernel-ml)'Redirect all hostnames to the ApisCP panel hostname
To ensure all hostnames redirect to the primary panel hostname (defined bycpcmd scope:get net.hostname), configure a mod_rewrite rule in the ApisCP custom HTTPD configuration. This prevents access via incorrect hostnames and enforces the use of the primary panel address.# Add to /usr/local/apnscp/config/httpd-custom.conf <Directory ${APNSCP_ROOT}/public> RewriteEngine on RewriteOptions inherit RewriteCond %{HTTP_HOST} ^([^:]+) RewriteCond "%1 %{ENV:HOSTNAME}" "!(^[^ ]*) \1" RewriteRule ^(.*)$ %{REQUEST_SCHEME}://%{ENV:HOSTNAME}:%{SERVER_PORT}/$1 [R,L] </Directory>Restart ApisCP to apply changes
systemctl restart apiscpUpdate plugin paths after cloning WordPress
After cloning a WordPress installation to a new location, manually update the absolute paths to the new WordPress root directory for any plugins that store the root path as a constant in their configuration.Switch from Podman to Docker CE on ApisCP
If Podman's firewall behavior causes issues, you can switch to Docker CE. This process involves removing Podman, installing Docker CE, and applying a systemd unit override to fix theExecStartdefinition. Note that systemd-backed container definitions must be recreated usingdocker runordocker-composeafter the switch.# Remove podman or other docker-related packages dnf remove docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-engine podman runc # Add Docker CE repo dnf config-manager --add-repo https://download.docker.com/linux/rhel/docker-ce.repo # Install docker-ce package dnf install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin # Stop unit for reconfiguration systemctl stop docker # Fix ExecStart definition with a unit override mkdir -p /etc/systemd/system/docker.service.d cat << EOF > /etc/systemd/system/docker.service.d/override.conf [Service] # This clears any ExecStart= inherited from docker.service ExecStart= ExecStart=/usr/bin/dockerd --containerd=/run/containerd/containerd.sock EOF # Reload systemd daemon systemctl daemon-reload # Docker group should be created by default, but just in case groupadd --system docker # Allow docker to be accessible under /.socket echo -e '{\n\t"hosts": ["unix:///var/run/docker.sock", "unix:///.socket/docker.sock"],\n\t"group": "docker"\n}' > /etc/docker/daemon.json # Enable and start the unit systemctl enable --now docker # Verify installation docker ps