I have cento os 7 and installing php website and by default i have to upload code to /var/www/html but i want my code to pick from /home/magento.

How to rewrite Document Root path in cento os .

  • I'm just revisiting some questions, how did you get on with this? – I_GNU_it_all_along Nov 11 '16 at 16:09

Use these commands one by one:

chcon -R --reference=/var/www/html/ /home/magento 
chcon -R -t httpd_sys_content_t /home/magento/ 
semanage fcontext -a -t httpd_sys_content_t "/home/magento(/.*)?" 
setsebool -P httpd_enable_homedirs true 
chmod 755 /home/magento # important !!
service httpd restart 

You can change the DocumentRoot directive in your httpd.conf (this should be found in /etc).

The file should contain a line like:

DocumentRoot "/var/www/html"

Change it to:

DocumentRoot "/home/magento"

If you add more directories in different locations that you want published you'll need to start making use of VirtualHost files

Also, if SELinux is set to enforcing, you'll need to set the SELinux context of the directory to match that of your /var/www directory. To find out whether or not SELinux is in operation use:


If the output is "permissive" then it's not enforcing.

If the output is "enforcing" then it's enforcing.

In order to change the context of the directory and its contents run the following:

semanage -a -t httpd_sys_content_t "/home/magento(/.*)?"

Now when you run ls -dZ /home/magento the "httpd_sys_content_t" context should be present in the output.

You will likely also have to set an SELinux boolean to allow publishing home dirs. To do this use:

setsebool -P httpd_enable_homedirs true

Note: the apache user will also need permissions to read the directory's contents.

  • i had changed documentroot to /home/magento and still website is not picking from /home/magento – Pradeep Sanku Sep 15 '16 at 11:45
  • Have you checked if SELinux is enforcing? – I_GNU_it_all_along Sep 15 '16 at 11:46
  • i didnt undersand what to do with SELinux is set to enforcing. i had checked getenforce it outputs enforcing – Pradeep Sanku Sep 15 '16 at 11:46
  • its enforcing... – Pradeep Sanku Sep 15 '16 at 11:46
  • Edited my answer with some more info. – I_GNU_it_all_along Sep 15 '16 at 12:02

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.