0

In my old server I used to use the /home/domain folder.

In this new server I use /var/www/vhosts/domain

In a very old script which consists of lots of php files, it was used like /home/domain/public_html/...

I wonder if there is a way to use symlink or something similar to use those php files without replacing each line with the new folder name.

Mike
  • 23,542
  • 14
  • 76
  • 87
Utku Dalmaz
  • 9,780
  • 28
  • 90
  • 130

1 Answers1

0

First, just wanted to say that hard-coding paths all over your files is not really a good idea. If you need the full path, it is far better to save the document root as a constant and if you ever need to modify it, you only have to change it on one place. Then just make all paths in your script relative to the document root.

If you don't want to do this, you have a few other options. Unfortunately symlinking is probably not one of them because you may run into directory restrictions unless your web server (e.g. Apache) is configured to also serve content from the directory being symlinked to.

Option 1: Find and replace

Use sed to find and replace all occurrences of the old directory with the new one. See: Find and replace with sed in directory and sub directories. Just make sure you do a backup of all your files first since there is no "undo" with sed and you can really mess things up if you do it wrong.

Option 2: Use the same directory as you were before

Edit your site's configuration file (e.g. for Apache on Debian this would be something like /etc/apache2/sites-enabled/example.com.conf) and change the DocumentRoot and <Directory> to the old path. Then actually create it if it doesn't exist and copy your files over.

Option 3: Bind mount (probably not recommended)

Symlinks probably won't work, but something similar to symlinks are bind mounts. This is basically mounting one part of your file system into another part of it. Something about this just screams overkill for what you are trying to do, but I'm posting it here mainly for interest in case you want to fool around with your server.

Edit your server's /etc/fstab and add something like this to the end:

/var/www/vhosts/domain/ /home/domain  none rw,bind 0 0 

Make sure /home/domain doesn't actually exist yet and then execute mount -a as root, which should create /home/domain for you with the contents of /var/www/vhosts/domain/.

Community
  • 1
  • 1
Mike
  • 23,542
  • 14
  • 76
  • 87