Search code examples
wordpressapachehttpd.confrhel7

Httpd only allows to access files that are directly created in the /var/www/html folder


I'm using Httpd for the first time and the final goal is to setup a wordpress instance on a local RHEL server (that has no external internet access).
So I installed httpd via yum and used touch hello.html inside the /var/www/html folder which worked fine and the file is available via browser. Now I started to move a html file from another computer via winScp to the root directory of the server and moved it with mv to the folder. I did also use chmod to set the correct access rights, but it didn't work.

How can I setup the server to serve these files? Atm I receive an 403 Forbidden error, so I assume I have to do something within the httpd config?

Would be very thankful for any help to get me onboard!


Solution

  • It's good practice to use a VirtualHost, and put the configuration in sites-enabled directory. You can of course just edit your httpd.conf and put the configuration in there. It's just not as flexible for administration.

    Edit /etc/httpd/conf/httpd.conf using sudo.

    Add IncludeOptional sites-enabled/*.conf at end of httpd.conf. Save and exit.

    sudo mkdir /etc/httpd/sites-enabled /etc/httpd/sites-available
    

    Using sudo, edit /etc/httpd/sites-available/mysite.conf and add the followingVirtualHosts` block:

    <VirtualHost *:80>
        DocumentRoot /var/www/html
        ServerName mysite.domain
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
    </VirtualHost>
    

    Now create the link for the config to the sites-enabled directory

    sudo ln -s /etc/httpd/sites-available/mysite.conf /etc/http/sites-enabled

    To restart Apache after completing the above, do

    sudo systemctl restart httpd
    

    The alternative is to add the VirtualHost block directly in httpd.conf, then re-start Apache.