Help pointing URL to correct folder in AWS Lightsail LAMP

Keywords: LAMP/MAMP/WAMP - AWS - Technical issue - Other
bnsupport ID: ffe1bb6e-5dc1-1aa6-6a1e-c358425c7f2d
Description:
I am new to AWS Lightsail LAMP stack and am having trouble getting my website to route properly to its folder.

I have all my files for my website on folder /opt/bitnami/apache/htdocs/testsite

However, when I type testsite.com on the browser, it gets the default index.html on the root folder, that is on /opt/bitnami/apache/htdocs/index.html

How can I point my website to /opt/bitnami/apache/htdocs/testsite folder?

On the /opt/bitnami/apache/conf/bitnami/bitnami.conf file, I have following:-

<VirtualHost default:80>
DocumentRoot "/opt/bitnami/apache/htdocs"
<Directory "/opt/bitnami/apache/htdocs">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>

# Error Documents
ErrorDocument 503 /503.html
</VirtualHost>

<VirtualHost *:80>
ServerName testsite (did not let me put 2 links on the post)
ServerAlias testsite(did not let me put 2 links on the post)
ServerAdmin testsite@gmail.com
DocumentRoot "/opt/bitnami/apache/htdocs/testsite"
<Directory "/opt/bitnami/apache/htdocs/testsite">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require all granted
</Directory>
</VirtualHost>

This file was already included in /opt/bitnami/apache/conf/httpd.conf file

Please let me know what I am missing or please direct me to properly setting up the virtual host. I googled for help but each solution refers to httpd.conf on different folders and I was not able to solve my problem after trying many times.

Thank you so much,
Roshni

sorry, the post editor does not let me put the VirtualHost section correctly.

Hi @roshni,

Thanks for using Bitnami. I checked your Apache logs and it is reporting an error in your /opt/bitnami/apache/conf/vhosts/httpd.conf file. Can you check it?

Syntax error on line 520 of /opt/bitnami/apache/conf/vhosts/httpd.conf

Apart from that, we can’t provide support for custom applications installed into the apache/htdocs folder. Can you check the guide below on how to install a custom application?

https://docs.bitnami.com/aws/infrastructure/lamp/administration/create-custom-application-php/

Hi gongomgra, thank you for replying. Where did you see the error? I looked at 2 log files in /opt/bitnami/apache/logs and I do see that error. Can you please point me to the error log file? Thank you so much.

@gongomgra Now I cannot even access my static IP address at 23.21.208.227. It says ‘can’t establish a connection to the server at 23.21.208.227’.

Hi @roshni,

The bnsupport tool detected it in the Apache log at /opt/bitnami/apache2/logs/error_log, but it is true it isn’t present in the file the tool retrieved, probably due to log rotation. Can you check the mentioned file and try to fix the error messages present there? Can you also run the bnsupport tool again and share the new code it will generate?

Also, I launched a fresh new LAMP image and that file doesn’t exist by default. Did you generate it?

Hi @gongomgra, I removed httpd.conf file from /opt/bitnami/apache/conf/vhosts directory and after that I ran /opt/bitnami/apache/conf/vhosts, and then finally I can at least see my static IP address pulling up in the web.

I found this command by google searching which gave me the error you had mentioned.
systemctl status bitnami.service

Now, I need to figure out how to get the index file in htdocs/mysite folder pull up when I type www.mysite.com

wish we could edit out posted message :slight_smile:

This is the new code 908c7fd4-15a5-5234-de6f-2b03457f8014
Thank you so much.

Hi @roshni,

Gonzalo shared this guide with you but I can see that you didn’t create the different configuration files.

https://docs.bitnami.com/aws/infrastructure/lamp/administration/create-custom-application-php/

Could you please follow that guide and remove the custom VirtualHost block you added in the /opt/bitnami/apache/conf/bitnami/bitnami.conf file? This block shouldn’t be there

<VirtualHost *:80>
    ServerName nepalimoms.com
    ServerAlias http://www.nepalimoms.com
__ServerAdmin reetdipti@gmail.com
__DocumentRoot "/opt/bitnami/apache/htdocs/nepalimoms"
__<Directory  "/opt/bitnami/apache/htdocs/nepalimoms">
____Options +Indexes +Includes +FollowSymLinks +MultiViews
____AllowOverride All
____Require all granted
__</Directory>
</VirtualHost>

Hi @jota Thank you so much for replying.

I removed the block from bitnami.conf as you told. I followed the guide. I found that my installation was Approach A: using system packages using following command.
test ! -f "/opt/bitnami/common/bin/openssl" && echo "Approach A: Using system packages." || echo "Approach B: Self-contained installation."

I created /opt/bitnami/myapp
I added index.html to it.

Then, I created the /opt/bitnami/apache2/conf/vhosts/myapp-vhost.conf and /opt/bitnami/apache2/conf/vhosts/myapp-https-vhost.conf.

