-1

i am trying to open the Laravel project in local server I get that error but i don't have public/index file and the project works on public server here is server.php code

 <?php

/**
 * Laravel - A PHP Framework For Web Artisans
 *
 * @package  Laravel
 * @author   Taylor Otwell <taylor@laravel.com>
 */

$uri = urldecode(
    parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)
);

// This file allows us to emulate Apache's "mod_rewrite" functionality from the
// built-in PHP web server. This provides a convenient way to test a Laravel
// application without having installed a "real" web server software here.
if ($uri !== '/' && file_exists(__DIR__.'/public'.$uri)) {
    return false;
}

require_once __DIR__.'/public/index.php';
ALAA ELDIN
  • 59
  • 1
  • 1
  • 9
  • First of all, why are you saying you don't have a `public/index.php` file ? It comes with Laravel installation, did you remove it? Also, to fix your problem (if you have the mentioned file correctly) you should have it like this: `require_once __DIR__ . './public/index.php';`. Please, do not edit these files as are vital and you don't require to change anything on it. If you must do so, explain why are you doing that. – matiaslauriti Sep 05 '21 at 06:05
  • Actually i didn't changed anything in this file but after i got this error i have change it I returned the code as it was and when I run the project I still get this error – ALAA ELDIN Sep 05 '21 at 07:57

1 Answers1

-1

To run laravel project on apache server like xampp you DO NOT need to change server.php;

There are two options to run laravel project:

A. Move contents of public folder:

  1. Move all contents of public folder to root of project.
  2. Change two lines in index.php in project root like below
//index.php

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

.
.
.

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

.
.
.

warning: In this method all files must be protected. My suggestion is to change .htaccess

  1. change .htaccess in root of project like below:
<IfModule mod_rewrite.c>

# Deny access to .htaccess
<Files .htaccess>
Order allow,deny
Deny from all
</Files>

<Files .env>
Order allow,deny
Deny from all
</Files>
    <IfModule mod_negotiation.c>
        Options -MultiViews -Indexes
    </IfModule>

    RewriteEngine On

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

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

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

<IfModule mod_suphp.c>
  suPHP_ConfigPath /home/path/to/public_html
</IfModule>

B: Move public folder

  1. Move your public folder to public_html and other files in a folder aligned with public_html with your-project-name (in xampp you can put it prev folder of htdocs) 2.change index.php like below:
//index.php

.
.
.
require __DIR__.'../your-project-name/vendor/autoload.php';

// in xampp: require __DIR__.'../../your-project-name/vendor/autoload.php';

.
.
.

$app = require_once __DIR__.'../your-project-name/bootstrap/app.php';
// in xampp: $app = require_once __DIR__.'../../your-project-name/bootstrap/app.php';

.
.
.
mahmood
  • 124
  • 1
  • 10
  • You don'ct need to modofy anything related to Laravel, just edit the `apache2.conf` file or create a new site and add it to the folder `sites-available` and then enable it like a normal apache... – matiaslauriti Sep 05 '21 at 09:05
  • This answer is correct mabye your method too but it's not a reason that my way is wrong. – mahmood Sep 06 '21 at 12:05
  • Where is the sites-available in xampp apache? can you write the true path for me? – mahmood Sep 06 '21 at 12:10
  • Look at [this answer](https://stackoverflow.com/a/21914920/1998801). I know it is related to `ports` and not `websites` but it is the same, you have to edit `httpd.conf` file and add a new site. I do not recommend `XAMPP` at all, start using `docker-compose`, you will have less problems and be super configurable. There are plenty of good tutorials out there about this, you will also learn more ! – matiaslauriti Sep 06 '21 at 13:41