skip to Main Content

I have deployed my Laravel application in CentOS7,Apache and LAMP. Created two subdomains and mapped the directories like as below

Subdomains

  • abc.example.com -> /var/www/abc.example.com/public_html/public
  • xyz.example.com -> /var/www/xyz.example.com/public_html/public

Virtual Host Configuration

Created virtual host configuration files for each subdomain. For example for abc.example.com created the file in /etc/conf.d/abc.example.com.conf

and in /var/www/abc.example.com/public_html/.htaccess having the following entries.

public_html/.htaccess

<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
    Options -MultiViews
</IfModule>

RewriteEngine On

# Redirect All Requests To The Subfolder
RewriteRule ^ /public

and in /var/www/abc.example.com/public_html/public/.htaccess having the following entries.

public_html/public/.htaccess

<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
    Options -MultiViews
</IfModule>

RewriteEngine On

# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]

# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

also, index.php (/abc.example.com/public_html/index.php) contains laravel’s default code as below

<?php

/**
 * Laravel - A PHP Framework For Web Artisans
 *
 * @package  Laravel
 * @author   Taylor Otwell <[email protected]>
 */

define('LARAVEL_START', microtime(true));

/*
|--------------------------------------------------------------------------
| Register The Auto Loader
|--------------------------------------------------------------------------
|
| Composer provides a convenient, automatically generated class loader for
| our application. We just need to utilize it! We'll simply require it
| into the script here so that we don't have to worry about manual
| loading any of our classes later on. It feels great to relax.
|
*/

require __DIR__.'/vendor/autoload.php';

/*
|--------------------------------------------------------------------------
| Turn On The Lights
|--------------------------------------------------------------------------
|
| We need to illuminate PHP development, so let us turn on the lights.
| This bootstraps the framework and gets it ready for use, then it
| will load up this application so that we can run it and send
| the responses back to the browser and delight our users.
|
*/

$app = require_once __DIR__.'/bootstrap/app.php';

/*
|--------------------------------------------------------------------------
| Run The Application
|--------------------------------------------------------------------------
|
| Once we have the application, we can handle the incoming request
| through the kernel, and send the associated response back to
| the client's browser allowing them to enjoy the creative
| and wonderful application we have prepared for them.
|
*/

$kernel = $app->make(IlluminateContractsHttpKernel::class);

$response = $kernel->handle(
    $request = IlluminateHttpRequest::capture()
);

$response->send();

$kernel->terminate($request, $response);

While browsing http://abc.example.com forbidder error is displaying
enter image description here

Also, error.log file is logging the following exception as below.

AH01276: Cannot serve directory /var/www/abc.example.com/public_html/public/: No matching DirectoryIndex (index.html) found, and server-generated directory index forbidden by Options directive

2

Answers


  1. also, index.php (/abc.example.com/public_html/index.php) contains laravel’s default code as below

    According to your other directives, the index.php file should be inside the /public_html/public subdirectory, not /public_html.

    Also, you do need to make sure that the DirectoryIndex is correctly set. The server default is index.html only. For example, at the top of /public/.htaccess:

    DirectoryIndex index.php
    
    Login or Signup to reply.
  2. You need to authorize the directory containing your code
    You can try this command:

    sudo chown -R www-data:www-data /var/www/abc.example.com/public_html/
    sudo find /var/www/abc.example.com/public_html/ -type f -exec chmod 644 {} ;
    sudo find /var/www/abc.example.com/public_html/ -type d -exec chmod 755 {} ;
    sudo chgrp -R www-data /var/www/abc.example.com/public_html/storage/
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search