Step-by-Step Guide
Move index.php and .htaccess from the public directory to the root
Move the index.php and .htaccess files from the public directory to the root of your Laravel project.
sudo mv /var/www/html/your-laravel-project/public/index.php /var/www/html/your-laravel-project/
sudo mv /var/www/html/your-laravel-project/public/.htaccess /var/www/html/your-laravel-project/
Update index.php Paths
Edit the index.php file to update the paths to the vendor directory and the bootstrap file.
sudo nano /var/www/html/your-laravel-project/index.php
Change these lines:
php
require __DIR__.'/../vendor/autoload.php';
$app = require_once __DIR__.'/../bootstrap/app.php';
To:
php
require __DIR__.'/vendor/autoload.php';
$app = require_once __DIR__.'/bootstrap/app.php';
Save and close the file (Ctrl+X, Y, Enter).
Configure Apache
Edit your Apache configuration file to set the DocumentRoot to the Laravel project's root directory.
sudo nano /etc/apache2/sites-available/000-default.conf
Change the DocumentRoot directive to point to your Laravel project's root directory:
apache
DocumentRoot /var/www/html/your-laravel-project
Add the following Directory block:
apache
<Directory /var/www/html/your-laravel-project>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
Save and close the file (Ctrl+X, Y, Enter).
Enable Apache Mod Rewrite
Enable the Apache mod_rewrite module, which is required for Laravel's pretty URLs.
sudo a2enmod rewrite
Restart Apache
Restart Apache to apply the changes.
sudo systemctl restart apache2