3

I'm learning how to configure linux, apache, php, mysql.

I followed these steps, how to set permissions for root:www-dev on the files and folders under /var/www/

Now I'd like to know how I can move the dir /var/www/ and I assume the permissions I've set will hold. I'm pretty sure I'll have to edit some apache configuration to let apache know it's directory has changed place.

I'm not sure where mysql is located, I also assume php is a module of apache therefore it should be somewhere in /var/www/

I'm just experimenting trying to get a feel for linux in general, and how to config a simple web server.


My configuration at the moment is default except for the permissions I've set.

# yum install httpd
# yum install mysql mysql-server
# yum install php php-mysql

3 Answers 3

7

Do it the safe way !

cp -pr /var/www /srv/www

it will copy the contents of /var/www recursively (-r switch) with permission intact (-p switch) to new folder /srv/www

You will need to change

DocumentRoot 

settings in your website or virtual host configuration file.

You need not worry about php module or mysql module for your case.

6
  • After you are done with testing and got it working , you can then safely delete /var/www folder
    – kaji
    Feb 20, 2012 at 3:03
  • Thank you I was expecting a more complicated situation, good to know it was as simple cp and only a few edits of httpd.conf
    – RzK
    Feb 20, 2012 at 5:09
  • 1
    If you're using SELinux, note that you'll also need use semanage to duplicate the contexts from /var/www onto /srv/www. If you don't, your SELinux filesystem contexts will get clobbered if you ever have to do a filesystem relabel. Feb 20, 2012 at 6:21
  • 3
    I wouldn't necessarily recommend copying then removing. If the two copies are on the same disk, mv is a lot better: it won't create a temporary copy that could get out of synch if someone or something modifies it at that time (and, secondarily, may use up a lot of space). Feb 21, 2012 at 2:24
  • @Gilles True, although my directories were pretty much empty except for a couple of files, I can see your point if httpd is running and running files while a copy is taking place, but can't the same be said for mv? The safest bet would probably be to stop the service before a mv or cp?
    – RzK
    Feb 22, 2012 at 7:03
2

If /var and /srv are on the same filesystem, then you can atomically move the www directory from one to the other:

mv /var/www /srv/

When you do that, any process that has a file open under www will keep that file open.

If /var and /srv are on different filesystems, you'd better stop the services that use the files under www before doing the move, because there'll be a transition period during which the files are being copied then deleted.

In that case, if you want to minimize the downtime:

  1. Copy the files, respecting permissions:

    cp -a /var/www /srv/
    
  2. Edit the configuration files to point to /srv/www instead of /var/www.
  3. Remove the files from under /var/www.

If you copy then remove, there will be a transition period during which two copies of the files exist. So you must make sure that nothing gets written under the www directory during the transition period; otherwise the two copies will get out of synch and some data may be lost.

To see what needs to be changed:

  • Search files under /etc, and perhaps under /var/www itself, to find references to /var/www:

    grep -r '/var/www' /etc /var/www
    
  • Look for any absolute symbolic link that references /var/www.

    find /etc /var/www -lname '/var/www*'
    
1

You do need to change DocumentRoot but could do this as well:

ln -si /var/www /srv/www

which would create a sym link from the first one to the second one. Or as kaji said, do the reverse but symlink the /var/www to /srv/www -- just swap the two arguments in the above command.

2
  • If I understand you correctly, create a symlink(shortcut) from var to srv, and than cp over the old directory to the new location? What exactly is the point of creating a symlink? - Thanks
    – RzK
    Feb 22, 2012 at 7:08
  • @903: No, you misunderstood me. The point of a sym link is to act as an alias for that directory. In this case, both /var/www and /srv/www point to the same physical location on the hard drive. They are the same place in the file system just access with different paths. The point is that you do not have to copy anything but still get to use whatever path you wish. Feb 22, 2012 at 7:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.