While setting up Apache, PHP, and MySQL gets your server running, true administration begins after installation. Consider this basic server hardening script:
#!/bin/bash
# Basic server hardening
apt update && apt upgrade -y
ufw allow ssh
ufw allow http
ufw allow https
ufw enable
sed -i 's/PasswordAuthentication yes/PasswordAuthentication no/' /etc/ssh/sshd_config
systemctl restart sshd
Implementing monitoring tools is crucial. Here's a simple Prometheus configuration to monitor web server metrics:
global:
scrape_interval: 15s
scrape_configs:
- job_name: 'apache'
metrics_path: '/metrics'
static_configs:
- targets: ['localhost:9117']
- job_name: 'mysql'
static_configs:
- targets: ['localhost:9104']
A robust backup solution combines automation and verification. Here's a cron job example with verification:
0 3 * * * /usr/bin/mysqldump -u backup_user -p'password' --all-databases | gzip > /backups/mysql/$(date +\%Y\%m\%d).sql.gz &&
test $(gunzip -c /backups/mysql/$(date +\%Y\%m\%d).sql.gz | head -n 1 | wc -c) -gt 0 ||
(echo "Backup verification failed" | mail -s "Backup Alert" admin@example.com)
Automating certificate renewal is just the start. Implement this nginx config snippet for optimal security:
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers 'ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384';
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 24h;
ssl_stapling on;
ssl_stapling_verify on;
Apache performance tuning example based on server resources:
StartServers 4
MinSpareServers 4
MaxSpareServers 8
MaxRequestWorkers 150
MaxConnectionsPerChild 10000
# For PHP-FPM with opcache
opcache.enable=1
opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=4000
opcache.revalidate_freq=60
Regular security audits should include checking for vulnerable packages:
#!/bin/bash
# Security audit script
apt list --upgradable | grep security
grep -r "password" /var/www/ --include="*.php" | grep -v "//"
find /var/www/ -type f -perm -o+w -ls
Maintain an up-to-date documentation repository. Use this Markdown template for server documentation:
markdown
# Server: web-prod-01
## Basic Info
- IP: 192.168.1.10
- OS: Ubuntu 20.04 LTS
- Purpose: Primary web server
## Services
- Apache 2.4
- PHP 7.4
- MySQL 8.0
## Important Paths
- Webroot: /var/www/production
- Configs: /etc/apache2/sites-enabled/
- Logs: /var/log/apache2/
## Emergency Contacts
- Hosting Provider: 1-800-XXX-XXXX
- Team Lead: admin@example.com
Setting up a web server with Apache, PHP, and MySQL is just the beginning. A truly skilled administrator goes far beyond installation to ensure security, performance, and reliability. Here's what separates the good from the great.
Effective administrators constantly monitor server health. Tools like Nagios or Prometheus help track:
- CPU/memory usage
- Network traffic patterns
- Disk I/O performance
Example Bash script for basic monitoring:
#!/bin/bash # Simple server monitor while true; do echo "=== $(date) ===" echo "CPU Load: $(uptime)" echo "Memory: $(free -h)" echo "Disk: $(df -h /)" echo "Active connections: $(netstat -an | grep ESTABLISHED | wc -l)" sleep 60 done
Key security practices include:
- Regular patching (implement automated updates)
- Firewall configuration (iptables/nftables)
- SSL/TLS certificate management (Let's Encrypt automation)
Example certbot renewal cron job:
0 3 * * * /usr/bin/certbot renew --quiet --post-hook "systemctl reload apache2"
A robust backup system requires:
- Versioned backups (borg, rsync)
- Off-site storage (AWS S3, Backblaze)
- Regular test restores
Sample backup script:
#!/bin/bash # MySQL backup with rotation BACKUP_DIR="/backups/mysql" DATE=$(date +%Y%m%d) KEEP_DAYS=7 mysqldump -u backup_user -p'password' --all-databases | gzip > "$BACKUP_DIR/db_$DATE.sql.gz" # Rotate old backups find "$BACKUP_DIR" -name "*.sql.gz" -mtime +$KEEP_DAYS -delete
Tuning considerations:
- Apache/Nginx worker configuration
- PHP-FPM process management
- MySQL query caching and indexing
Example MySQL my.cnf optimizations:
[mysqld] innodb_buffer_pool_size = 4G query_cache_size = 128M max_connections = 200 slow_query_log = 1
The best administrators automate everything possible:
- Configuration management (Ansible, Puppet)
- Deployment pipelines (CI/CD)
- Monitoring alerts (PagerDuty integration)
Sample Ansible playbook snippet:
- hosts: webservers become: yes tasks: - name: Ensure Apache is installed apt: name: apache2 state: latest - name: Enable mod_rewrite apache2_module: name: rewrite state: present notify: restart apache handlers: - name: restart apache service: name: apache2 state: restarted
Stay updated with:
- Security mailing lists (OSS-Security, Bugtraq)
- Technology blogs (DigitalOcean, Linode)
- Community forums (Server Fault, Stack Overflow)