Proper way to change server hostname

Post Reply
User avatar
myVesta
Site Admin
Posts: 936
Joined: Fri Jun 19, 2020 9:59 am
Has thanked: 8 times
Been thanked: 6 times

Before we begin, it's crucial to confirm that your newly chosen hostname is correctly configured to point to your server's IP address. Once this DNS configuration is in place, proceed to your myVesta control panel as an admin user.

Within the WEB section, you should add your new hostname as a new domain entry, activate Let's Encrypt for it and delete the old hostname.

Next, in your SSH terminal as the root user, execute the following commands to update your server's hostname and DNS settings. Replace the placeholder values with your specific information:

Code: Select all

OLDHOST=''  # enter here old hostname
OLDNS1=''   # enter here old NS1
OLDNS2=''   # enter here old NS2

NEWHOST=''  # enter here new hostname
NEWNS1=''   # enter here new NS1
NEWNS2=''   # enter here new NS2

/usr/local/vesta/bin/v-change-sys-hostname "$NEWHOST"

find /home/*/conf/dns/ -type f -exec sed -i "s#$OLDHOST#$NEWHOST#g" {} \;
find /home/*/conf/dns/ -type f -exec sed -i "s#$OLDNS1#$NEWNS1#g" {} \;
find /home/*/conf/dns/ -type f -exec sed -i "s#$OLDNS2#$NEWNS2#g" {} \;
find /usr/local/vesta/data/users/*/dns/ -type f -exec sed -i "s#$OLDHOST#$NEWHOST#g" {} \;
find /usr/local/vesta/data/users/*/dns/ -type f -exec sed -i "s#$OLDNS1#$NEWNS1#g" {} \;
find /usr/local/vesta/data/users/*/dns/ -type f -exec sed -i "s#$OLDNS2#$NEWNS2#g" {} \;
sed -i "s#$OLDHOST#$NEWHOST#g" /usr/local/vesta/data/users/*/dns.conf
sed -i "s#$OLDNS1#$NEWNS1#g" /usr/local/vesta/data/users/*/dns.conf
sed -i "s#$OLDHOST#$NEWHOST#g" /usr/local/vesta/data/users/*/user.conf
sed -i "s#$OLDNS1#$NEWNS1#g" /usr/local/vesta/data/users/*/user.conf
sed -i "s#$OLDNS2#$NEWNS2#g" /usr/local/vesta/data/users/*/user.conf
sed -i "s/$OLDHOST/$NEWHOST/g" /etc/roundcube/plugins/password/config.inc.php
grep -rl "$OLDHOST" /etc | xargs sed -i "s/$OLDHOST/$NEWHOST/g"
grep -rl "$OLDHOST" /usr/local/vesta/conf | xargs sed -i "s/$OLDHOST/$NEWHOST/g"
sed -i "s#$OLDNS1#$NEWNS1#g" /usr/local/vesta/data/packages/*.pkg
sed -i "s#$OLDNS2#$NEWNS2#g" /usr/local/vesta/data/packages/*.pkg
service bind9 reload
These commands will systematically update your server's hostname and DNS records across various configuration files. This ensures a seamless transition to your new hostname while maintaining system integrity and security.

Then we need to tweak few additional things:

Code: Select all

phpv=$(v-get-php-version-of-domain "$NEWHOST")
mcedit /etc/php/$phpv/fpm/pool.d/$NEWHOST.conf
Edit /etc/php/$phpv/fpm/pool.d/$NEWHOST.conf

Find:

Code: Select all

group = admin
(probably line 9)
and change that line to:

Code: Select all

group = www-data
After that, restart php-fpm:

Code: Select all

systemctl restart php$phpv-fpm

Tags:
infiinite
Posts: 14
Joined: Mon May 31, 2021 2:05 pm

Hey dpeca,

there's a little typo in your command, it should be /local/ and not loal.

However, this is the error I got when I executed it

Code: Select all

root@s628141:~# /usr/local/vesta/bin/v-change-sys-hostname MYNEWHOSTNAME
/usr/local/vesta/bin/v-change-sys-hostname: line 16: /func/main.sh: No such file or directory
/usr/local/vesta/bin/v-change-sys-hostname: line 17: /conf/vesta.conf: No such file or directory
/usr/local/vesta/bin/v-change-sys-hostname: line 24: check_args: command not found
/usr/local/vesta/bin/v-change-sys-hostname: line 25: is_format_valid: command not found
/usr/local/vesta/bin/v-change-sys-hostname: line 53: log_event: command not found
User avatar
myVesta
Site Admin
Posts: 936
Joined: Fri Jun 19, 2020 9:59 am
Has thanked: 8 times
Been thanked: 6 times

infiinite wrote: Wed Jun 02, 2021 8:16 am However, this is the error I got when I executed it

Code: Select all

root@s628141:~# /usr/local/vesta/bin/v-change-sys-hostname MYNEWHOSTNAME
/usr/local/vesta/bin/v-change-sys-hostname: line 16: /func/main.sh: No such file or directory
/usr/local/vesta/bin/v-change-sys-hostname: line 17: /conf/vesta.conf: No such file or directory
/usr/local/vesta/bin/v-change-sys-hostname: line 24: check_args: command not found
/usr/local/vesta/bin/v-change-sys-hostname: line 25: is_format_valid: command not found
/usr/local/vesta/bin/v-change-sys-hostname: line 53: log_event: command not found
See viewtopic.php?f=17&t=49

Tnx for typo :D
infiinite
Posts: 14
Joined: Mon May 31, 2021 2:05 pm

Thanks, adding that to env worked.

But now I got this. I tried making a bash file as well as pasting it directly in terminal.
Same error in both cases

Code: Select all

root@janus:~# grep -rl "$OLDHOST" /etc | xargs sed -i "s/$OLDHOST/$NEWHOST/g"
sed: no input files
root@janus:~# grep -rl "$OLDHOST" /usr/local/vesta/conf | xargs sed -i "s/$OLDHOST/$NEWHOST/g"
sed: no input files
User avatar
myVesta
Site Admin
Posts: 936
Joined: Fri Jun 19, 2020 9:59 am
Has thanked: 8 times
Been thanked: 6 times

That's ok, grep found nothing and just printed that warning.
Actually, sed got empty list of files from grep...
infiinite
Posts: 14
Joined: Mon May 31, 2021 2:05 pm

Alright. Perfect then.
kjernekrafttrikk
Posts: 9
Joined: Sat Apr 09, 2022 1:17 pm

I've got some number of domains associated with my server. Is it right to change server hostname to IP address? I guess, this one bring me some errors (such as ssl cert applied to one domain, but from the another one)/
Post Reply