Category: Cpanel

  • Enable WebSocket in Cpanel Server with Nginx

    Enable WebSocket in Cpanel Server with Nginx

    On a Cpanel server, WebSocket server was running on port 8080. It worked fine with HTTP. After enabling HTTPS, it stopped working.

    The website code had the following entry

    var websocket_server = new WebSocket("ws://domain.com:8080");
    

    This Cpanel server had ea-nginx (Nginx provided by Cpanel) installed.

    To fix the error, I created a file

    vi /etc/nginx/conf.d/ws-domain.com.conf
    

    In the above, replace domain.com with the actual domain name.

    Add following content

    map $http_upgrade $connection_upgrade {
        default upgrade;
        '' close;
    }
    
    upstream websocket {
        server 127.0.0.1:8080;
    }
    

    Create file

    vi /etc/nginx/conf.d/users/CPANEL_USER/domain.com/wss.conf
    

    Replace CPANEL_USER with the actual Cpanel user name for the website. domain.com with real domain name,

    Add following

    location /wsapp/ {
        proxy_pass http://websocket;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $connection_upgrade;
        proxy_set_header Host $host;
    }
    

    Restart nginx

    systemctl restart nginx
    

    In your application code, find

    var websocket_server = new WebSocket("ws://domain.com:8080");
    

    Replace with

    var websocket_server = new WebSocket("wss://domain.com/wsapp/NNN");
    

    See Cpanel Server

  • Ubuntu Cpanel Can’t locate FindBin.pm in @INC

    Ubuntu Cpanel Can’t locate FindBin.pm in @INC

    Cpanel control panel recently started supporting Ubuntu Operating System. Ubuntu support was announced after RedHat stopped supporting RHEL-based CentOS. When I install Cpanel on Ubuntu 20.04 server, I got the following error message

    Can't locate FindBin.pm in @INC (you may need to install the FindBin module) (@INC contains: /etc/perl /usr/local/lib/x86_64-linux-gnu/perl/5.30.0 /usr/local/share/perl/5.30.0 /usr/lib/x86_64-linux-gnu/perl5/5.30 /usr/share/perl5 /usr/lib/x86_64-linux-gnu/perl/5.30 /usr/share/perl/5.30 /usr/local/lib/site_perl /usr/lib/x86_64-linux-gnu/perl-base) at /home/cPanelInstall/selfgz1202/install line 12.
    BEGIN failed--compilation aborted at /home/cPanelInstall/selfgz1202/install line 12.
    Ubuntu Cpanel FindBin error

    To fix the error install package “libfindbin-libs-perl” with apt

    sudo apt install libfindbin-libs-perl

    Back to Cpanel Server

  • How to Increase size of /tmp on cpanel server

    How to Increase size of /tmp on cpanel server

    To increase the size of /tmp folder, first, stop monitoring services, so it won’t get auto started while we resize /tmp folder

    whmapi1 configureservice service=cpsrvd enabled=1 monitored=0
    whmapi1 configureservice service=mysql enabled=1 monitored=0
    whmapi1 configureservice service=httpd enabled=1 monitored=0
    

    Now stop Cpanel, MySQL and Apache services

    /scripts/restartsrv_cpsrvd --stop
    /scripts/restartsrv_mysql --stop
    /scripts/restartsrv_httpd --stop
    

    Unmout current /tmp folder

    umount /tmp
    

    Rename tmp file

    mv /usr/tmpDSK /usr/tmpDSK.old
    

    Create a new file

    dd if=/dev/zero of=/usr/tmpDSK bs=1024 count=10000000
    mkfs.ext3 /usr/tmpDSK
    

    This will create a 10 GB /tmp folder. If you need to change the size, adjust “count=10000000”.

    Now you can mount the /tmp folder with the command

    mount -a
    

    Or

    mount -o loop,noexec,nosuid,rw /usr/tmpDSK /tmp
    

    Start the services

    /scripts/restartsrv_cpsrvd --start
    /scripts/restartsrv_mysql --start
    /scripts/restartsrv_httpd --start
    

    Enable monitoring

    whmapi1 configureservice service=cpsrvd enabled=1 monitored=1
    whmapi1 configureservice service=mysql enabled=1 monitored=1
    whmapi1 configureservice service=httpd enabled=1 monitored=1
    

    Your /etc/fstab will have the following entry for /tmp folder

    /usr/tmpDSK             /tmp                    ext3    defaults,noauto        0 0
    

    If you want the default size, that works for most, you can use Cpanel provided script.

    /scripts/securetmp
    

    Running this script will auto-create /tmp folder with 4 GB size.

    Back to Cpanel Server

  • How to install  PHP ssh2 module in Cpanel Server

    How to install PHP ssh2 module in Cpanel Server

    PHP ssh2 module allows you to connect to SSH servers. On Cpanel servers, this module is not available under EasyApache. You need to install using PECL. The PECL module installer in WHM does not list this module. The module is available to download from

    https://pecl.php.net/package/ssh2

    To install it, log in to the Cpanel server as SSH user root or login to WHM as user root, go to Terminal.

    Run the command

    /opt/cpanel/ea-php74/root/bin/pecl install ssh2-1.3.1
    

    This will install ssh2 module for PHP 7.4.

    For PHP 8.0, you can run

    /opt/cpanel/ea-php80/root/bin/pecl install ssh2-1.3.1

    You can also specify the full download URL for the SSH2 module like

    /opt/cpanel/ea-php74/root/bin/pecl install https://pecl.php.net/get/ssh2-1.3.1.tgz

    If you need to install SSH module for another PHP version, change ea-php74 to whatever PHP version you are using. Make sure you select the appropriate ssh2 module version that works with the PHP version you are using.

    After installing, restart Apache with

    systemctl restart httpd

    To verify the ssh2 module is installed, create a PHP file with phpinfo() function, you will see.

    Cpanel php-ssh2 module phpinfo

    Back to Cpanel Server

  • Install Cpanel Control Panel

    To install the Cpanel/WHM control panel, run the following command as user root.

    cd /home && curl -o latest -L https://securedownloads.cpanel.net/latest && sh latest
    

    If you are installing on Ubuntu 20.04 and get the following error

    Can't locate FindBin.pm in @INC (you may need to install the FindBin module) 
    (@INC contains: /etc/perl /usr/local/lib/x86_64-linux-gnu/perl/5.30.0 /usr/local/share/perl/5.30.0 
    /usr/lib/x86_64-linux-gnu/perl5/5.30 /usr/share/perl5 /usr/lib/x86_64-linux-gnu/perl/5.30
     /usr/share/perl/5.30 /usr/local/lib/site_perl /usr/lib/x86_64-linux-gnu/perl-base) 
    at /home/cPanelInstall/selfgz1630/install line 12.
    BEGIN failed--compilation aborted at /home/cPanelInstall/selfgz1630/install line 12.
    

    Install package “libfindbin-libs-perl”.

    apt install -y libfindbin-libs-perl
    

  • Set Time in Cpanel Server

    Set Time in Cpanel Server

    In Cpanel Server, you can set Time Zone in WHM once you logged in as user root. If you have WHM reseller access you won’t be able to set server time. You need to contact the server administrator with root access to set the time.

    Go to

    Home > Server Configuration > Server Time
    

    You can also use the search box on the top-left corner of WHM. Search for “time”.

    On the Server Time page, you can change the server time zone.

    Cpanel WHM server time

    From the Dropdown menu, select the desired time zone you want.

    Click the button “Change TimeZone” to change the time zone.

    If you have customers from different countries, it is better to select time zone UTC (GMT + 0) as it is universal time Most PHP applications have the option to offset time from UTC and display the local time for users.

    Once the time zone is set, click on the button “Sync Time with Time Server”. This will update server time.

    Back to Cpanel Server Setup

  • How To See Currently Running Processes in Cpanel/WHM Server

    How To See Currently Running Processes in Cpanel/WHM Server

    To see the currently running process on Cpanel/WHM server, log in to WHM.

    Search for “process” on the left-top corner search box.

    CPanel WHM process

    Under System health, click on “Process Manager”

    WHM > System Health > Process Manager
    

    Cpanel Process Manager

    This page list all running process. On the left of each process, you have the option to kill a process and trace.

    The “trace” option allows you to see what the process is doing. It uses strace command to attach a process and show the result.

    kill option allows you to kill a process. There is an option to kill all processes owned by a specific user.

    On the left menu, there is another link “Show Current Running Processes”, this just shows a read-only process list. You won’t be able to interact with it.

    Another option is to search for “terminal” in WHM, click on Terminal Link. This will open the Terminal connection to the server, here you can run Linux commands. You can use the following Linux commands to see the running process.

    ps aux
    top
    

    Back to Cpanel Server

  • Disable catch-all email on Cpanel Server

    To disable catch-all email address for all sites hosted on Cpanel Server, run

    sed -i 's/^\*: [^ ]*$/*: :fail: ADDRESS DOES NOT EXIST/g' /etc/valiases/*
    

    Back to Cpanel Server

  • How to fix Cpanel Server shared IP address show customer site

    On a Cpanel Server, when you visit a shared IP address used by multiple websites, you will see the website of the first VirtualHost entry. This is not good when you have multiple customer websites as your other customers may visit the IP and see the site associated with the first VirtualHost entry and complain about this. I had customers reporting that their site is hacked when this happened to them.

    The solution is to add a VirtualHost entry for the IP address. So when visitors use IP address, that VirtualHost shows up.

    On Cpanel Server, you can do this by editing

    vi /etc/apache2/conf.d/includes/pre_virtualhost_global.conf
    

    Add content

    
    DocumentRoot /var/www/html
    
    
    
    DocumentRoot /var/www/html
    
    suPHP_UserGroup nobody nobody
    
    
    AllowOverride All
    
    
    SSLEngine on
    
    SSLCertificateFile /var/cpanel/ssl/cpanel/cpanel.pem
    SSLCertificateKeyFile /var/cpanel/ssl/cpanel/cpanel.pem
    SSLCertificateChainFile /var/cpanel/ssl/cpanel/cpanel.pem
    SSLUseStapling Off
    
    
    
    SecRuleEngine On
    
    
    

    In the above code, replace YOUR_SERVER_IP_HERE with your actual server IP address. If you have multiple IP addresses, repeat the code above for each of your IP addresses.

    Now restart Apache

    systemctl restart httpd
    

    See Cpanel Server

  • How To Add an Additional IP Address in cPanel Server

    How To Add an Additional IP Address in cPanel Server

    Cpanel servers allow you to add multiple IP addresses. Additional IP addresses are useful for running name servers, hosting sites on different IP addresses (many use dedicated IP for SEO), and mail servers. Before you can add additional IP addresses to a server, you need it purchased from your server provider.

    To add an IP address, log in to WHM of your server by going to

    http://your-server-ip/whm
    

    After login, click on

    IP Functions > Add a New IP Address
    

    WHM IP functions

    On the next page, you will get a form, where you can add the IP address.

    cpanel server add ip

    Enter your IP address in the text box “New IP or IP range to add:”. Then select the netmask from the select box below. Netmask and IP address will be provided by your server hosting provider. Generally, netmask will be 255.255.255.0, some providers recommend you to use 255.255.255.255.

    Click on Submit button to add IP address.

    To verify IP address working properly, you can ping to the IP or visit the IP address in a web browser, you should see the default Cpanel page.

    See Cpanel Server

  • CPanel  SSL Renew on password protected site

    CPanel SSL Renew on password protected site

    We have a site where we host demo websites that we do for our customers. We don’t want search engines to index these sites or strangers to see them. So it is password protected. The problem is Cpanel Auto SSL needs to access URI like /.well-known/ for SSL domain validation. With password protection, SSL domain verification fails and you won’t be able to renew the SSL certificate.

    In this post, I am doing it for domain demo.hostonnet.com with Cpanel username hostond.

    cpanel password protected site ssl

    Redirect HTTP to HTTPS

    I want to force all buy SSL verification requests to get redirected to HTTPS. For this, i created a folder

    mkdir -p /etc/apache2/conf.d/userdata/std/2_4/hostond/demo.hostonnet.com/
    

    Now create a file

    vi /etc/apache2/conf.d/userdata/std/2_4/hostond/demo.hostonnet.com/force-ssl.conf
    

    Add following content to it.

    RewriteEngine On 
    RewriteCond %{REQUEST_URI} !^/\.well-known/
    RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]
    

    This will redirect all requests that do not start with URI .well-known to HTTPS.

    Password Protect site

    Since HTTP only allows domain validation (pages inside folder .well-known) and redirects all other requests to HTTPS, we only need to password protect the HTTPS side of the website.

    First, create a directory

    mkdir -p /etc/apache2/conf.d/userdata/ssl/2_4/hostond/demo.hostonnet.com/
    

    Create file

    vi /etc/apache2/conf.d/userdata/ssl/2_4/hostond/demo.hostonnet.com/password.conf
    

    Add following content

    
        AuthType Basic
        AuthName "Restricted Content"
        AuthUserFile /etc/apache2/demo-hon-htpaswd
        Require valid-user
    
    

    Setting Password

    HTTP Basic authentication password is stored in file /etc/apache2/demo-hon-htpaswd. To set password, use htpasswd command.

    To create a user, use

    htpasswd -c /etc/apache2/demo-hon-htpaswd admin
    

    This will create a user with the username “admin”. You will be asked to enter a password.

    Now restart apache

    systemctl restart httpd
    

    See Cpanel Server

  • Cpanel Mail Server

    To see the current mail server setup on the Cpanel server, run

    [root@server78 ~]# /scripts/setupmailserver --current
    Current mailserver type: dovecot
    Current storage format: maildir or mdbox
    [root@server78 ~]#
    

    Cpanel Provide Following Mail servers

    SMTP: exim
    POP/IMAP: courier, dovecot
    

    Roundcube mail logs in Cpanel

    tail -f /var/cpanel/roundcube/log/errors
    

    See exim mail server, Cpanel Server