Comprehensive Guide to Troubleshooting and Managing cPanel/Linux Server Issues Print

  • 0

Maintaining a cPanel/Linux server requires constant monitoring, optimization, and troubleshooting to ensure optimal performance, security, and uptime. This guide walks you through common server issues, their causes, and step-by-step troubleshooting methods to keep your server running efficiently. πŸš€

πŸ” 1. Diagnosing Server Performance Issues

πŸ“ˆ Checking Load Average & CPU Usage

High load average or excessive CPU usage can slow down your server significantly, affecting website speed, application performance, and user experience.

βœ… Check System Load in Real-Time

Run the following commands to monitor system load:

uptime       # Shows system load averages for the past 1, 5, and 15 minutes
top -c       # Displays active processes with CPU and memory usage
htop         # Interactive process viewer for better visualization

πŸ“Š Interpreting Load Average

  • Ideal Load: Should be less than the number of CPU cores.

  • Moderate Load: Equal to CPU cores – nearing saturation.

  • High Load: Exceeds CPU core count, indicating possible performance issues.

πŸ” Identify High-Resource-Consuming Processes

Use these commands to find which processes are consuming the most CPU:

top -o %CPU      # Sort processes by CPU usage in real-time
ps aux --sort=-%cpu | head -10  # Show the top 10 highest CPU-consuming processes

πŸ”§ Find CPU-Intensive Processes by User

To check which user is consuming the most resources:

ps -eo user,%cpu,%mem,cmd --sort=-%cpu | head -10

For a detailed step-by-step guide on diagnosing server performance issues, refer to: πŸ‘‰ Diagnosing Server Performance Issues and Solutions πŸš€

πŸ›  Advanced Performance Monitoring Tools

For deeper performance analysis, use SAR, iotop, and lsof:

βœ… SAR (System Activity Reporter) - Historical Performance Analysis

SAR helps analyze CPU usage trends over time.

πŸ“Œ Install SAR:

yum install sysstat -y   # CentOS/RHEL
apt install sysstat -y   # Ubuntu/Debian

πŸ“Œ Monitor CPU usage every 5 seconds for 10 intervals:

sar -u 5 10

πŸ“Œ Analyze Disk I/O bottlenecks:

sar -d 5 10

πŸ’Ύ iotop - Monitor Disk I/O in Real-Time

When disk read/write operations are high, they can cause server slowdowns. iotop shows which processes are consuming the most I/O.

πŸ“Œ Install iotop:

yum install iotop -y   # CentOS/RHEL
apt install iotop -y   # Ubuntu/Debian

πŸ“Œ Run iotop to monitor real-time disk usage:

iotop -o

πŸ“Œ Find top I/O-consuming processes:

iotop -b -o | head -20

πŸ“‚ lsof - List Open Files and Network Connections

If a server is under high load, checking open files and network connections can help identify issues.

πŸ“Œ Install lsof:

yum install lsof -y   # CentOS/RHEL
apt install lsof -y   # Ubuntu/Debian

πŸ“Œ Find open files for a process (Replace <PID> with actual Process ID):

lsof -p <PID>

πŸ“Œ Check active network connections:

lsof -i

This upgraded version of the section provides: βœ… Better readability
βœ… More diagnostic tools for deeper insights
βœ… Linked reference to a detailed guide

Let me know if you want further enhancements or additional troubleshooting methods! πŸš€


πŸ‘ 2. Memory (RAM) Usage & Swap Optimization

🧠 Checking Memory Usage

Monitor your server’s memory consumption using:

free -m
vmstat 1 5

If swap usage is high, your server may be running out of RAM.

πŸ”§ How to Optimize Memory Usage

  • Increase PHP-FPM max children to prevent excessive memory use per site.

  • Enable OPcache to reduce repeated script execution overhead.

  • Increase MySQL innodb_buffer_pool_size for better database efficiency.


⚑ 3. Slow Website & High Latency Troubleshooting

🌐 Checking Website Performance

Use:

ping domain.com
traceroute domain.com
curl -I domain.com

Look for high response times or packet loss, which may indicate network issues.

Identify slow scripts using strace or by enabling WordPress debug logs.

πŸ‘‰ More details on website speed troubleshooting: Why Is My Website Slow?


