Archives

How to change the hostname on a cPanel web server

You will probably not change the server hostname very often, but we will show you here how to do it.

Usually, on a Linux server you will use the command hostname server.domain.com , like:

root@web [~]# hostname
web.plothost.com
root@web [~]# hostname webnew.plothost.com
root@web [~]# hostname
webnew.plothost.com
root@web [~]#
This is not a recommended method on a cPanel server.

There some recommended methods by cPanel to change the hostname:

1. Via WHM >> Networking Setup >> Change Hostname
2. Via sethostname WHM API function.
3. Via the set_hostname cPanel utility.

The second method can be used in a third party site/application. Read the cPanel documentation for more details. We will detail the methods 1. and 3.

To change the hostname in WHM:

  1. Login as root to WHM
  2. Navigate to Networking Setup >> Change Hostname
  3. Enter the desired hostname in the New Hostname field.
    whm change hostname
  4. Click the Change button. After few seconds you will the message Changing hostname… …Done with other details.
  5. Scroll to the bottom of the page and click the Add an A entry for your hostname button
    whm add a entry hostname
  6. On the page that will open, click the Add Entry button.
    whm confirm a entry
  7. You will see a message Adding A Entry……Done
  8. That’s all. Your new hostname is ready to use.

Don’t forget to read the cPanel Instructions:

It is important to choose a hostname that you will not be using for any account. You should choose something that will be socially acceptable, as it will appear in all mail headers. Your hostname must be a FQDN. In English, a hostname should consist of a name and a domain name. All valid hostnames should have 2 dots in them. Hostnames should never begin with “www”. Hostnames should also not begin with a digit, nor end with a hyphen (“-”).

The movie tutorial for changing the server’s hostname in WHM:

We will show below how to change the server’s hostname via the set_hostname cPanel utility. First, the full command:

root@web [~]# /usr/local/cpanel/bin/set_hostname --help
/usr/local/cpanel/bin/set_hostname 

When run as root, this program changes this servers hostname, updating it in all of the relevant locations on your system.

Options:
    --help: this help
root@web [~]#

Now let’s change the hostname:

root@web [~]# /usr/local/cpanel/bin/set_hostname web11.plothost.com
Changing hostname to web11.plothost.com...Success!

Hostname set to: web11.plothost.com
Output during rename:

Stopping cPHulkd during hostname change
Waiting for “cphulkd” to stop ………finished.
Startup Log
        Aug 19 03:43:46 web systemd[1]: Starting cPanel brute force detector services...
        Aug 19 03:43:46 web systemd[1]: PID file /var/run/cphulkd_processor.pid not readable (yet?) after start.
        Aug 19 03:43:46 web systemd[1]: Started cPanel brute force detector services.
        Aug 19 03:47:18 web systemd[1]: Stopping cPanel brute force detector services...
cphulkd stopped successfully.
Stopping MySQL during hostname change
Changing hostname in kernel to web11.plothost.com
Altered hostname in /etc/sysconfig/network
Updating cPHulkd

hulkdsetup: database schema is up to date.

Starting cPHulkd

Waiting for “cphulkd” to start ……waiting for “cphulkd” to initialize ………finished.
Service Status
        cphulkd (cPhulkd - processor - dormant mode - acce --start) is running as root with PID 7633 (systemd check method).
Startup Log
        Aug 19 03:47:22 web systemd[1]: Starting cPanel brute force detector services...
        Aug 19 03:47:22 web systemd[1]: PID file /var/run/cphulkd_processor.pid not readable (yet?) after start.
        Aug 19 03:47:22 web systemd[1]: cphulkd.service: Supervising process 7633 which is not our child. We'll most likely not notice when it exits.
        Aug 19 03:47:22 web systemd[1]: Started cPanel brute force detector services.
cphulkd started successfully.
Restarting Exim

