How to change AWS Lamp apache root directory? - php

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.

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

Related

Laravel 8 404 api routes in production

I have never had this issue before, it was working perfectly and after I reinstalled the server I now got a 404 when I call my 0.0.0.0/api/students/show.
I did composer production call on SSH to create latest autoloader. Cleared the cache for php artisan, the normal steps to setup a Laravel production app. But I still get 404 when I call the API endpoint.
Maybe the problems is something with chmod rights? Storage, etc. is already done...
In your apache2.conf make sure you've AllowOverride All and not AllowOverride none.
Example
<Directory /var/www/html/public>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
Original Answer
You should not need to write Directory at all.
This is my working page custom .conf file on sites-available folder:
<VirtualHost *:80>
ServerName matiaslauriti.dev
ServerAlias www.matiaslauriti.dev
Redirect 301 / https://matiaslauriti.dev
</VirtualHost>
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName matiaslauriti.dev
ServerAlias www.matiaslauriti.dev
DocumentRoot /var/www/html/public
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/matiaslauriti.dev/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/matiaslauriti.dev/privkey.pem
</VirtualHost>
</IfModule>
What I do have on my apache2.conf is default, I did not change anything:
<Directory />
Options FollowSymLinks
AllowOverride None
Require all denied
</Directory>
<Directory /usr/share>
AllowOverride None
Require all granted
</Directory>
<Directory /var/www/>
Options +FollowSymLinks -Indexes
AllowOverride All
Require all granted
</Directory>

Symfony project shows directory listing index instead of index page

I am new to Symfony, and I've just created a new project on Windows server + Php7.3 + Apache 2.4.
The project folder is located at C:\Apache24\htdocs\symfony.
When I access that folder from my web browser, I see the directory listing page it should show the index page in the public folder.
Here is my code in apache:
<VirtualHost *:90>
ServerAdmin abc#abc.com
DocumentRoot "${SRVROOT}/htdocs/"
ServerName localhost
<Directory "${SRVROOT}/htdocs/symfony/public">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
And i tried to use .htacess option as in Symfony guideline with install symfony/apache-pack, but no luck:
<VirtualHost *:90>
ServerAdmin abc#abc.com
DocumentRoot "${SRVROOT}/htdocs/"
ServerName localhost
<Directory "${SRVROOT}/htdocs/symfony/public">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
the .htaccess file had been created in public folder.
i have tried to install the demo application too, the same issue.
Wordpress or other applications have been installed without issue.
Thank you.
Shouldn't the DocumentRoot also be pointing to the Symfony public directory?
<VirtualHost *:90>
ServerAdmin abc#abc.com
DocumentRoot "${SRVROOT}/htdocs/symfony/public"
ServerName localhost
<Directory "${SRVROOT}/htdocs/symfony/public">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>

Laravel 5 on CentOS 7 Not Working On Domain

I've installed Laravel 5 on CentOS 7 with ease. Made .htaccess changes and and generated application key. My .conf file is like this:
<VirtualHost *:80>
ServerName mydomain.com
DocumentRoot "/var/www/html/laravel/public"
ServerAlias www.mydomain.com
ServerAdmin x#localhost
<Directory "/var/www/html/laravel">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
But when i try to open it via www.mydomain.com it opens Apache Testing 123.. page. And when i try www.mydomain.com/laravel/public, i can see default laravel page.
What am i missing?
<VirtualHost *:80>
ServerName mydomain.com
DocumentRoot "/var/www/html/laravel"
ServerAlias www.mydomain.com
ServerAdmin x#localhost
<Directory "/var/www/html/laravel">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
</Directory>
</VirtualHost>
Directory and document root should be the same
I had the exact same problem some months ago, check in your .htaccess for the following lines
<IfModule dir_module>
DirectoryIndex index.html
</IfModule>
If it's like this, include index.php so when apache is looking in the public folder it will use that file to redirect your routes. Also be sure you are loading the php module.
LoadModule php7_module modules/libphp7.so

virtual host alias for multiple laravel applications on single domain

I want my domain to run two separate laravel applications depending the url
for instance
domain.com to /home/sites/1
domain.com/account to /home/sites/2
I have this working, however the laravel instance running on site 2 thinks domain.com/account is the homepage.
When i goto domain.com/account i see the homepage of site 2 - not the route for setup for /account.
here is my vhost file
<VirtualHost *:443>
ServerName domain.com
ServerAdmin webmaster#localhost
UseCanonicalName Off
DocumentRoot /home/sites/1/public/
DirectoryIndex index.php
<Directory />
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
<Directory /home/sites/1/public/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
Alias /account/ /home/sites/2/public/
<Directory /home/sites/2/public/>
Require all granted
Options Indexes Includes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
Allow from all
RewriteEngine On
</Directory>
</VirtualHost>
Add this to your custom apache virtualhost file
<VirtualHost *:80>
ServerAdmin xx#xxx.com
ServerName xxx.com
DocumentRoot /path/to/site1/public
Alias /account /path/to/site2/public
<Directory /path/to/site1/>
AllowOverride All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Now you need to change .htaccess file of public folder of the alias -
add RewriteBase /directory_name_of_site2/ right after the RewriteEngine On in .htacess file
you can add as many aliases you want just remember to modify the .htaceess file of every projects

configure virtual hosts in azure ubuntu to run multiple laravel applications

I have created 2 laravel applications in /home/azureuser directory.
I want to run multiple laravel applications on single ubuntu VM. I tried configuring virtual hosts but not able to make it work.
Below is the contents of /etc/apache2/sites-enabled/000-default.conf
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName apitesting.cloudapp.net/demo
DocumentRoot /home/azureuser/demoapp/public
<Directory /home/azureuser/demoapp/public>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
SetEnv APPLICATION_ENV dev
LogLevel warn
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName apitesting.cloudapp.net/quiz
DocumentRoot /home/azureuser/quizapp/public
<Directory /home/azureuser/quizapp/public>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
SetEnv APPLICATION_ENV dev
LogLevel warn
</VirtualHost>
Not sure whether the above is correct.
It seem we cannot set the ServerName in the URL with a sub path param. As according your requirement, you can leverage the rewrite mod.
First, install apache rewrite mod via command: sudo a2enmod rewrite, then restart apache via: sudo service apache2 restart.
After that, modify the config file /etc/apache2/sites-enabled/000-default.conf, config the directory to the parent folder of your applications:
...
DocumentRoot /home/azureuser
ServerName apitesting.cloudapp.net
<Directory /home/azureuser>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
...
Then create a file named .htaccess in the root directory of your application, to redirect the incoming requests to your public folders, with the content:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>

Categories