# Botched Apache24 config



## dinsdale (Apr 5, 2020)

Hi, 

I'd like to set up apache24 to host a couple of domains. I had something hosted here before, but I think I've botched my configuration, currently only the first site I've set up is working.

What I would LIKE to do is this:

# winlua.net. Plain html site with some download links
www.winlua.net  -> .../www/winlua_net  
#Bookstack wiki. php based. I have 7.4.4 installed, but I'm not sure if apache is correctly configured
docs.winlua.net -> .../www/bookstack

Currently, www is in the default /usr/local/. My httpd.conf can be paraphrased as this:


```
ServerRoot "/usr/local"

#Standard modules n stuff

<Directory />
    AllowOverride none
    Require all denied
</Directory>

DocumentRoot "/usr/local/www"

IncludeOptional etc/apache24/sites-enabled/*.conf
```

I then have a conf file in sites-enabled called winlua_net.conf


```
<VirtualHost *:80>
    #Can this be relative to the main document root?
    DocumentRoot "www/winlua_net"
    ServerName www.winlua.net
</VirtualHost>
```

This site works.

But I created a second conf file in sites-enabled called docs_winlua_net.conf


```
<VirtualHost *:80>
        DocumentRoot "www/bookstack"
        ServerName docs.winlua.net
        #ServerAlias www.winlua.net/docs
        DirectoryIndex index.php
#RewriteEngine On

#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteRule ^ index.php [L]
</VirtualHost>
```

I've tried various things but that site always gives me "Index of /". I've tried both an absolute and relative path in DocumentRoot.  Is there anything obvious that I have done incorrectly?


----------



## SirDice (Apr 6, 2020)

Basic virtualhost configuration:

```
<VirtualHost *:80>
  DocumentRoot '/usr/local/www/somedir'
  ServerName site.example.com

  DirectoryIndex index.html index.php

  <Location />
    Require all granted
  </Location>
</VirtualHost>
```


----------



## dinsdale (Apr 7, 2020)

Thank you, that at least gives me confidence in the configuration file. 

I didn't like the files under /usr/local/ so I moved my two websites to/www. The docs_winlua_net.conf file now looks like this: 


```
<VirtualHost *:80>
  DocumentRoot '/www/bookstack/public'
  ServerName docs.winlua.net

  DirectoryIndex index.html index.php

  <Location />
    Require all granted
  </Location>
</VirtualHost>
```

I still get the same response. "Index of /".

The instructions for bookstack say "Ensure the storage, bootstrap/cache & public/uploads folders are writable by the web server" so I set permission to 774. I have set the ownership of bookstack to root:www.

#bookstack installation instructions.
bookstack installation


----------



## SirDice (Apr 7, 2020)

dinsdale said:


> I still get the same response. "Index of /".


It will only show this if there is no index.html or index.php in the /www/bookstack/public directory.


----------



## dinsdale (Apr 8, 2020)

SirDice said:


> It will only show this if there is no index.html or index.php in the /www/bookstack/public directory.



That makes sense, but I see an index.php file. 
	
	



```
russellh@freebird:/www# ll /www/bookstack/public/
total 66
-rw-r--r--  1 root  www    421 Apr  2 22:45 .htaccess
-rw-r--r--  1 root  www   5672 Apr  2 22:45 book_default_cover.png
drwxr-xr-x  2 root  www      6 Apr  2 22:45 dist/
-rw-r--r--  1 root  www  10933 Apr  2 22:45 favicon.ico
-rw-r--r--  1 root  www   1711 Apr  2 22:45 index.php
drwxr-xr-x  3 root  www      3 Apr  2 22:45 libs/
-rw-r--r--  1 root  www  11098 Apr  2 22:45 loading.gif
-rw-r--r--  1 root  www   5415 Apr  2 22:45 logo.png
drwxrwxr--  2 root  www      4 Apr  2 22:45 uploads/
-rw-r--r--  1 root  www   7405 Apr  2 22:45 user_avatar.png
-rw-r--r--  1 root  www   1193 Apr  2 22:45 web.config
```


Oh, wait. I just renamed bookstack/ to bookstack1/. I didn't restart the server and the "Index of /" message didn't change (I would have thought I would get an error). Restarting Apache complains though:


