Pre-installation configuration question(s) - Self hosted

Hi,
I’d like to try a self hosted instance of Invoice Ninja following some adverse changes to my current invoice platform.
I run a server (Ubuntu 18.04) that currently only runs an instance of Nextcloud and pi-hole.
I have Nextcloud set up under mydomain.net but ideally I’d like to change that to nextcloud.mydomain.net so that I can also have invoiceninja.mydomain.com
The next cloud files are installed in /var/www/html.
Should I originally have installed them in /var/www/html/nextcloud so that I can now create /var/www/html/invoiceninja?
I’d really rather not start all over. If this is possible to do can someone point me to some good information on it as I’m not even sure what to search for.

J

What folder the files are in doesn’t matter, as long as Apache knows where to look for what site. /var/www/html is simply the default folder that Apache uses, and is fine for most cases. I keep my own in /var/www/ninja/.

What you’re looking to do is create a subdomain. To do that, you’ll have to update the DNS entries with your registrar first. Then you’ll need to configure the vhosts in apache for each site. So you’ll have a config file for mydomain.net, nextcloud.mydomain.net, and invoiceninja.mydomain.net, all of which will need entries in the DNS with your registrar. The config files will need to have the ServerName variable set, because when a request comes in, that’s what will determine which set of pages gets served. But as long as DocumentRoot is pointed to wherever the correct files are, there’s no need to start over.

https://askubuntu.com/questions/463618/setting-up-subdomain-on-ubuntu-server might explain this a bit better than I can (as subdomains aren’t really my area).

Thanks for your reply,

I think I’ve made some progress.
I have set up a subdomain forward with my registrar and if I ping newthing.mydomain.com I see my public IP address returned - so that appears to be working.
I have created /var/www/newthing and placed a basic html file in it but going to newthing.mydomain.com doesn’t work.
My virtual host file, in /etc/apache2/sites-available reads (comments removed);

<VirtualHost *:80>        ServerName mydomain.com
        ServerAlias www.mydomain.com
        ServerAdmin [email protected]
        DocumentRoot /var/www/newthing
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

The contents of ports.conf is;

`# If you just change the port or add more ports here, you will likely also# have to change the VirtualHost statement in

/etc/apache2/sites-enabled/000-default.conf

Listen 80
<IfModule ssl_module>
Listen 443
</IfModule>
<IfModule mod_gnutls.c>
Listen 443
</IfModule>’

When I try to access http://newthing.mydomain.com it’s getting redirected to https://newthing.mydomain.com.
From memory, when I set up nextcloud this was also something I set up for security measures. But I can’t really remember anything about it - I think it’s a product of letsencrypt. I’ve tried changing my virtual hosts file for newthing to <VirtualHost *:443> but the result has been the same.

My sites-available directory contains:
000-default-le-ssl.com (contains the virtual host info for the nextcloud install)
000-default.conf
default-ssl.conf
new thing.mydomain.com.conf

My sites-enabled directory contains:
000-default-le-ssl.com
000-default.conf
new thing.mydomain.com.conf

Hoping someone can help.

J

I was a bit off when I mentioned needing separate conf files for each site. You should be able to put multiple VirtualHost entries in the same conf that you were already using.

So for example, you’d be doing something like the following (adapted from https://httpd.apache.org/docs/2.4/vhosts/examples.html):

<VirtualHost *:80>
    DocumentRoot "/var/www/html/nextcloud"
    ServerName nextcloud.mydomain.net

    # Rest of the stuff here
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "/path/to/invoiceninja/public"
    ServerName invoiceninja.mydomain.net

    # Rest of the stuff here
</VirtualHost>

The top entry will be the “primary”, meaning that without anything else specified (such as just typing in “mydomain.net”), that’s the set of pages it will serve. The ServerName entry there is basically just a fallback in case no other lookup works. But normally, unless specifically requested, it will serve what’s in the /nextcloud folder by default, so it should work with either “nextcloud.mydomain.net” or “mydomain.net”.

However, if you use “invoiceninja.mydomain.net”, it will see that as something specifically defined, and lookup whatever is in the specified folder (always point to ninja/public, as you don’t want people being able to see/read your .env file).

And be sure to restart apache after any changes so they take effect.

Thanks again,
I’ll have another look at it tomorrow.

J

I’m all good now - thanks for the replies.
I think the crux of the matter was that I had to add my new subdomain to my existing SSL certificate.