Wednesday, November 6, 2013

How to resolve "Could not open configuration file /etc/httpd/conf/httpd.conf: Permission denied" when start httpd service on RHEL 6?

I encounter this when I transfer (scp) httpd.conf file from my local machine to my new RHEL 6 server. I overwrote the httpd.conf file at /etc/httpd/conf directory and restart httpd service through "service httpd restart". Error message  "Could not open configuration file /etc/httpd/conf/httpd.conf: Permission denied" is prompted.

Type in the command below,
ls -Z
Output as described below is displayed
-rw-rw-r--. user1     user1      unconfined_u:object_r:user_home_t:s0 httpd.conf
-rw-r--r--. root       root       system_u:object_r:httpd_config_t:s0 magic
Steps to resolve this

1. Run the command below to change "unconfined_u:object_r:user_home_t:s0" to "system_u:object_r:httpd_config_t:s0".
chcon system_u:object_r:httpd_config_t:s0 httpd.conf
Once restart httpd service, it should be able to restart the apache service now.

2. For the sake of change the ownership correctly, you can run command below to change the owner
chown root:root httpd.conf
chmod 644 httpd.conf