WordPress Hosting Cheatsheet
Table of Contents(GO directly where you need)
🔍 Pre-Deployment Checklist
- Server Requirements
- Ubuntu 20.04/22.04 LTS
- 2+ vCPU, 4GB RAM, 20GB SSD (min)
- Static IP/Domain configured (
nationnowsamachar.com)
- Essential Tools
sudo apt update && sudo apt upgrade -y
sudo apt install git htop ufw snapd rsync unzip -y
🌐 LAMP Stack Installation
1. Apache Web Server
sudo apt install apache2 -y
sudo systemctl enable apache2
sudo ufw allow "Apache Full"
2. MySQL Database
sudo apt install mysql-server -y
sudo mysql_secure_installation
# Follow prompts to set root password and secure DB
3. PHP Processing
sudo apt install php libapache2-mod-php php-mysql \
php-xml php-gd php-curl php-mbstring php-zip -y
🛠️ WordPress Setup Workflow
1. Download WordPress
cd /tmp
wget https://wordpress.org/latest.tar.gz
tar -xzvf latest.tar.gz
2. Deploy to Web Root
sudo rsync -avP /tmp/wordpress/ /var/www/html/yourdomain/
3. Configure Permissions
sudo chown -R www-data:www-data /var/www/html/yourdomain
sudo find /var/www/html/yourdomain -type d -exec chmod 755 {} \;
sudo find /var/www/html/yourdomain -type f -exec chmod 644 {} \;
4. Create MySQL Database
CREATE DATABASE wp_db;
CREATE USER 'wp_user'@'localhost' IDENTIFIED BY 'StrongPassword123!';
GRANT ALL PRIVILEGES ON wp_db.* TO 'wp_user'@'localhost';
FLUSH PRIVILEGES;
EXIT;
5. Apache Virtual Host
/etc/apache2/sites-available/yourdomain.conf:
<VirtualHost *:80>
ServerAdmin admin@yourdomain.com
ServerName yourdomain.com
ServerAlias www.yourdomain.com
DocumentRoot /var/www/html/yourdomain
<Directory /var/www/html/yourdomain>
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
sudo a2ensite yourdomain.conf
sudo a2dissite 000-default.conf
sudo a2enmod rewrite
sudo systemctl restart apache2
🔒 SSL/TLS Configuration (HTTPS)
sudo apt install certbot python3-certbot-apache -y
sudo certbot --apache -d yourdomain.com -d www.yourdomain.com
# Auto-renewal test:
sudo certbot renew --dry-run
⚙️ Post-Installation Essentials
1. wp-config.php Setup
// ** MySQL settings ** //
define('DB_NAME', 'wp_db');
define('DB_USER', 'wp_user');
define('DB_PASSWORD', 'StrongPassword123!');
define('DB_HOST', 'localhost');
// ** Security Keys ** //
define('AUTH_KEY', 'generate_unique_string');
// ... (get keys from: https://api.wordpress.org/secret-key/1.1/salt/)
2. File Permissions Best Practice
sudo chown -R www-data:www-data /var/www/html/yourdomain/wp-content/uploads
sudo find /var/www/html/yourdomain -type d -exec chmod 750 {} \;
sudo find /var/www/html/yourdomain -type f -exec chmod 640 {} \;
3. Cron Job for Automation
# Daily DB backup
0 3 * * * mysqldump -u wp_user -p'password' wp_db > /backups/wp_db_$(date +\%F).sql
🚨 Troubleshooting Toolkit
| Symptom | Command |
|---|---|
| Permission Errors | sudo chown -R www-data:www-data /var/www/html/yourdomain |
| Site Not Loading | sudo tail -50 /var/log/apache2/error.log |
| Database Issues | sudo mysql -u root -p -e "SHOW ENGINE INNODB STATUS" |
| HTTPS Redirect Loop | sudo apachectl configtest && sudo nano /etc/apache2/sites-enabled/yourdomain-le-ssl.conf |
| Plugin Conflicts | cd /var/www/html/yourdomain && mv wp-content/plugins plugins-old && mkdir plugins |
📚 Core Concepts Cheat Sheet
- LAMP Architecture
- Linux: OS foundation
- Apache: Web server handling HTTP requests
- MySQL: Database for dynamic content
- PHP: Processing language for WordPress
- Permission Philosophy
www-datauser owns files → Apache access- 755 for directories (rwx for owner, rx for others)
- 644 for files (rw for owner, r for others)
- Security Hierarchy
graph LR
A[Firewall] --> B[SSH Keys]
B --> C[AppArmor/SELinux]
C --> D[Regular Updates]
D --> E[Backups]
- WP-CLI Magic
# Reset admin password
wp user update admin --user_pass=NewStrongPass123!
# Bulk replace URLs
wp search-replace 'http://oldurl' 'https://newurl' --all-tables
🔄 Deployment Automation Script
#!/bin/bash
# Usage: ./wp-deploy.sh domain.com db_password
DOMAIN=$1
DB_PASS=$2
wget https://wordpress.org/latest.tar.gz
tar -xzf latest.tar.gz
sudo rsync -av wordpress/ /var/www/html/$DOMAIN/
sudo chown -R www-data:www-data /var/www/html/$DOMAIN
mysql -u root -p <<MYSQL_SCRIPT
CREATE DATABASE ${DOMAIN//./_};
CREATE USER '${DOMAIN//./_}'@'localhost' IDENTIFIED BY '$DB_PASS';
GRANT ALL PRIVILEGES ON ${DOMAIN//./_}.* TO '${DOMAIN//./_}'@'localhost';
FLUSH PRIVILEGES;
MYSQL_SCRIPT
certbot --apache -d $DOMAIN -d www.$DOMAIN --non-interactive
echo "✅ Deployment complete! Access: https://$DOMAIN"
📈 Monitoring & Maintenance
- Cockpit Dashboard
sudo apt install cockpit
sudo systemctl enable --now cockpit.socket
sudo ufw allow 9090
Access: https://yourserver:9090
- Essential Cron Jobs
# Weekly WP updates
0 4 * * 1 cd /var/www/html/yourdomain && wp core update && wp plugin update --all
# Security scans
30 2 * * * sudo lynis audit system
Pro Tip: Always test deployments in staging environment! Use
rsync -avP staging:/var/www/html/staging/ /var/www/html/prod/for zero-downtime updates.