Help directing my domains to specific custom PHP applications in one Lightsail instance

Keywords: LAMP/MAMP/WAMP - AWS - How to - Domain Name (DNS)
Description:
I am running Bitnami LAMP stack on a single AWS Lightsail instance. That instance is associated with MyDomainOne.com (placeholder). I also own MyDomainTwo.com (placeholder). I manage both of the domains through Amazon.

I have a number of different PHP apps running in my Lightsail instance, including a Wordpress blog, a Nextcloud installation, etc. All set up based on the instructions at https://docs.bitnami.com/general/infrastructure/lamp/administration/create-custom-application-php/

Right now I can see my Wordpress blog at www.MyDomainOne.com/MyDomainTwo/wp

I want to set things up so that that Wordpress blog “appears at” www.MyDomainTwo.com/wp – that is, people who go to www.MyDomainTwo/wp should see what I now see at www.MyDomainOne.com/MyDomainTwo/wp

I know there is a way to do this within Apache conf files, and that I probably have to change things in Wordpress as well, but even after reading the thread at https://docs.bitnami.com/aws/apps/wordpress/administration/redirect-custom-domains/ I can’t get it to work (still confused).

What steps do I have to take in terms of modifying the conf files? And what steps do I need to take on the DNS management side?

All help appreciated – thanks

Hi @JoeQ,

Thanks for using Bitnami. You will need to configure a VirtualHost for each of your custom applications following the next guide

https://docs.bitnami.com/aws/infrastructure/lamp/configuration/configure-custom-application/#approach-b-self-contained-bitnami-installations

Hope it helps!

@gongomra

Just so I am clear, what I need to do is edit the httpd-vhosts.conf file with this content (changing the ports appropriately)

<VirtualHost *:8080> ServerName www.MyDomainTwo.com/wp DocumentRoot "/opt/bitnami/apps/MyDomainTwo/wp/htdocs" Include "/opt/bitnami/apps/MyDomainTwo/wp/conf/httpd-app.conf" </VirtualHost>

That is, ServerName is the URL I want to appear to users in the address bar, and DocumentRoot is that actual path to the website files. Is that correct?

Sorry, in the previous reply I meant to tag @gongomgra.

Hi @JoeQ,

Yes, you are right. Take into account that default ports in cloud images are 80 and 443. For the domain name containing /wp, I think you will need to use the Alias directive and set ServerName to www.MyDomainTwo.com only.

Thanks. I have a follow-on question about certificates.

In this case it is a slightly different setup:

I have a site at mydomain.com/sci and I want it to be visible at sci.mydomain.com. So I understand that I need to use httpd-vhosts.conf and use the line ServerName sci.mydomain.com to make that change, with ports 80 and 443.

The question is, when I created the SSL certificate for mydomain.com (I believe I used bncert-tool) it does not “automatically” include a new subdomain like sci.mydomain.com, correct?

How can I have the existing SSL certificate apply to sci.mydomain.com as well? Or do I create a new one? What is the best approach? There seem to be multiple contradictory answers in the archives.

Hi @JoeQ,

You are right, the SSL certificate for yourdomain.com won’t cover sci.yourdomain.com, but you can create a certificate for both domains using bncert-tool. Just provide the list of your domains when asked for the domains.

Hi @gongomgra,

Thanks for this. However, when I run the bncert-tool and ask it to provide certificates for both mydomain.com and sci.mydomain.com, I get a message that sci.mydomain.com does not resolve.

This is despite having the following in httpd-vhosts.conf:

<VirtualHost *:80>
ServerName sci.mydomain.com
DocumentRoot "/opt/bitnami/apps/sci/htdocs"
Include "/opt/bitnami/apps/sci/conf/httpd-app.conf"
</VirtualHost>

<VirtualHost *:443>
ServerName sci.mydomain.com
DocumentRoot "/opt/bitnami/apps/sci/htdocs"
# SSLEngine on
# SSLCertificateFile "/opt/bitnami/apps/sci/conf/certs/server.crt"
# SSLCertificateKeyFile "/opt/bitnami/apps/sci/conf/certs/server.key"
Include "/opt/bitnami/apps/sci/conf/httpd-app.conf"
</VirtualHost>

