skip to Main Content

I have a dev server that is used by me and a fellow dev, I have set up similar scenarios on live development servers before. The following Apache set up has worked on other Laravel projects, though lower versions.

The set up:
Server version: Apache/2.4.57 (Ubuntu)
PHP 8.1.18 (cli)
Laravel 9.19
React 18
Inertia 0.8.1
vite v3.2.6

There are 3 working directories, dir1, dir2 and dir3. In the apache conf files the following virtual host conf is enabled, {ip} omits the real IP addresses.

Apache virtual hosts file:

Listen {ip}:81
Listen {ip}:82

<VirtualHost *:80>
    ServerName {ip}
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/dir1/public
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    #RewriteEngine on
    #RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,QSA,R=permanent]

<Directory /var/www/dir1/public>
    Require all granted
    AllowOverride All
    allow from all
    Options +Indexes
</Directory>

</VirtualHost>


<VirtualHost {ip}:81>
    ServerName {ip}:81
    DocumentRoot /var/www/dir2/public

<Directory /var/www/dir2/public>
#   Require all granted
   AllowOverride All  
</Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>



<VirtualHost {ip}:82>
    DocumentRoot /var/www/dir3/public

<Directory /var/www/dir3/public>
   Require all granted
   AllowOverride All  
</Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>

The working directory (dir1), serves and presents the application fine, dir2 and dir3 both through the same apache error

[Wed May 10 15:06:12.166000 2023] [php:error] [pid 45741] [client {ip}:53093] PHP Fatal error:  Uncaught RuntimeException: A facade root has not been set. in /var/www/dir2/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php:335nStack trace:n#0 /var/www/dir2/vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/RegisterErrorViewPaths.php(18): Illuminate\Support\Facades\Facade::__callStatic()n#1 /var/www/dir2/vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php(642): Illuminate\Foundation\Exceptions\RegisterErrorViewPaths->__invoke()n#2 /var/www/dir2/vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php(623): Illuminate\Foundation\Exceptions\Handler->registerErrorViewPaths()n#3 /var/www/dir2/vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php(554): Illuminate\Foundation\Exceptions\Handler->renderHttpException()n#4 /var/www/dir2/vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php(460): Illuminate\Foundation\Exceptions\Handler->prepareResponse()n#5 /var/www/dir2/vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php(377): Illuminate\Foundation\Exceptions\Handler->renderExceptionResponse()n#6 /var/www/dir2/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(493): Illuminate\Foundation\Exceptions\Handler->render()n#7 /var/www/dir2/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(138): Illuminate\Foundation\Http\Kernel->renderException()n#8 /var/www/dir2/public/index.php(52): Illuminate\Foundation\Http\Kernel->handle()n#9 {main}n  thrown in /var/www/dir2/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php on line 335

I have ran every cache clear command known to me, including the all singing all dancing php artisan optimize:clear

I’ve ran composer:update, npm run build, all to continue to get the same error each time.

I have ran this exact same Virtual host set up before in other Laravel 8 projects with even more ports and directories and have copied the exact same structure so the issue lies with the framework itself, however, I can’t narrow down the root cause as to why the application will not load on another port

2

Answers


  1. Chosen as BEST ANSWER

    If anyone runs into this issue, check your Laravel Logs too, keep forgetting about that log and narrowed down the issue.

    It was an app config misconfiguration, which php artisan optimize:clear wasn't fixing, the php artisan config:cache command fixed everything


  2. 2 things to try here
    1- set <Directory /var/www/dir2/public> and <Dirctory /var/www/dir3/public>
    Exactly like dir 1 with these parameters

    Require all granted
    AllowOverride All
    allow from all
    Options +Indexes
    

    And

    2- Disable SELinux

    Run the command:

    sudo setenforce 0
    

    and then (to disable it also after rebooting)

    sed 'SELinux=enforcing/s//SELinux=disabled/' -i /etc/selinux/config
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search