How to run laravel 10 project without artisan serve?
There are several reasons why you might want to run Laravel without using `php artisan serve`:
1. Performance: The built-in PHP server that `php artisan serve` uses is not designed for production use and may not perform as well as a dedicated web server like Apache or Nginx.
2. Configuration: Using a dedicated web server allows you to have more control over the server configuration, which can be beneficial for optimizing performance and security.
3. Compatibility: If you're using additional technologies like Vue.js with Laravel, you might need to create a virtual host for proper functioning.
4. Convenience: Once you've set up a dedicated web server, you don't need to manually start the server every time you want to test your application.
It's also important to note that while you can make your Laravel application run without `php artisan serve`, you should still point your web server to the `public` directory of your Laravel application to prevent public access to sensitive files.
In laravel 10 there is no server.php file so move index.php and .htaccess from public folder and paste it to root directory.
<?php
use Illuminate\Contracts\Http\Kernel;
use Illuminate\Http\Request;
define('LARAVEL_START', microtime(true));
/*
|--------------------------------------------------------------------------
| Check If The Application Is Under Maintenance
|--------------------------------------------------------------------------
|
| If the application is in maintenance / demo mode via the "down" command
| we will load this file so that any pre-rendered content can be shown
| instead of starting the framework, which could cause an exception.
|
*/
if (file_exists($maintenance = __DIR__.'/storage/framework/maintenance.php')) { //CHANGED FILE LOCATION
require $maintenance;
}
/*
|--------------------------------------------------------------------------
| Register The Auto Loader
|--------------------------------------------------------------------------
|
| Composer provides a convenient, automatically generated class loader for
| this application. We just need to utilize it! We'll simply require it
| into the script here so we don't need to manually load our classes.
|
*/
require __DIR__.'/vendor/autoload.php'; //CHANGED FILE LOCATION
/*
|--------------------------------------------------------------------------
| Run The Application
|--------------------------------------------------------------------------
|
| Once we have the application, we can handle the incoming request using
| the application's HTTP kernel. Then, we will send the response back
| to this client's browser, allowing them to enjoy our application.
|
*/
$app = require_once __DIR__.'/bootstrap/app.php'; //CHANGED FILE LOCATION
$kernel = $app->make(Kernel::class);
$response = $kernel->handle(
$request = Request::capture()
)->send();
$kernel->terminate($request, $response);
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
<Files .env>
Order Allow,Deny
Deny from all
</Files>
RewriteEngine On
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
RewriteRule ^robots.txt -f [NC]
RewriteCond %{REQUEST_URI} !(\.css|\.js|\.png|\.jpg|\.jpeg|\.gif|\.html|\.txt|\.ico|\.woff|\.woff2|\.svg|\.pdf|\.ttf|\.json)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/public/
RewriteRule ^(css|build|vendor|assets|storage|js)/(.*)$ public/$1/$2 [L,NC]
</IfModule>
The `.htaccess` file provided is a configuration file used by Apache web servers. It allows you to control various aspects of your website on a per-directory basis. Here's a breakdown of the directives in your `.htaccess` file:
1. `<IfModule mod_rewrite.c>`: This checks if the `mod_rewrite` module is enabled on your Apache server. The `mod_rewrite` module allows you to rewrite URL patterns and implement pretty URLs.
2. `<IfModule mod_negotiation.c>`: This checks if the `mod_negotiation` module is enabled. The `Options -MultiViews -Indexes` directive inside this block disables content negotiation and directory listing.
3. `<Files .env>`: This block restricts access to the `.env` file, which typically contains sensitive information such as database credentials.
4. `RewriteEngine On`: This enables the URL rewriting engine.
5. `RewriteCond %{HTTP:Authorization} .` and `RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]`: These lines pass the HTTP Authorization header through to PHP as an environment variable, which is useful when using HTTP Basic Authentication.
6. The next set of `RewriteCond` and `RewriteRule` directives handle URL rewriting for pretty URLs.
7. The final `RewriteCond` and `RewriteRule` directives redirect requests for static files (CSS, JS, images, etc.) to the `public` directory.
Tags
Related Posts
How to create a common dynamic modal in Laravel?
How to edit env dynamically in laravel?
How to solve CORS error in laravel?
How to save image from a url in laravel?
How to integrate ChatGPT into Laravel?
How to create and integrate a ChatGPT AI bot into Laravel?
How to integrate ChatGPT image generation into Laravel?
How to use seeder in laravel?
How to create multi auth in laravel with 2 different login page?
How to create custom command in laravel?