Waiting for “exim” to restart ………waiting for “exim” to initialize ………finished.
Service Status
        exim (/usr/sbin/exim -bd -q60m -oP /var/spool/exim/exim-daemon.pid) is running as mailnull with PID 7661 (systemd check method).
        exim (/usr/sbin/exim -qG) is running as root with PID 7662 (systemd check method).
        exim (/usr/sbin/exim -qG) is running as root with PID 7676 (systemd check method).
Startup Log
        Aug 19 03:47:23 web systemd[1]: Starting Exim is a Mail Transport Agent, which is the program that moves mail from one machine to another....
        Aug 19 03:47:23 web systemd[1]: Started Exim is a Mail Transport Agent, which is the program that moves mail from one machine to another..
Log Messages
        2017-08-19 03:47:23 exim 4.89 daemon started: pid=7661, -q1h, listening for SMTP on port 587 (IPv6 and IPv4) port 25 (IPv6 and IPv4) and for SMTPS on port 465 (IPv6 and IPv4)
exim restarted successfully.
Updating Apache configuration

Updating cPanel license...Done. Update succeeded.
Building global cache for cpanel...Done

The system has queued the hostname changes for the Horde and DAV services.
Users cannot access the Horde or DAV features that use these services until
the system has finished updates to the hostname. After the system adjusts a
specific user’s database, it restores their access to the Horde and DAV services.

You will receive a notification when the system completes the update for all users.

Waiting for “mysql” to start ……waiting for “mysql” to initialize ………finished.

Service Status
        mysql (/usr/sbin/mysqld) is running as mysql with PID 7576 (systemd check method).