```
russellh@freebird:/www# mv bookstack/ bookstack1
russellh@freebird:/www# service apache24 restart
Performing sanity check on apache24 configuration:
AH00112: Warning: DocumentRoot [/www/bookstack/public] does not exist
Syntax OK
Stopping apache24.
Waiting for PIDS: 43398.
Performing sanity check on apache24 configuration:
AH00112: Warning: DocumentRoot [/www/bookstack/public] does not exist
Syntax OK
Starting apache24.
AH00112: Warning: DocumentRoot [/www/bookstack/public] does not exist
```

So... confused...


----------



## SirDice (Apr 8, 2020)

Think twice about what you are doing...


```
russellh@freebird:/www# mv bookstack/ bookstack1
...
AH00112: Warning: DocumentRoot [/www/bookstack/public] does not exist
```


----------



## dinsdale (Apr 9, 2020)

SirDice said:


> Think twice about what you are doing...
> 
> ```
> russellh@freebird:/www# mv bookstack/ bookstack1
> ...



I'm sorry, the intention of the above test wasn't clear (late night, lots of frustration).

The original problem: The configuration file parsed without warning when starting Apache, but displayed an empty directory.
I moved the bookstack directory while Apache was running but it didn't complain and showed the same empty listing. I would have expected a "resource not found" or something to that effect.
I restarted Apache (while the directory was missing) and the service warned that it could not find the directory. However, the web server displayed the same empty listing as when it *did* find the directory.
So what is that telling me? I think that means even though a shell shows files in the /www/bookstack/public folder and the webserver validated that the folder was there, Apache cannot see the contents. Permissions or ownership issues? Or is it not serving from the directory in the config file?

The one thing the test validates is the configuration file is looking at the correct directory.

One possibility: I removed the DocumentRoot and Directory commands in the httpd.conf file. Those commands pointed to the default configuration. I left "deny all on root" command (in httpd.conf):

```
<Directory />
    AllowOverride none
    Require all denied
</Directory>
```

I have two configuration files and I am wondering if one is affecting the other, causing the the later to default to a RootDirectory that has no permissions (due to "deny all" noted above)?

docs_winlua_net.conf (Servers the empty listing):

```
<VirtualHost *:80>
  DocumentRoot '/www/bookstack/public'
  ServerName docs.winlua.net

  DirectoryIndex index.html index.php

  <Location />
    Require all granted
  </Location>
</VirtualHost>
```

winlua_net.conf (works correctly)

```
<VirtualHost *:80>
        DocumentRoot "/www/winlua_net/"
        ServerName www.winlua.net
        ServerAlias winlua.net
        Options +FollowSymLinks
        <Location />
                Require all granted
        </Location>
</VirtualHost>
```

Hmmm... no, that's not it. I moved the working winlua_net.conf file into sites-available and docs.winlua.net still doesn't work (I restored /www/bookstack directory).


----------



## richardtoohey2 (Apr 9, 2020)

I think you have got to the stage of chasing your own tail and ended up in spagetti!

Might be easier to start again on a different machine or VM or whatever.  So leave this machine alone and start afresh on another.

Take the default settings and set-up your two virtual hosts and don't worry about the content in them - just one index.html each with a "this is host X" line in.

Get the simplest case working first, then worry about the PHP and permissions etc.  So make sure *both* virtual hosts work, no errors in Apache.

Once you've got the simplest case working it might help provide some clues as to how to get the main machine working in the same way, or at least a working foundation to then take the next steps.


----------



## SirDice (Apr 9, 2020)

dinsdale said:


> I removed the DocumentRoot and Directory commands in the httpd.conf file. Those commands pointed to the default configuration.


Leave them in please. 

You rarely need to modify httpd.conf. Create your virtualhost config in /usr/local/etc/apache24/Includes.


----------



## dinsdale (Apr 10, 2020)

First: Thank you, SirDice, you are a gentleman and a scholar. Thank you also to richardtoohey2  and pyret.

Second: I found the problem. I am only using DNS services from my hosting provider. The DNS record for docs.winlua.net was still pointing at the default setting of their (empty) server. I suspect I didn't save it correctly in the CPanel when I last tried to change it. 

Php isn't working yet, but that's a different problem.

I would like to ask one final question: if the sites-enabled/sites-available pattern is something that I should use?

Thank you all for your time. The positive side of this is many questions I had about defaults and changing them have been answered. I've reverted back to a nearly default httpd.conf file and very basic virtual host files. 

Okay, configuring php...
Regards,
Dinsdale


----------



## dinsdale (Apr 10, 2020)

SirDice said:


> It will only show this if there is no index.html or index.php in the /www/bookstack/public directory.


Prophetic.


----------

