Applicable to:
- Plesk for Linux
Question
How to change virtual hosts locations in Plesk for Linux?
How to replicate website vhost and root document path during migration from a non-Plesk server?
Answer
Check the warnings before making any changes:
Warning: These actions may cause websites downtime depending on the number of domains and data to be copied to the new location. It is recommended to apply this during maintenance hours.
Warning: Changing vhosts directory with the SELinux enabled in Plesk will break websites. This is due to SELinux limitation: it stores absolute paths in its policies, /var/www/vhosts, in this case. As a workaround, set SELinux to permissive mode before applying steps below.
After changing vhosts folder, SELinux should be kept in the permissive mode for correct websites working capacity.
Fix SELinux context with
# chcon -R system_u:object_r:httpd_sys_content_t:s0 /home/vhosts/
# find /customdir/vhosts/ -maxdepth 2 -type d -name logs | xargs chcon -R root:object_r:httpd_log_t:s0
# find /customdir/vhosts/ -maxdepth 2 -type d -name bin | xargs chcon -R system_u:object_r:bin_t:s0
# find /customdir/vhosts/ -maxdepth 3 -name resolv.conf | grep 'etc/resolv.conf' | xargs chcon system_u:object_r:net_conf_t:s0
Warning: it will work until restorecon
will not be running against net vhost location or its parent directory.
The location change can be done using transvhosts.pl
utility:
# plesk bin transvhosts.pl --help
For example, to change virtual hosts location to /customdir
directory:
# plesk bin transvhosts.pl --dest-dir /customdir --correct-scripts
All virtual host content will be automatically moved to the new location.
Changing virtual host location will not affect backup restoration functionality. Content from backups will be restored to new custom location.
Comments
17 comments
hello i get error message 502 Bad Gateway and 503 on domains client after using this guide. Version Plesk Onyx v17.5.3_build1705170317.16 os_CentOS 7
@web studio,
I suppose that you have faced the bug from the "Warning" message (Plesk Onyx, enabled SELinux).
Contact Plesk support to assist you in resolving the issue: https://www.plesk.com/contact-support
Thank you!!! Muchas gracias, estaba buscando esta solución hace 1 mes, y con este script pude cambiar de carpeta el virtual host.
Thank You!!!
Hi !
Is this problem now corrected by updates ?
Thanks
Hi @Jean Poulain,
The bug "#PPPM-6521" is not fixed yet
As a workaround, before changing the vhosts folder, set SELinux to permissive mode:
How to enable/disable SELinux on a server?
For correct websites working capacity, SELinux has to be in the permissive mode even after changing websites vhosts directory
I also updated the article with this information
When you write "As an alternative workaround, mount new partition as /var/www/vhosts." what is the procedure?
I just have my domain in var/www/vhosts and if I mount the additional hard disk the data I think disappear.
Hello @Giorgio,
Generally, the procedure is similar to steps described here (just mount new partition to /var/www/vhosts):
https://www.tecmint.com/move-home-directory-to-new-partition-disk-in-linux/
Let me warn you that this is an administrative task and misconfiguration during following the steps may lead the server to stop booting.
As you already have content at /var/www/vhosts I would recommend to change the virtual hosts location, as proposed in this article.
Hi,
I followed this procedure on 3 instances and at 1 I have the following:
Error 1146 (42S02) at line 1: Table 'psa.ServiceInstanceProperties' doesn't exist and system hangs on Correct user scripts.
Any idea what to do? I have a problem with 1 of the websites which gets now 503 error.
SElinux was disabled (and still is)
regards
Karol
Hello Karol,
The 'psa.ServiceInstanceProperties' message can be safely ignored. This database existed in Plesk 12.x only. As script applicable for all Plesk versions the error appears.
The website error is too generic and to be addressed properly it should be investigated in ticket:
https://support.plesk.com/hc/en-us/articles/213608509-How-to-submit-a-request-to-Plesk-support-
Hi Ivan Postnikov,
> "Warning: Websites which have absolute file paths in the code can become broken after vhosts location changing."
Can't i SYMLINK the OLD Path to new in order to prevent all CMS go down?
Joomla for example always has absolut path to tmp and cache DIR.
Anything to make this smoother?
Hello Lenusch
> Can't i SYMLINK the OLD Path to new in order to prevent all CMS go down?
Yes, that could be a solution.
> Anything to make this smoother?
The best suggestion for such changes is to check them on a test server 1st in order to avoid production downtime.
I used plesk bin transvhosts.pl --dest-dir /mnt/sdb --correct-scripts to move my sites to an external disk (200Gb). Now I want to move them back to the local disk (50Gb) on the server. What command should I use?
Hi Rodrigo Martinez,
The original directory is the next one:
# egrep HTTPD_VHOSTS_D /etc/psa/psa.conf
HTTPD_VHOSTS_D /var/www/vhosts
Article said,
"Warning: Changing vhosts directory with the SELinux enabled on Plesk Onyx will break websites."
Is this also applicable to Obsidian ?
@Fouad Ahmed Fouad yes
Running this now, did everything correctly with SELinux....
Seems to be hung at:
[root@intrepid ~]# plesk bin transvhosts.pl --dest-dir /home/www --correct-scripts
Moving files to new directory...
Correct psa configuration file...
Correct passwd file...
Correct php-fpm pools configuration...
Restart plesk-php80-fpm service...
Restart plesk-php74-fpm service...
Restart plesk-php56-fpm service...
Correct Fail2Ban jails configuration...
OK
File "/etc/fail2ban/jail.local" was stored successfully.
OK
Correct database...
Update hosting settings...
done
Update subdomains settings...
done
Update system users settings...
done
Update aps resources parameters...
done
The service node 'local' was successfully updated.
Reconfigure aps applications...
done
Now I am waiting, it has not come back to a prompt.
I never got a prompt. The ssh session froze. I hope the script finished! If not, perhaps someone can advise.
Got the same "problem" on Obsidian Version 18.0.47 Update #5 (the newest to date), the shell stop after:
Reconfigure aps applications...
done
But it looks like everything is done? the files are on the new place and the sites are working. The pearl script is found /opt/psa/bin/transvhosts.pl maybe could look if this was the last step.
Please sign in to leave a comment.