I commented out the SSL-related lines, thinking that the certificates will be in place after I run bncert-tool. If I don’t comment them out, I get errors when trying to restart Apache to apply the new config files – it is looking for certificates that aren’t yet there.

In addition to the above, in the /opt/bitnami/apache2/conf/bitnami/bitnami-apps-prefix.conf file I have the line `Include “/opt/bitnami/apps/sci/conf/httpd-prefix.conf” commented out.

And in the /opt/bitnami/apache2/conf/bitnami/bitnami-apps-vhosts.conf file I have added the line `Include “/opt/bitnami/apps/sci/conf/httpd-vhosts.conf”, as described at https://docs.bitnami.com/aws/infrastructure/lamp/configuration/configure-custom-application/

So I think I’m missing something basic (bncert-tool can’t resolve the domain, but the domain isn’t resolving because Apache doesn’t like my httpd-vhosts.conf file or something like that.

Any ideas?

Hi @JoeQ,

This has nothing to do with your current configuration but the DNS provider one. You need to configure in the DNS provider dashboard the configuration of sci.mydomain.com. You can use this online tool to confirm that the configuration is correct

https://www.whatsmydns.net/

Hi @jota, I appreciate the help. I had neglected to set up the subdomain configuration, now it works.

@gongomgra

I am still having trouble with httpd-vhosts.conf (I think). I’ve changed things so I no longer want to go into www.MyDomainTwo.com/wp but just www.MyDomainTwo.com

I have httpd-vhosts.conf setup as follows:

<VirtualHost *:80>
ServerName MyDomainTwo.com
DocumentRoot "/opt/bitnami/apps/MyDomainTwo/htdocs"
Include "/opt/bitnami/apps/MyDomainTwo/conf/httpd-app.conf"
</VirtualHost>

<VirtualHost *:443>
ServerName MyDomainTwo.com
DocumentRoot "/opt/bitnami/apps/MyDomainTwo/htdocs"
SSLEngine on
SSLCertificateFile "/opt/bitnami/apache2/conf/server.crt"
SSLCertificateKeyFile "/opt/bitnami/apache2/conf/server.key"
Include "/opt/bitnami/apps/MyDomainTwo/conf/httpd-app.conf"
</VirtualHost> 

The httpd-prefix.conf file looks like:

Alias /MyDomainTwo/ "/opt/bitnami/apps/MyDomainTwo/htdocs/"
Alias /MyDomainTwo "/opt/bitnami/apps/MyDomainTwo/htdocs/"
Include "/opt/bitnami/apps/MyDomainTwo/conf/httpd-app.conf"

I can successfully see my site (with some CSS issues, but that’s for another day) at MyDomainOne.com/MyDomainTwo

I would like to be able to see it when I go to MyDomainTwo.com. Instead, when I go to MyDomainTwo.com I see exactly what I see at MyDomainOne.com (i.e. the root level site)

I don’t think this is a DNS issue, as MyDomainTwo.com does get sent to my MyDomainOne.com space, but the redirection down into the folder MyDomainOne.com/MyDomainTwo never happens. Any advice appreciated.

Hi @JoeQ,

Check you are not including your websites in Apache using both the bitnami-apps-prefix.conf and bitnami-apps-vhosts.conf files. Using the -vhosts.conf file should be enough to fit your requirements.

@gongomgra – I’ve commented out any mention of the MyDomainTwo app in bitnami-apps-prefix.conf but it doesn’t seem to make a difference.

Do I perhaps need to first make my desired site available with a subdomain, as in MyDomainTwo.MyDomainOne.com pointing to MyDomainOne.com/MyDomainTwo for this redirection to work?

Hi @JoeQ,

We have a Support Tool that will gather relevant information for us to analyze your configuration and logs. Could you please execute it on the machine where the stack is running by following the steps described in the guide below?

Please note that you need to paste the code ID that is shown at the end.

@gongomgra

The code is b9c47bfc-9c1f-f9a8-c35c-b4b8ca791fc4

Hi @JoeQ,

Thanks for the bnsupport code. I visited your two different application installed as virtualhost and I’m getting a different website for each of them, so I understand everything is working properly. Can you give us more details about what are the issues you are facing?

I also managed to visit your other website using the prefix configuration

@gongomgra

sci.orbito.me and my Nextcloud installation are fine.

The issue I am having is that photosensitive.ca is showing the same content as orbito.me (just a funny placeholder) when in fact it should be showing the content I would expect to see at orbito.me/photosensitive if I didn’t have all the aliases commented out etc.

How can I make photosensitive.ca show what I now have at orbito.me/photosensitive (that is, the website in /opt/bitnami/apps/photosensitive/) What changes do I need to make to the conf files?

Hi @JoeQ,

The Apache configuration seems fine to me, and also the DNS configuration

I don’t know if it can be caused for using a mix of virtualhosts and prefixed sites. Can you comment out all the lines in the bitnami-apps-prefix.conf file, restart Apache and try to access photosensitive.ca again?

sudo /opt/bitnami/ctlscript.sh restart apache

Can you also tell us where did you install that sample HTML file? the content of the photosensitive/htdocs directory seems to be a WordPress installation. I also can’t find any configuration for orbito.me, but I don’t know how this can be related. I also tried to navigate to http://orbito.me/photosensitive and it is giving me a 404 not found error.

@gongomgra

Thank you.

In bitnami-apps-prefix.conf the line related to photosensitive is already commented out, as is the one about sci.orbito.me.

The sample HTML file (“Welcome to Astroworm…”) one sees when visiting both orbito.me and photosensitive.ca is in the default htdocs folder, the path is /opt/bitnami/apache2/htdocs.

You are correct that the photosensitive/htdocs contents are a Wordpress site. That’s what I want to be displayed when a visitor goes to photosensitive.ca. But instead the visitor gets the /opt/bitnami/apache2/htdocs content.

When I delete the Virtual Host content for photosensitive I am able to see my Wordpress site at orbito.me/photosensitive

So I’m not sure what’s happening here.

Hi @JoeQ,

I checked your Apache config again and I think I know what can be the issue here. Your bitnami.conf file is next

<VirtualHost _default_:80>
  DocumentRoot "/opt/bitnami/apache2/htdocs"
  <Directory "/opt/bitnami/apache2/htdocs">
    Options Indexes FollowSymLinks
    AllowOverride All
    <IfVersion < 2.3 >
      Order allow,deny
      Allow from all
    </IfVersion>
    <IfVersion >= 2.3 >
      Require all granted
    </IfVersion>
  </Directory>

  # Error Documents
  ErrorDocument 503 /503.html

  # Bitnami applications installed with a prefix URL (default)
  Include "/opt/bitnami/apache2/conf/bitnami/bitnami-apps-prefix.conf"

  # This part should force everything to https
  DocumentRoot "/opt/bitnami/apache2/htdocs"
  RewriteEngine On
  RewriteCond %{HTTPS} !=on
  RewriteCond %{HTTP_HOST} !^(localhost|127.0.0.1)
  RewriteRule ^/(.*) https://%{SERVER_NAME}/$1 [R,L]

</VirtualHost>

As you can see, you are overwriting the DocumentRoot directive and running the HTTP to HTTPS redirection in a different place than the one recommended in our docs. I think overwriting DocumentRoot after the include

https://docs.bitnami.com/aws/apps/wordpress/administration/force-https-apache/

As shown there, it is supposed to be added at the beginning of the VirtualHost definition. Can you replace that section with the next content and restart Apache?

<VirtualHost _default_:80>
  DocumentRoot "/opt/bitnami/apache2/htdocs"
  RewriteEngine On
  RewriteCond %{HTTPS} !=on
  RewriteCond %{HTTP_HOST} !^(localhost|127.0.0.1)
  RewriteRule ^/(.*) https://%{SERVER_NAME}/$1 [R,L]
  <Directory "/opt/bitnami/apache2/htdocs">
    Options Indexes FollowSymLinks
    AllowOverride All
    <IfVersion < 2.3 >
      Order allow,deny
      Allow from all
    </IfVersion>
    <IfVersion >= 2.3 >
      Require all granted
    </IfVersion>
  </Directory>

  # Error Documents
  ErrorDocument 503 /503.html

  # Bitnami applications installed with a prefix URL (default)
  Include "/opt/bitnami/apache2/conf/bitnami/bitnami-apps-prefix.conf"

</VirtualHost>