Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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
share|improve this question

migrated from serverfault.com Feb 20 '12 at 3:48

This question came from our site for professional system and network administrators.

3 Answers 3

up vote 7 down vote accepted

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.

share|improve this answer
    
After you are done with testing and got it working , you can then safely delete /var/www folder –  kaji Feb 20 '12 at 3:03
1  
+1 for the safe way –  MaxMackie Feb 20 '12 at 4:09
    
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 '12 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. –  jgoldschrafe Feb 20 '12 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). –  Gilles Feb 21 '12 at 2:24

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*'
    
share|improve this answer

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.

share|improve this answer
    
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 '12 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. –  Sardathrion Feb 22 '12 at 7:11

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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