Startup Log
        Aug 19 03:47:21 web mysqld[7576]: 2017-08-19  3:47:21 139846925715712 [Note] InnoDB: Highest supported file format is Barracuda.
        Aug 19 03:47:21 web mysqld[7576]: 2017-08-19  3:47:21 139846925715712 [Note] InnoDB: 128 rollback segment(s) are active.
        Aug 19 03:47:21 web mysqld[7576]: 2017-08-19  3:47:21 139846925715712 [Note] InnoDB: Waiting for purge to start
        Aug 19 03:47:21 web mysqld[7576]: 2017-08-19  3:47:21 139846925715712 [Note] InnoDB:  Percona XtraDB (http://www.percona.com) 5.6.36-82.1 started; log sequence number 113808666
        Aug 19 03:47:21 web mysqld[7576]: 2017-08-19  3:47:21 139846925715712 [Note] Plugin 'FEEDBACK' is disabled.
        Aug 19 03:47:21 web mysqld[7576]: 2017-08-19  3:47:21 139846181975808 [Note] InnoDB: Dumping buffer pool(s) not yet started
        Aug 19 03:47:21 web mysqld[7576]: 2017-08-19  3:47:21 139846925715712 [Note] Server socket created on IP: '::'.
        Aug 19 03:47:21 web mysqld[7576]: 2017-08-19  3:47:21 139846925715712 [Note] /usr/sbin/mysqld: ready for connections.
        Aug 19 03:47:21 web mysqld[7576]: Version: '10.1.26-MariaDB'  socket: '/var/lib/mysql/mysql.sock'  port: 3306  MariaDB Server
        Aug 19 03:47:21 web systemd[1]: Started MariaDB database server.

Log Messages
        Aug 19 03:47:21 web mysqld: Version: '10.1.26-MariaDB'  socket: '/var/lib/mysql/mysql.sock'  port: 3306  MariaDB Server
        Aug 19 03:47:21 web mysqld: 2017-08-19  3:47:21 139846925715712 [Note] /usr/sbin/mysqld: ready for connections.
        Aug 19 03:47:21 web mysqld[7576]: Version: '10.1.26-MariaDB'  socket: '/var/lib/mysql/mysql.sock'  port: 3306  MariaDB Server

mysql started successfully.
root@web [~]#
Share this post:

How to install nano editor with yum

nano is a very used command line editor for Linux. Many Linux distribution has it installed by default. Anyway, if you system doesn’t has it, you can easily install it.

For more information on nano visit the webpage https://www.nano-editor.org/

You can test if nano is installed by trying to access it. Just type nano. It you see its “window” then it’s installed.

If it’s not installed, you will see a message like:

[root@webcp ~]# nano -bash: /usr/bin/nano: No such file or directory

To check the latest nano version on yum use yum info nano

[root@webcp ~]# yum info nano
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirror.steadfast.net
 * epel: mirror.steadfast.net
 * extras: repos-tx.psychz.net
 * updates: mirror.steadfast.net
Available Packages
Name        : nano
Arch        : x86_64
Version     : 2.3.1
Release     : 10.el7
Size        : 440 k
Repo        : base/7/x86_64
Summary     : A small text editor
URL         : http://www.nano-editor.org
License     : GPLv3+
Description : GNU nano is a small and friendly text editor.

To install nano use the command yum install nano

[root@webcp ~]# yum install nano
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirror.steadfast.net
 * epel: mirror.steadfast.net
 * extras: repos-tx.psychz.net
 * updates: mirror.steadfast.net
Resolving Dependencies
--> Running transaction check
---> Package nano.x86_64 0:2.3.1-10.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

========================================================================================================================================================================
 Package                              Arch                                   Version                                         Repository                            Size
========================================================================================================================================================================
Installing:
 nano                                 x86_64                                 2.3.1-10.el7                                    base                                 440 k

Transaction Summary
========================================================================================================================================================================
Install  1 Package

Total download size: 440 k
Installed size: 1.6 M
Is this ok [y/d/N]: y
Downloading packages:
nano-2.3.1-10.el7.x86_64.rpm                                                                                                                     | 440 kB  00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : nano-2.3.1-10.el7.x86_64                                                                                                                             1/1
  Verifying  : nano-2.3.1-10.el7.x86_64                                                                                                                             1/1

Installed:
  nano.x86_64 0:2.3.1-10.el7

Complete!
[root@webcp ~]# nano
[root@webcp ~]#

You can now edit text files with nano editor  🙂 

nano editor window

For nano source code, binaries, archives visit nano-editor.org/download.php
Share this post:

Remove cPanel users’ backups

cPanel users can generate backups of their accounts. Such backups are kept in the root of users’ directories, like /home/username/backup.tar.gz.

The filename format of the backups is backup-date_time_username.tar.gz. Example: backup-6.11.2017_09-52-35_plothost.tar.gz
The issue is that these backups take disk space and at some point you may see that your server is low on disk space. So, it’s a good idea to remove these backups from time to time.

You may want to inform your clients that you are removing backups (older than 5days etc.)

To remove backups for a single account, just navigate to the user’s directory and remove them with the command:

rm /home/username/backup-*.tar.gz

Usage example:

root@web [/]#
root@web [/]# cd home/plothost
root@web [/home/plothost]# ls backup-*.tar.gz
backup-6.11.2017_09-52-31_plothost.tar.gz  backup-6.11.2017_09-52-35_plothost.tar.gz
root@web [/home/plothost]# rm /home/plothost/backup-*.tar.gz
rm: remove regular file '/home/plothost/backup-6.11.2017_09-52-31_plothost.tar.gz'? y
rm: remove regular file '/home/plothost/backup-6.11.2017_09-52-35_plothost.tar.gz'? y
root@web [/home/plothost]#

To find and list all the backups from users’ directories:

find /home/* -maxdepth 1 -type f -name 'backup-*.tar.gz'

To find and delete all the backups from users’ directories:

find /home/* -maxdepth 1 -type f -name 'backup-*.tar.gz' -delete

To find and list all the backups from users’ directories which are older than 5 days:

find /home/* -maxdepth 1 -type f -mtime +5 -name 'backup-*.tar.gz'

To find and delete all the backups from users’ directories which are older than 5 days:

find /home/* -maxdepth 1 -type f -mtime +5 -name 'backup-*.tar.gz' -delete

You can create a con job for this task.
1.Enter the cron job editor:

crontab -e

2. Add the cron job (this job will run every day at 04:00 and will delete all backup archives older than 5 days)

* 4 * * * find /home/* -maxdepth 1 -type f -mtime +5 -name 'backup-*.tar.gz' -delete

3. Exit (with saving the changes) the cron job editor.

4. Check if the cron job was added successfully with the command (it will list all cron jobs):

crontab -l
Share this post:

How to shutdown or reboot Linux

The simple way to restart your CentOS/Linux system is by using the reboot command.

reboot

For more options, check the parameters:

root@web [~]# reboot --help
reboot [OPTIONS...] [ARG]

Reboot the system.

     --help      Show this help
     --halt      Halt the machine
  -p --poweroff  Switch off the machine
     --reboot    Reboot the machine
  -f --force     Force immediate halt/power-off/reboot
  -w --wtmp-only Don't halt/power-off/reboot, just write wtmp record
  -d --no-wtmp   Don't write wtmp record
     --no-wall   Don't send wall message before halt/power-off/reboot
root@web [~]#
You must be logged in as root to shutdown the operating system.

The other command is shutdown. It’s similar to reboot.

To reboot the machine with the shutdown command, use:

shutdown -r now

To reboot the machine at a specific time, use:

shutdown -r 02:30

To reboot the machine after X minutes, use:

shutdown -r X

To shutdown the machine, use:

shutdown -h now

To shutdown the machine at a specific time, use:

shutdown -h 02:30

To shutdown the machine after X minutes, use:

shutdown -h X

For more options, check the parameters for the shutdown command:

root@web [~]# shutdown --help
shutdown [OPTIONS...] [TIME] [WALL...]

Shut down the system.

     --help      Show this help
  -H --halt      Halt the machine
  -P --poweroff  Power-off the machine
  -r --reboot    Reboot the machine
  -h             Equivalent to --poweroff, overridden by --halt
  -k             Don't halt/power-off/reboot, just send warnings
     --no-wall   Don't send wall message before halt/power-off/reboot
  -c             Cancel a pending shutdown
root@web [~]#

For more information use the commands:

man reboot
man shutdown
Share this post:

Restart cPanel Services

Sometimes, you may want to restart services (like exim, httpd etc.) on your cPanel web server.

cPanel recommends for CentOS 7 to use a command like:

systemctl [restart|start|stop|status] service-name.service

Example1. Check the status of the exim server:

root@web [~]# systemctl status exim.service
* exim.service - Exim is a Mail Transport Agent, which is the program that moves mail from one machine to another.
   Loaded: loaded (/etc/systemd/system/exim.service; enabled; vendor preset: disabled)
   Active: active (running) since Mon 2017-05-01 07:51:39 EDT; 1 months 7 days ago
 Main PID: 12081 (exim)
   CGroup: /system.slice/exim.service
           `-12081 /usr/sbin/exim -bd -q60m -oP /var/spool/exim/exim-daemon.pid

Warning: Journal has been rotated since unit was started. Log output is incomplete or unavailable.
root@web [~]# 

Example2. Restart the exim server:

root@web [~]# systemctl restart exim.service
root@web [~]#
Notice that no output will be displayed if everything is fine.

Common used cPanel services are:

httpd
exim
pure-ftpd
named
dovecot
cphulkd
sshd
mysql
cpanellogd
crond
cpanel

If you prefer, you can restart common services via WHM:

  1. Log into your WHM account
  2. Navigate to Restart Services.
    whm restart services
  3. Click on the service icon you want to restart
  4. Click the Yes button when WHM will ask Are you sure you wish to restart this service?
  5. You will see a short restart log.
Share this post:
Page 1 of 6
1 2 3 6