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
NOTE: 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 (on RPM-based Linux distributions) will break websites, refer to the 'Fix SELinux context' tab to apply the fix for the servers with SELinux enabled. As an alternative, keep SELinux in the permissive mode for the correct website's working capacity.
1. Connect to the server via SSH
2. The location change can be done using transvhosts.pl
utility, run command with --help
argument to learn about it:
# plesk bin transvhosts.pl --help
3. To change virtual hosts location to /home/vhosts/
directory for example run the following command (replace /home/vhosts/
with the actual path to target directory):
# plesk bin transvhosts.pl --dest-dir /home/vhosts/ --correct-scripts
All virtual host content will be automatically moved to the new location.
Note: changing virtual host location will not affect backup restoration functionality. Content from backups will be restored to new custom location.
Warning: running restorecon
on the virtual host directory or its parent directory will revert this fix.
1. Connect to the server via SSH
2. Run the following commands to fix the SELinux context for the custom virtual host directory (make sure to replace /home/vhosts/
with the actual path to virtual host directory):
# chcon -R system_u:object_r:httpd_sys_content_t:s0 /home/vhosts/
# find /home/vhosts/ -maxdepth 2 -type d -name logs -exec chcon -R root:object_r:httpd_log_t:s0 {} \;
# find /home/vhosts/ -maxdepth 2 -type d -name bin -exec chcon -R system_u:object_r:bin_t:s0 {} \;
# find /home/vhosts/ -maxdepth 3 -path '*/etc/*' -name resolv.conf -exec chcon system_u:object_r:net_conf_t:s0 {} \;
Note: vote for these steps to be automated in the Plesk UserVoice portal. The top-ranked suggestions are likely to be included in the next versions of Plesk.
Comments
4 comments
The “Fix SELinux” tab has both /home/vhosts/ and /customdir/vhosts/.
When exactly is the transvhosts.pl procedure run in relation to the SELinux fix?
Thx
The third SELinux fix fails with a “missing operand” error as shown below.
Ubuntu 24.04 on Supermicro Xeon server.
I had the same error.
"chcon: missing operand after ‘root:object_r:httpd_log_t:s0’
Try 'chcon --help' for more information."
CPU
Intel(R) Xeon(R) Platinum
Version
Plesk Obsidian v18.0.66_build1800241218.14 os_RedHat el9
Operating System
AlmaLinux 9.5 (Teal Serval)
Roy Jensen,
Ubuntu does not have SELinux enabled by default. Instead, it uses AppArmor as its primary mandatory access control system. There is no need to fix the context on such an OS.
Francisco Gochez,
The commands in the article are updated to suit AlmaLinux 9.
Please sign in to leave a comment.