An intelligent, automated WordPress hosting solution for Ubuntu servers with LEMP stack (Linux, Nginx, MariaDB, PHP-FPM) and Redis object caching. This script automatically detects system resources and optimizes configurations accordingly.
- Intelligent Resource Detection: Automatically detects CPU, RAM, and disk space
- Optimized Configuration: Generates PHP, MySQL, Nginx, and Redis configurations based on available resources
- Multiple WordPress Sites: Support for hosting multiple WordPress sites on one server
- SSL/TLS Automation: Automatic SSL certificate installation with Let's Encrypt
- Redis Object Cache: Built-in Redis support for WordPress object caching
- Automated Backups: Scheduled daily backups with configurable retention
- Security Hardening: Firewall configuration, MySQL security, and WordPress hardening
- Interactive Menu: User-friendly menu system for server management
- Performance Monitoring: Built-in monitoring tools for system resources
- Performance Settings Viewer: View all current PHP, MySQL, Nginx, and Redis configurations with detailed reports
- Operating System: Ubuntu 20.04 LTS, 22.04 LTS, or 24.04 LTS
- RAM: Minimum 512MB (1GB+ recommended)
- Disk Space: Minimum 10GB free
- Root Access: Must be run as root or with sudo
git clone <repository-url> wpserver
cd wpserversudo ./build.sh --installThis will:
- Detect your system resources
- Install LEMP stack components (only what's needed)
- Configure services with optimized settings
- Set up security (firewall, MySQL)
- Configure automated backups
- Offer to create your first WordPress site
During installation, you'll be prompted to add your first site. You can also add sites later:
sudo ./build.sh --add-site example.com# Interactive menu
sudo ./build.sh --menu
# Select option 3 → Manage Existing Site → Install SSL
# Or directly:
sudo ./build.sh --add-site example.com
# (SSL installation will be offered during site creation)# Show help
./build.sh --help
# Run full installation
sudo ./build.sh --install
# Launch interactive menu
sudo ./build.sh --menu
# Add new WordPress site
sudo ./build.sh --add-site example.com
# List all sites
./build.sh --list-sites
# Backup all sites
sudo ./build.sh --backup-all
# Show system status
./build.sh --system-status
# View all performance settings
sudo ./build.sh --performance
# Show version
./build.sh --versionLaunch the menu system:
sudo ./build.sh --menu
# Or simply:
sudo ./build.shMenu Options:
- Install New WordPress Site - Create a new WordPress installation
- List All WordPress Sites - View all registered sites
- Manage Existing Site - SSL, backups, removal
- System Status & Monitoring - View resources and service status
- Backup Management - Manual backups, backup list
- Performance Tuning - View all settings, PHP/MySQL/Nginx/Redis configs, clear caches
- Security Management - Firewall, SSL certificates
- Exit - Exit menu system
- Show All Performance Settings - Complete overview of all configurations
- Show PHP Configuration - PHP.ini, FPM pool settings, loaded modules
- Show MySQL Configuration - InnoDB settings, connections, runtime values
- Show Nginx Configuration - Workers, cache, compression, enabled sites
- Show Redis Configuration - Memory settings, persistence, runtime stats
- Recalculate Resources - Re-detect system resources and show allocations
- Clear All Caches - Clear Redis and Nginx FastCGI caches
- Save Configuration Report - Generate timestamped performance report
- Back to Main Menu
The installation follows these phases:
- Verify root privileges
- Check internet connectivity
- Detect operating system (Ubuntu version)
- Verify disk space (minimum 10GB)
- Create directory structure
- Detect CPU cores (for Nginx workers, PHP-FPM processes)
- Detect total RAM (for memory allocation)
- Detect available disk space
- Calculate optimal configuration values
- Check for existing Nginx installation
- Check for MariaDB/MySQL
- Check for PHP and version
- Check for Redis
- Check for Certbot
- Display what will be installed/configured
- Update package lists
- Add required repositories (Ondrej PHP PPA, MariaDB repo)
- Install only missing components:
- Nginx web server
- MariaDB database server
- PHP-FPM and extensions (mysql, curl, gd, mbstring, xml, redis, imagick, opcache, etc.)
- Redis server
- Certbot (Let's Encrypt)
- WP-CLI (WordPress command-line interface)
- Monitoring tools (htop, iotop)
- Generate optimized Nginx configuration
- Generate PHP.ini with calculated memory limits
- Generate PHP-FPM pool with calculated process settings
- Generate MariaDB configuration with InnoDB buffer pool sizing
- Generate Redis configuration with maxmemory settings
- Apply and test all configurations
- MySQL secure installation (automated)
- Configure UFW firewall (allow SSH, HTTP, HTTPS)
- Set secure file permissions
- Disable dangerous PHP functions
- Generate strong random passwords
- Configure automated daily backups (2 AM)
- Setup SSL certificate auto-renewal
- Create monitoring scripts
The script intelligently allocates resources based on available RAM:
- InnoDB Buffer Pool: 400MB
- PHP Max Children: 10
- Redis Memory: 128MB
- PHP Memory Limit: 256MB
- InnoDB Buffer Pool: 800MB
- PHP Max Children: 20
- Redis Memory: 128MB
- PHP Memory Limit: 256MB
- InnoDB Buffer Pool: 1800MB
- PHP Max Children: 30
- Redis Memory: 256MB
- PHP Memory Limit: 384MB
- InnoDB Buffer Pool: 45% of total RAM
- PHP Max Children: 60+
- Redis Memory: 512MB+
- PHP Memory Limit: 512MB
- Nginx Workers: Equal to CPU cores
- PHP-FPM Start Servers: CPU cores × 2
- PHP-FPM Min Spare: CPU cores × 1
- PHP-FPM Max Spare: CPU cores × 3
After installation, you can view and review all current performance configurations:
# View all performance settings at once
sudo ./build.sh --performance
# Or use the alias
sudo ./build.sh --show-settingssudo ./build.sh --menu
# Select option 6: Performance Tuning- Complete Overview - All system resources, calculated allocations, and service status
- PHP Settings - Memory limits, upload sizes, execution times, OPcache, FPM pool configuration, loaded modules
- MySQL/MariaDB Settings - InnoDB buffer pool, log file sizes, max connections, query cache, runtime values
- Nginx Settings - Worker processes, FastCGI cache, gzip compression, client limits, enabled sites
- Redis Settings - Memory limits, eviction policy, persistence status, current memory usage
Generate a detailed timestamped report of all configurations:
sudo ./build.sh --performance
# Then select option 8: Save Configuration ReportReports are saved to /opt/wpserver/logs/performance-report-YYYYMMDD_HHMMSS.txt and include:
- System resources (CPU, RAM, disk)
- All calculated resource allocations
- Complete PHP configuration with file paths
- MySQL/MariaDB settings with runtime values
- Nginx configuration details
- Redis configuration and statistics
- Service status for all components
These reports are useful for:
- Documenting server configuration
- Troubleshooting performance issues
- Planning server upgrades
- Comparing configurations across servers
- Compliance and audit requirements
/opt/wpserver/ # Installation directory
├── build.sh # Main script
├── lib/ # Function libraries
│ ├── core.sh # Logging, utilities
│ ├── detection.sh # System detection
│ ├── install.sh # Package installation
│ ├── config.sh # Configuration generation
│ ├── wordpress.sh # WordPress management
│ ├── ssl.sh # SSL certificates
│ ├── security.sh # Security hardening
│ ├── backup.sh # Backup operations
│ └── menu.sh # Interactive menu
├── scripts/
│ ├── daily-backup.sh # Automated backup script
│ └── monitor.sh # System monitoring
├── config/
│ └── wpserver.conf # Sites registry
├── logs/
│ ├── install.log # Installation log
│ ├── error.log # Error log
│ └── backup.log # Backup log
└── backups/ # Backup storage
├── databases/
└── files/
/var/www/ # WordPress sites
├── example.com/
│ ├── public_html/ # WordPress files
│ ├── logs/ # Site-specific logs
│ └── ssl/ # SSL certificates
After installation, the script generates optimized configurations:
- Nginx Main:
/etc/nginx/nginx.conf - Nginx Sites:
/etc/nginx/sites-available/{domain} - PHP.ini:
/etc/php/{version}/fpm/php.ini - PHP-FPM Pool:
/etc/php/{version}/fpm/pool.d/www.conf - MariaDB:
/etc/mysql/mariadb.conf.d/99-custom.cnf - Redis:
/etc/redis/redis.conf
All passwords and credentials are stored securely:
- Location:
/root/.wpserver-credentials - Permissions: 600 (read/write for root only)
- Contains: Database passwords, MariaDB root password, WordPress admin passwords
sudo ./build.sh --add-site example.comThis will:
- Create directory structure (
/var/www/example.com/) - Create database and user with random secure passwords
- Download latest WordPress
- Generate
wp-config.phpwith Redis support - Create Nginx server block configuration
- Set secure file permissions
- Offer SSL installation
- Display credentials
Use the interactive menu:
sudo ./build.sh --menu
# Select option 3: Manage Existing SiteOr use command-line options to:
- Install SSL certificate
- Create backup
- Remove site (with confirmation)
All WordPress sites are automatically configured for Redis object caching:
// Auto-added to wp-config.php
define('WP_REDIS_HOST', '127.0.0.1');
define('WP_REDIS_PORT', 6379);
define('WP_CACHE', true);To activate, install the "Redis Object Cache" plugin from WordPress admin.
# During site creation, you'll be offered SSL installation
# Or install later:
sudo ./build.sh --menu
# Option 3 → Manage Existing Site → Install SSL Certificate- Certbot requests certificate from Let's Encrypt
- Nginx configuration is updated for HTTPS
- HTTP→HTTPS redirect is configured
- Auto-renewal is set up (certificates renew automatically)
sudo certbot renewAutomatic renewal runs via systemd timer (twice daily).
Backups run automatically at 2 AM daily via cron. Each backup includes:
- Database dump (compressed)
- WordPress files (wp-content directory)
- Nginx configuration
- Backup manifest
Retention: 7 days (configurable in lib/backup.sh)
# Backup all sites
sudo ./build.sh --backup-all
# Backup via menu
sudo ./build.sh --menu
# Option 5: Backup Management/opt/wpserver/backups/{timestamp}_{domain}/
├── database.sql.gz
├── files.tar.gz
├── nginx.conf
└── manifest.txt
sudo /opt/wpserver/scripts/monitor.shShows:
- System resources (CPU, RAM, disk usage)
- Service status (Nginx, MariaDB, PHP-FPM, Redis)
- Connection tests
- WordPress site count
# Check individual services
systemctl status nginx
systemctl status mariadb
systemctl status php8.2-fpm # or your PHP version
systemctl status redis-server
# View logs
tail -f /var/log/nginx/error.log
tail -f /opt/wpserver/logs/error.log-
Firewall (UFW)
- Default deny incoming
- Allow SSH (22), HTTP (80), HTTPS (443)
-
MariaDB Security
- Random strong root password
- Remove anonymous users
- Disable remote root login
- Remove test database
-
WordPress Hardening
- Disable file editing via admin
- Force SSL for admin area
- Secure file permissions (755/644)
- wp-config.php with 440 permissions
-
PHP Security
- Disabled dangerous functions
- OPcache enabled for performance
- Exposed PHP version hidden
-
Nginx Security Headers
- X-Frame-Options
- X-Content-Type-Options
- X-XSS-Protection
- Referrer-Policy
# View firewall status
sudo ufw status verbose
# Add custom rule
sudo ufw allow from 192.168.1.0/24 to any port 3306All WordPress sites are configured with Nginx FastCGI caching:
- Cache path:
/var/cache/nginx - Cache size: 100MB
- Inactive time: 60 minutes
- Automatic cache bypass for admin pages and logged-in users
Enabled by default with optimized settings:
- Memory: 128MB
- Interned strings buffer: 16MB
- Max accelerated files: 10,000
Redis is configured for WordPress object caching:
- Memory limit: Based on server RAM
- Eviction policy: allkeys-lru
- Persistence: Disabled (for caching only)
# Via menu
sudo ./build.sh --menu
# Option 6: Performance Tuning → Clear All Caches
# Or manually
sudo redis-cli FLUSHALL
sudo rm -rf /var/cache/nginx/*
sudo systemctl reload nginxProblem: Package installation fails
# Solution: Update package lists
sudo apt-get update
sudo apt-get upgradeProblem: Service won't start
# Check status and logs
sudo systemctl status nginx
sudo journalctl -u nginx -n 50
# Test configuration
sudo nginx -t
sudo php-fpm8.2 -tProblem: White screen / 500 error
# Check PHP error log
sudo tail -f /var/log/php8.2-fpm.log
# Check Nginx error log
sudo tail -f /var/log/nginx/error.log
# Check site-specific logs
sudo tail -f /var/www/example.com/logs/error.logProblem: Database connection error
# Verify MariaDB is running
sudo systemctl status mariadb
# Test database connection
mysql -u wp_username -p wp_databaseProblem: SSL certificate installation fails
# Check domain DNS
dig example.com
# Verify Nginx configuration
sudo nginx -t
# Check Certbot logs
sudo tail -f /var/log/letsencrypt/letsencrypt.logTo use a different PHP version, modify PHP_MAJOR_VERSION in lib/detection.sh before installation.
Edit the calculate_resources() function in lib/detection.sh to adjust allocation formulas.
No limit on the number of sites. Resources are shared based on initial server capacity calculation.
All operations are logged:
- Installation Log:
/opt/wpserver/logs/install.log - Error Log:
/opt/wpserver/logs/error.log - Backup Log:
/opt/wpserver/logs/backup.log - Nginx Access:
/var/www/{domain}/logs/access.log - Nginx Error:
/var/www/{domain}/logs/error.log
To completely remove the WordPress LEMP server:
# Remove all WordPress sites
sudo rm -rf /var/www/*
# Remove LEMP stack (if desired)
sudo apt-get remove --purge nginx mariadb-server php8.2-fpm redis-server
# Remove wpserver directory
sudo rm -rf /opt/wpserver
sudo rm -f /usr/local/bin/wpserverFor issues, questions, or contributions, please check:
- Installation logs:
/opt/wpserver/logs/install.log - Error logs:
/opt/wpserver/logs/error.log - System monitor:
/opt/wpserver/scripts/monitor.sh
MIT License - See LICENSE file for details
Contributions are welcome! Please submit pull requests or open issues on the repository.
Current Version: 1.0.0