Now, when I type in nepalimoms.com in the browser URL, I correctly see the text from index.html in /opt/bitnami/myapp folder.

But when I type in www.nepalimoms.com or http://www.nepalimoms.com or https://www.nepalimoms.com, I get problem loading page.

I have put the virtual host blocks in both the .conf files. Is there anything wrong with them or should I remove the default one? Please advise me.

I have run the bitnami-suupport-tool again, just in case. Here is the code:
a0b385fc-add4-08ed-b4e9-dabeef9f0c33

Thank you so much!

Hi @roshni,

You also need to configure the www domain in your DNS provider board. As you can see here, the non-www domain resolves properly but the www one does not

https://www.whatsmydns.net/#A/nepalimoms.com
https://www.whatsmydns.net/#A/www.nepalimoms.com

Oh…I did not know about that. It used to work before I pointed to AWS nameservers. Let me check in the DNS provider. Thank you.

@jota Thank you so much. I updated the DNS records in Lightsail Networking region by adding CNAME with www to point to main domain, and it now works.

I do have general question. What is the difference between Self-contained installation versus Installation using system packages? I know I have Installation using system packages. Why was this chosen for me? I had chosen LAMP using Lightsail.

Hi @roshni,

Thanks for your message. I’m glad you solved your errors with the DNS settings. About the recent changes in our stacks moving from self-contained installations to system packages, you can get more information in the next guide

https://docs.bitnami.com/aws/faq/get-started/understand-upcoming-changes/

Notice we are releasing our applications with the new installation format progressively. In the case of LAMP, it was one of our first assets using the new installation and configuration methods. It is not possible to chose the installation method for your server, it is just published with the new configuration format inside.

1 Like

I am again facing issue with the virtual hosts. I added another folder for my application. I add my new nepalimoms-vhost.conf file with following:

<VirtualHost *:80>
ServerName nepalimoms.com
ServerAlias http://www.nepalimoms.com
ServerAdmin test@gmail.com
DocumentRoot “/opt/bitnami/nepalimoms”
<Directory “/opt/bitnami/nepalimoms”>
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require all granted

I removed this virtual host block from myapp-vhost.conf file. I also added nepalimoms-https-vhost.conf file.

But my website still points to index file in myapp folder and not the one in nepalimoms folder. If you could point to me where I am going wrong, I would be very grateful. Can I not have multiple appname-vhost.conf files?

Here is the bitnami support code:
a47e18f5-a5b6-01fd-2b7c-8fd7e2a54af2

Thanks

Hi @roshni,

I just reviewed the configuration files inside the Bitnami Support tool and found the following

$ head apache/conf/vhosts/myapp-vhost.conf
<VirtualHost 127.0.0.1:80 _default_:80>
  ServerAlias *
  DocumentRoot /opt/bitnami/myapp
  <Directory "/opt/bitnami/myapp">
    Options -Indexes +FollowSymLinks -MultiViews
    AllowOverride All
    Require all granted
  </Directory>
</VirtualHost>

$ head apache/conf/vhosts/nepalimoms-vhost.conf
<VirtualHost *:80>
  ServerName nepalimoms.com
  ServerAlias http://www.nepalimoms.com
  ServerAdmin nepalimoms@gmail.com
  DocumentRoot "/opt/bitnami/nepalimoms"
  <Directory "/opt/bitnami/nepalimoms">
    Options +Indexes +Includes +FollowSymLinks +MultiViews
    AllowOverride All
    Require all granted
  </Directory>

As you can see, the myapp-vhost.conf file has this line ServerAlias *. That means that it matches with all the domains and that’s why you are not accessing the nepalimoms app. If you do not have “myapp” configured, just disabled the virtualhost files for it.

sudo mv /opt/bitnami/apache/conf/vhosts/myapp-vhost.conf /opt/bitnami/apache/conf/vhosts/myapp-vhost.back
sudo mv /opt/bitnami/apache/conf/vhosts/myapp-https-vhost.conf /opt/bitnami/apache/conf/vhosts/myapp-https-vhost.back

and restart Apache

sudo /opt/bitnami/ctlscript.sh restart apache

However, I accessed at your site now and saw that I can get what seems a valid test file

image

Did you already make these changes in the configuration? Is everything working as expected?

Thanks @jota for explaining. I used ServerAlias of myapp.com and that is why the other site started working. I had thought ServerAlias * would work only if it could not find specific aliases in one of the .conf files. I had read somewhere that defaults only take over, if apache cannot find virtual host for specific ServerName.

Hi @roshni,

I think you are right, but you shouldn’t specify the ServerName/ServerAlias parameters in the default VirtualHost, that way it doesn’t match with the other valid domains with custom configuration.

Now that you set your other domain, you now have 2 virtual host for your 2 sites.

Enjoy :slight_smile:

1 Like