πŸ’Ύ 4. Disk Usage & I/O Performance Issues

πŸ“Š Checking Disk Space & Usage

df -h
du -sh /home/*

If /var or /tmp is full, database crashes or mail issues may occur.

Delete unnecessary backups, logs, or cache files to free up space.

πŸ‘‰ Learn how to analyze excessive bandwidth & log usage: Log Analysis & Bandwidth Optimization


⚠ 5. Troubleshooting Common cPanel Issues

πŸ”’ 403/404 Forbidden & Not Found Errors

Check file permissions:

find /home/user/public_html -type d -exec chmod 755 {} \;
find /home/user/public_html -type f -exec chmod 644 {} \;

Ensure the .htaccess file isn’t blocking requests.

Verify ownership of files:

chown -R user:user /home/user/public_html

πŸ’› DNS Issues (Domains Not Resolving Properly)

Check domain DNS settings:

dig domain.com
nslookup domain.com

Ensure nameservers are correct in /etc/resolv.conf.


πŸ”₯ 6. MySQL & Database Issues

βš™οΈ Checking MySQL Service Status

systemctl status mariadb
mysqladmin processlist

If you see Too many connections, increase max_connections in my.cnf.

Optimize slow queries by enabling MySQL slow query logs.

πŸ‘‰ Read more: Diagnosing & Fixing Slow MySQL Queries


πŸš€ 7.Β PHP-FPM & Web Server Optimization: Boosting Server Performance

πŸ” Why PHP-FPM Matters for Server Performance

PHP-FPM (FastCGI Process Manager) is an advanced PHP handler designed to optimize high-performance applications by efficiently managing PHP processes. Unlike traditional PHP handlers (e.g., mod_php), PHP-FPM significantly reduces CPU and memory usage while improving the speed and responsiveness of dynamic websites.

βœ… Key Benefits of PHP-FPM:

  • πŸš€ Better Performance: PHP-FPM efficiently handles concurrent requests, reducing server load.

  • πŸ’Ύ Lower Memory Consumption: Uses process pools to optimize RAM usage.

  • 🎯 Fine-Grained Control: Customizable pools for different domains and applications.

  • πŸ”„ Smooth Scalability: Handles peak loads without service interruptions.

  • πŸ”₯ Increased Security: Runs processes under separate user accounts, improving isolation.

⚑ Optimizing Server Performance Using PHP-FPM

1️⃣ Tune PHP-FPM Configuration

The default PHP-FPM settings may not be optimized for a high-traffic shared server. Modify /etc/php-fpm.d/www.conf or the respective pool configuration files in cPanel, DirectAdmin, or Webuzo.

πŸ”Ή Key Parameters to Optimize:

pm = dynamic
pm.max_children = 150
pm.start_servers = 20
pm.min_spare_servers = 10
pm.max_spare_servers = 50
pm.process_idle_timeout = 10s
pm.max_requests = 500
  • Dynamic Process Management: Adjusts worker processes based on demand.

  • Max Children: Controls how many PHP-FPM workers can run simultaneously.

  • Spare Servers: Maintains idle workers to handle sudden request spikes.

  • Process Timeout: Ensures efficient termination of inactive processes.

2️⃣ Enable OPcache for Faster PHP Execution

opcache.enable=1
opcache.memory_consumption=256
opcache.max_accelerated_files=100000
opcache.validate_timestamps=0
  • OPcache stores precompiled PHP scripts in memory, reducing processing time.

3️⃣ Adjust PHP-FPM Pools for Multiple Websites

Each website can have a separate pool for better resource management. Example for a separate domain:

[example.com]
user = example_user
group = example_group
listen = /run/php-fpm/example.com.sock
pm = ondemand
pm.max_children = 50
pm.process_idle_timeout = 30s
  • Separate pools prevent resource overuse by a single website.

4️⃣ Optimize Web Server Configuration

πŸ”Ή For Apache (cPanel & DirectAdmin):

<IfModule mod_proxy_fcgi.c>
    <FilesMatch "\.php$">
        SetHandler "proxy:unix:/run/php-fpm/example.com.sock|fcgi://localhost"
    </FilesMatch>
</IfModule>
  • Integrates PHP-FPM with Apache for optimized execution.

πŸ”Ή For Nginx (Webuzo & Custom Setups):

location ~ \.php$ {
    fastcgi_pass unix:/run/php-fpm/example.com.sock;
    fastcgi_index index.php;
    include fastcgi.conf;
}
  • Enables efficient PHP handling using PHP-FPM and UNIX sockets.


πŸ“₯ Installation Guide for PHP-FPM in cPanel, DirectAdmin & Webuzo

πŸ”Ή Installing PHP-FPM on cPanel

  1. Log in to WHM.

  2. Navigate to Home > Software > EasyApache 4.

  3. Click Customize on the currently installed profile.

  4. Go to PHP Extensions, search for phpXX-php-fpm, and enable it.

  5. Click Review > Provision.

  6. Enable PHP-FPM for each domain in MultiPHP Manager.

πŸ”Ή Installing PHP-FPM on DirectAdmin

  1. SSH into your server as root.

  2. Edit DirectAdmin custom configuration:

    cd /usr/local/directadmin/custombuild
    ./build set php_fpm yes
    ./build php n
  3. Restart PHP-FPM:

    systemctl restart php-fpm

πŸ”Ή Installing PHP-FPM on Webuzo

  1. Log in to Webuzo Admin Panel.

  2. Navigate to Server Settings > PHP Settings.

  3. Enable PHP-FPM and select the desired PHP version.

  4. Restart Webuzo services:

    service webuzo restart

πŸ†Tips for Maximum Performance

βœ… Keep PHP & PHP-FPM updated. βœ… Use UNIX sockets instead of TCP for faster local connections. βœ… Monitor resource usage with htop, top, or php-fpm -t. βœ… Regularly analyze slow logs to optimize performance. βœ… Fine-tune server parameters based on real-world load patterns.

By optimizing PHP-FPM settings and integrating them with your web server, you can significantly improve performance, reduce resource consumption, and ensure a smooth experience for high-traffic websites. πŸš€πŸ’¨


πŸ›‘οΈ 8. Server Security & Firewall Troubleshooting

πŸ” Checking CSF Firewall & IP Blocks

CSF (ConfigServer Security & Firewall) is a powerful tool for managing firewall rules and blocking malicious activity on your server. To check if an IP is blocked:

csf -g <blocked_ip>
grep "<blocked_ip>" /var/log/lfd.log

If a legitimate user is blocked, whitelist them:

csf -a <ip_address>

πŸ‘‰ Read more: Managing CSF Firewall Blocks

πŸ”₯ Preventing Brute Force Attacks

To prevent unauthorized access attempts, enable Login Failure Daemon (LFD) and monitor logs:

tail -f /var/log/lfd.log

Use Fail2Ban to block repeated login failures:

apt install fail2ban -y  # Ubuntu/Debian
yum install fail2ban -y  # CentOS/RHEL
systemctl enable --now fail2ban

Modify /etc/fail2ban/jail.local to protect SSH and other services:

[sshd]
enabled = true
maxretry = 3
findtime = 600
bantime = 3600

Restart Fail2Ban:

systemctl restart fail2ban

🌐 Mitigating DDoS Attacks with CSF

To mitigate DDoS attacks, adjust CSF configurations:

csf --profile apply /etc/csf/csf.profile
csf --deny <attacker_ip>

Reduce connection limits to prevent excessive connections from a single IP:

echo "CT_LIMIT = "50"" >> /etc/csf/csf.conf
csf -r  # Restart CSF

πŸ‘‰ Read more: Mitigating DDoS Attacks Using CSF

πŸ”’ Additional Security Measures

  • Disable Root Login via SSH to prevent unauthorized access:

    nano /etc/ssh/sshd_config
    PermitRootLogin no
    systemctl restart sshd
  • Enable Two-Factor Authentication (2FA) for cPanel and WHM users.

  • Use ModSecurity (WAF) to block malicious requests:

    a2enmod security2  # Enable ModSecurity (Apache)
    systemctl restart apache2

By implementing these security measures, you can significantly enhance the protection of your cPanel/Linux server against unauthorized access and attacks. πŸš€


🌟 9. Nginx (Reverse Proxy) Management in Popular Control Panels

Nginx is a powerful, high-performance web server and reverse proxy that can significantly enhance server performance when used correctly. Many popular control panels provide built-in or plugin-based Nginx support. This guide covers how to manage Nginx in cPanel, DirectAdmin, and Webuzo, including installation steps and optimization tips.


🌟 Why Use Nginx as a Reverse Proxy?

  • πŸš€ Performance Boost – Handles static content faster than Apache.

  • πŸ”„ Load Balancing – Efficiently distributes requests among backend servers.

  • 🎯 Caching Capabilities – Reduces database queries and enhances speed.

  • πŸ”’ Enhanced Security – Provides protection against DDoS attacks.


πŸ”§ Installation & Management in Popular Control Panels

πŸ› οΈ cPanel (Nginx as Reverse Proxy)

cPanel does not include native support for Nginx, but you can install and manage it using Engintron or the official Nginx Manager Plugin.

βœ… Installing Nginx on cPanel (Engintron Plugin)

cd /; bash <(curl -s https://raw.githubusercontent.com/engintron/engintron/master/engintron.sh)
  • Access WHM > Plugins > Engintron to configure Nginx settings.

πŸ”„ Managing Nginx in cPanel

systemctl restart nginx
systemctl status nginx
  • Restart and check the status of Nginx service.

  • Configure cache settings via Engintron for enhanced performance.


πŸ› οΈ DirectAdmin (Apache + Nginx or Pure Nginx)

DirectAdmin supports Apache + Nginx Hybrid Mode or Standalone Nginx.

βœ… Installing & Configuring Nginx in DirectAdmin

cd /usr/local/directadmin/custombuild
./build set webserver nginx_apache  # Or use 'nginx' for standalone
./build nginx_apache
./build rewrite_confs
  • DirectAdmin will configure Nginx as a proxy or a standalone web server.

πŸ”„ Managing Nginx in DirectAdmin

systemctl restart nginx
systemctl restart apache
  • Restart Nginx and Apache after making changes.

  • Adjust Nginx settings in DirectAdmin > Admin Settings.


πŸ› οΈ Webuzo (Nginx + Apache or Nginx Only)

Webuzo provides an easy way to manage Nginx from the panel or via CLI.

βœ… Enabling Nginx in Webuzo

  1. Log in to Webuzo Admin Panel.

  2. Navigate to Server Settings > Web Server Settings.

  3. Choose Apache + Nginx or Nginx Only.

  4. Click Restart Web Server.

πŸ”„ Managing Nginx via CLI in Webuzo

service nginx restart
service httpd restart
  • Restart Nginx and Apache if required.

  • Configure caching in Webuzo > Nginx Settings.


🌟 Choosing the Right Setup

  • πŸ“ˆ For High-Traffic Websites β†’ Standalone Nginx is recommended.

  • πŸ’‘ For Compatibility with .htaccess β†’ Use Apache + Nginx.

  • ✨ For Easy Control Panel Integration β†’ Use the built-in Nginx options in cPanel, DirectAdmin, or Webuzo.

This guide provides an in-depth look at how to install, manage, and optimize Nginx as a Reverse Proxy in various hosting control panels. Let me know if you need further customizations! πŸš€


🌟  10. Advanced Server Optimization: Managing cPanel, CloudLinux, PHP-FPM, Apache, MySQL & Nginx

Managing a cPanel/Linux server requires routine checks, debugging, logging, and monitoring to maintain smooth operation, optimal performance, and security. This guide covers essential commands, troubleshooting techniques, and solutions to keep your server running efficiently. πŸš€


πŸ–₯️ 1. cPanel Management

βœ… Check cPanel Service Status

service cpanel status

πŸ”„ Restart cPanel Service

service cpanel restart
cd /etc/rc.d/init.d
./cpanel restart

πŸ“œ View cPanel Logs

tail -100 /usr/local/cpanel/logs/error_log
tail -100 /usr/local/cpanel/logs/access_log

πŸ› οΈ Restart Tailwatch Service (cPanel Service Monitoring)

/scripts/restartsrv_chkservd

πŸ”₯ 2. Apache (Web Server) Management

βœ… Check Apache Status & Processes

ps aux | grep httpd
systemctl status httpd
service httpd status

πŸ”„ Restart Apache

/scripts/restartsrv_httpd --restart --hard
/scripts/restartsrv_httpd

πŸ“œ View Apache Logs

tail -100 /var/log/apache2/error_log
tail -100 /etc/apache2/logs/error_log

🚨 Fix Apache Server Name Error

Error: AH00558: httpd: Could not reliably determine the server's fully qualified domain name

Solution:

vi /etc/httpd/conf/httpd.conf  # Edit the Apache configuration file
ServerName localhost  # Add this line
/scripts/restartsrv_httpd  # Restart Apache

πŸ”— Read More: Mastering Apache Execution Models - The Ultimate Comprehensive Guide


πŸ’Ύ 3. MySQL (MariaDB) Management

βœ… Check MySQL Status

service mysqld status
systemctl status mysqld
mysqladmin proc status

πŸ”„ Restart MySQL

/scripts/restartsrv_mysql

πŸ“œ View MySQL Logs

tail -100 /var/log/mysqld.log

🚨 Fix MySQL Connection Issues

Error: ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock'

Solution:

systemctl status mysqld  # Check if MySQL is running
/scripts/restartsrv_mysql  # Restart MySQL service

⚑ 4. PHP-FPM Management

βœ… Check PHP-FPM Status

/scripts/restartsrv_cpanel_php_fpm status

πŸ”„ Restart PHP-FPM

/scripts/restartsrv_cpanel_php_fpm
/scripts/restartsrv_apache_php_fpm

πŸ“œ View PHP-FPM Logs

tail -100 /usr/local/cpanel/logs/php-fpm/error.log

🚨 Fix PHP-FPM Configuration Error

Error: [ERROR] Unable to read FPM configuration file

Solution:

php-fpm -t  # Check the PHP-FPM configuration for syntax errors
vi /etc/php-fpm.conf  # Correct any errors found
/scripts/restartsrv_cpanel_php_fpm  # Restart PHP-FPM

🌐 5. Nginx (Reverse Proxy) Management

βœ… Check Nginx Configuration & Status

nginx -t
systemctl status nginx
apachectl -t

πŸ”„ Restart Nginx

/scripts/restartsrv_nginx --hard

πŸ“œ View Nginx Logs

tail -100 /var/log/nginx/error.log

🚨 Fix Nginx Configuration Error

Error: nginx: [emerg] "server" directive is not allowed here

Solution:

nginx -t  # Validate Nginx configuration
vi /etc/nginx/nginx.conf  # Correct the configuration file
/scripts/restartsrv_nginx --hard  # Restart Nginx

πŸ”’ 6. ModSecurity (WAF) Management

βœ… Check ModSecurity Logs

grep "ModSecurity" /var/log/messages

🚨 Fix ModSecurity Rule Error

Error: ModSecurity: Warning. Pattern match "(?i:(?:<\s*?script|<\s*?img|<\s*?iframe))" at ARGS

Solution:

vi /usr/local/apache/conf/modsec2.user.conf  # Modify or disable the specific rule if necessary

πŸ›‘οΈ 7. CloudLinux Management

βœ… Check CloudLinux Services

cldetect --version  # Check CloudLinux LVE Manager status
cagefsctl --status  # Check CageFS status
service db_governor status  # Check Database Governor status

πŸ”„ Restart CloudLinux Services

service lvestats restart  # Restart LVE Manager
cagefsctl --force-update  # Restart CageFS

πŸ› οΈ Check Overall System Status

systemctl --failed  # Check for failed systemd units
journalctl -xe  # View detailed system logs for errors

πŸ† 8. Kernel Management

πŸ“œ View Kernel Messages

tail -100 /var/log/dmesg

🚨 Check for Out of Memory (OOM) Errors

egrep "oom_reaper|out of memory" /var/log/messages | grep http | tail -25
egrep "out of memory" /var/log/messages | grep http | tail -25

🚨 Identify Killed Process Errors

grep "Killed process" /var/log/messages
grep "oom-killer" /var/log/messages

βœ… Conclusion

By following this guide, you can efficiently diagnose and fix common cPanel/Linux server issues. Regular monitoring, optimization, and security practices will ensure a stable and high-performing server. Bookmark this guide and keep your server running at peak performance! πŸš€


πŸ“– Useful Links for Further Reading:

πŸš€ Stay proactive! Regular maintenance and quick troubleshooting ensure a smooth and high-performing server. 🎯


Was this answer helpful?

« Back