Virtual Hosts Document Root

I’d like to change the default document root for the html website files of my vhost (public accessible).
It is now in /var/lib/nethserver/vhost/“myftpuser”
I prefer it to be /var/lib/nethserver/vhost/“myftpuser”/public_html
How can I change this? I don’t find the configuration file.

It’s in /etc/httpd/conf.d/virtualhosts.conf but it’s a templated config file so you shouldn’t change it directly.

You may create a custom template but in this case it’s not recommended as you have to override an original template and updates may not be applied. Why do you need that special config? Maybe we find another way to solve this.

The bad solution:

mkdir -p /etc/e-smith/templates-custom/etc/httpd/conf.d/virtualhosts.conf/
cp /etc/e-smith/templates/etc/httpd/conf.d/virtualhosts.conf/20virtual_hosts /etc/e-smith/templates-custom/etc/httpd/conf.d/virtualhosts.conf/

Change line 20 in /etc/e-smith/templates-custom/etc/httpd/conf.d/virtualhosts.conf/20virtual_hosts to

$vhostData{DocumentRoot} = '/var/lib/nethserver/vhost/'.$vhost->key.'/public_html';

It’s not really a special config.
It’s standard directory structure in control panels like Direct Admin and cPanel and I’m used to it.
But I see your point. Ther’s no real need for it, so I’ll drop my question.
Thanks anyway, Markus!

2 Likes

a similar issue outlined below - a shame that nethserver cant easily accomodate this?

"It is now best practice to have certain files outside of the root public directory. This is why many frameworks and CMS have a “web” or “public” or “pub” directory where the public files can live. A directory below that is where sensitive things like .git, private files and such can live.

The simple way to deal with a /var/www/mysite.com/web is to edit your web server’s document root. For example, in Apache this would mean setting DocumentRoot /var/www/mysite.com/web This should be easy even if you don’t have access to your Apache or Nginx configuration files because changing the document root is a basic setting in shared hosting platforms like cPanel and Plesk."

@jozeff, @alpreseidente

Hi Jozef Francois and Alex,

Just a suggestion and your old WordPress will still be available if those procedures fail.

BEST WAY:

  • Make a mysqldump of your database.

  • Install Duplicator (https://fr.wordpress.org/plugins/duplicator/) over 24 386 416 downloads.

  • Create a packet (backup)

    mkdir  /var/lib/nethserver/vhost/myftpuser/public_html
    
  • Copy the archive.zip, database.sql, and installer.php from wp-snapshots to public_html.

  • Go to your site your-domaine/public_html/installer.php and follow the directives.

  • Copy the original myftpuser/index.php to myftpuser/index.php_original

  • Replace the content of myftpuser/index.php with a redirection link pointing to public_html/index.php .

You can have a look at how I used Duplicator: https://www.micronator.org/affaires/produit/nethserver-101-cahier-09duplicator-migration/

ANOTHER QUICK WAY:
If you only used relative links in your WordPress pages.

  • Make a mysqldum of you database.

    mkdir /temp
    cp -a /var/lib/nethserver/vhost/myftpuser   /temp
    mkdir  /var/lib/nethserver/vhost/myftpuser/public_html
    cp -aR /temp/myftpuser/*  /var/lib/nethserver/vhost/myftpuser/public_html/
    cp -aR /temp/myftpuser/.*  /var/lib/nethserver/vhost/myftpuser/public_html/
    

Edit public_html/wp-config.php and under the line define('DB_PASSWORD',... insert

define('WP_SITEURL','https://your-domaine/public_html');
define('WP_HOME','https://your-domaine/public_html');
define('RELOCATE',true);
  • Do the same with myftpuser/index.php as above.

It should work or at least you will learn Duplicator and what it can do,

Michel-Andr.

Hi Michel-Andr thanks for feedback - i may need to brush up on my french in order to follow your link though, noting that any unauthorised use of french language is now thoroughly discouraged in UK :wink: