Anowar Hosen
Anowar Hosen

Reputation: 187

How to change AWS Lamp apache root directory?

I am using AWS Lamp apache service. Here htdocs folder is the default root directory. I have a folder named my-folder inside htdocs.

htdocs
  my-folder

I want to set my-folder as a root directory.

But How?

I have edited /opt/bitnami/apache/conf/httpd.conf Here are the edited codes in httpd.conf file.

# DocumentRoot "/opt/bitnami/apache/htdocs"
# <Directory "/opt/bitnami/apache/htdocs">

DocumentRoot "/opt/bitnami/apache/htdocs/my-folder"
<Directory "/opt/bitnami/apache/htdocs/my-folder">
    Options Indexes FollowSymLinks
    AllowOverride None
    Require all granted
</Directory>

But it doesn't work!

Please correct me.

Upvotes: 1

Views: 1771

Answers (2)

Alejandro De Castro
Alejandro De Castro

Reputation: 2257

If you are using AWS Lightsail, the file to edit is:

sudo nano /opt/bitnami/apache/conf/bitnami/bitnami.conf

and then you can cange DocumentRoot and Directory, like this:

  DocumentRoot "/opt/bitnami/apache/htdocs/public"
  <Directory "/opt/bitnami/apache/htdocs/public">

This is my full exampole, in my case I add /public for Laravel apps.

# Default Virtual Host configuration.

# Let Apache know we're behind a SSL reverse proxy
SetEnvIf X-Forwarded-Proto https HTTPS=on

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

  # Error Documents
  ErrorDocument 503 /503.html
</VirtualHost>
Include "/opt/bitnami/apache/conf/bitnami/bitnami-ssl.conf"

Upvotes: 0

Anowar Hosen
Anowar Hosen

Reputation: 187

Problem Solved

I just modified /opt/bitnami/apache/conf/vhosts/00_status-vhost.conf as below.

  <VirtualHost 127.0.0.1:80 _default_:80>
    ServerAlias *
    DocumentRoot /opt/bitnami/apache/htdocs/my-folder
    <Directory "/opt/bitnami/apache/htdocs/my-folder">
      Options -Indexes +FollowSymLinks -MultiViews
      AllowOverride All
      Require all granted
    </Directory>
  </VirtualHost>

   #for https
  <VirtualHost 127.0.0.1:443 _default_:443>
    ServerAlias *
    DocumentRoot /opt/bitnami/apache/htdocs/my-folder
    SSLEngine on
    SSLCertificateFile "/opt/bitnami/apache2/conf/bitnami/certs/server.crt"
    SSLCertificateKeyFile "/opt/bitnami/apache2/conf/bitnami/certs/server.key"
   <Directory "/opt/bitnami/apache/htdocs/my-folder">
      Options -Indexes +FollowSymLinks -MultiViews
      AllowOverride All
      Require all granted
    </Directory>
  </VirtualHost>

and it's working!

Documention provided by AWS Create A Virtual Host For A Custom Application

Upvotes: 2

Related Questions