to create umpteen subdomains on a Ubuntu 21.04 VPS and they all work as expected. Also each have separate SSL Certificates courtesy of LetsEncrypt.org…
The Problem:
I use CodeIgniter4 PHP Framework and unfortunately it requires the subdomain to call the following file:
Are you trying to make a codebase that will automatically create and set up subdomains, or are you manually setting them up?
Looking at your virtual host file, you are setting up a wildcard, or was that an attempt to get all subdomains pointing to the main domain codebase?
Edit:
Could you also let us know the file structure of your main domain?
And how you would like the subdomains set up according to that.
(i.e. why do you need public_html in the path).
Assuming you want them to run the same codebase, one way to do it is inside the index.php file for the subdomain, is to set an indicator (if needed) on who is running, and then include the main code base index file.
For this to work, the subdomain needs to have access to the main code base. Depending on the server setup, this might be restricted by the user running apache, or PHP settings. If, you would either need to give the users access to the different codebase, or soften the settings.
Another method, would be as you suggested to change the subdomain to point to the main codebase. This should be doable from the virtual host files if you run apache, just make sure you update the correct ones. Though if you are running WHM or any similar management software packages, those might override changes you do. (I have only done similar updates to subdomains on nginx in the past.)
Today I’ve investigated further and decided to isolate the simple subdomains and they are all working as expected.
The modern trend with most PHP Frameworks, WordPress, etc is to have a publicly available index.php which includes other files Above-the-root in an endeavour to have the included files unreachable by Joe Public.
Latest Trials:
I now have another three domains using CodeIgniter4 and they each require a public_html sub-directory.
I would be grateful ti know how I can call the subdomain *public_html/index.php file.
As a last resort I am tempted to ignore the public_html/index.php file and to move the Above-the-root included files to the immediate level below the subdomains
It is a good approach to store all library files below the public path (i.e. all files that are not image, CSS, javascript, etc and entry files).
Though if you run subdomains on WHM for example, where Apache like to place the subdomains like this /home/website/public_html/subdomain, the best approach is to go below the current public_html folder, making the root path for the subdomain files /home/website/subdomain/
I have never run Apache as standalone, so not sure if it does the same when run as that.
However from the example conf files you provided, I would verify that you cannot access the main subdomain folder from the main website.
[quote]@TheRedDevil,
However from the example conf files you provided, I would verify that you cannot access the main subdomain folder from the main website.