I am trying to set up apach2 on an Ubuntu VPS. $ uname -a Linux www 5.4.0-58-generic #64-Ubuntu SMP Wed Dec 9 08:16:25 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux $ apache2 -v Server version: Apache/2.4.41 (Ubuntu) Server built: 2020-08-12T19:46:17 I bought an SSL cert from namecheap. I used their instructions to setup the SSL, and it seems to working. They have a test for it. But there are a few things I don't understand. Should port 80 and 443 both be enabled in 000-default.conf? The instructions gave a 443 template to pasted into the end of the file. I did that. But, it seems to want to default to port 80. Should I use www.example.com or example.com? I would like users to be able to enter either in the URL. I am trying to install Moodle in /var/www/html/moodle. I want users to just enter example.com. Do I need to change the server root to /var/www/html/moodle instead of /var/www/html? Any help appreciated. Thanks in advance.
Yes Port 80 should be enabled. Also, www is just a subdomain of example.com. So after setting up example.com on Apache, you can also set up www. the exact same way you will setup any other subdomain. Also, don't forget to configure SSL for the www. subdomain. If you don't setup www, your users will get a dns error when they try to visit your website via that subdomain. If you configured www on your dns already but forgot to configure it on Apache, Apache will show users the default page when users visit www.example.com
Thank you. I am still having some trouble. I have moodle installed in /var/www/html/moodle. My moodle site comes up just fine if I go to sitename.com/moodle If I go to sitename.com, I get the apache configuration page. I would like my site to come up if I go to sitename.com. I have tried changing DocumentRoot in the 000-default.conf to /var/www/html/moodle, that did not work. I have also tried a redirect in the the 000-default.conf, that did not work either. Should I just change in the DNS?
Move the moodle installation to html (/var/www/html/) if you do not want the moodle extension in your url. Set up a 301 permanent redirect in your .htaccess file to redirect all traffic from http (port 80) to https (port 443). Your Apache configuration works so there is no longer a need to keep editing it. Remove the default apache index file from html and you will be good to go.
This will solve the problem but what if he would like to host some other domain on the same server? He'll still be forced to go back to the config
Setting DocumentRoot should solve the issue. So when you say it doesn't work, what exactly do you mean? Does it give you an error? Does it still show the Apache page? Also, remember that the way Apache loads conf files is in numeric and alphabetical order. That is why default config are usually preceded with 000- so Apache will be sure to load it first. So check your directory to be sure that there is no other config file that is being loaded first. Secondly, you should probably paste the contents of 000-default.conf here. If you are uncomfortable posting it on a public place, send it privately. DocumentRoot ALWAYS work. I found out that when it doesn't work, the fault was from me.
This is a weird comment. If he'd like an add on domain or child domain, it is easily achieved and will also need to be at doc root so I am confused as to what exactly your advise is here in relation to what has been requested? To add ANY vhost, the config WILL have to be edited. He has so far already configured Apache correctly and everything is displaying as it should be including the default apache page. In that case, the only thing that needs to be changed is the path of the installation. If he should want to add additional domains, then yes, he will need to edit the config but that was not part of the question. Lastly, he clearly mentioned he has tried docroot and that did not work (maybe misconfigured).
This is a weird response because if he wanted an add on domain or child, he would need to create the subdomain at the document root level and, it has no basis in relation to his question. Yes, he will have to reconfigure as will need to be done any time a new vhost is added. But from my understanding, apache is working correctly and serving the defaut page so all that needs changing is the installation path.