Sign Up

welcome

Already have an account? Sign In

Sign In

welcome

Sign Up
Login with Google

Don't have account, Sign Up Here
Sign In Sign Up

letsrectify

letsrectify
  • Home
  • About Us
  • Contact Us
  • Jobs
Ask a Question
Home
aman
Asked: 31-07-24

If you are seeing the "public" directory in the URL of your Laravel application hosted on an EC2 Ubuntu instance, you can resolve this by configuring your Apache server to serve your Laravel application correctly. Here are the steps to remove the "public" from the URL:

  • 0

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

https://www.letsrectify.com/answer/ODM5/letsrectify" data-action="share/whatsapp/share"> Share
  • Facebook
  • https://www.letsrectify.com/answer/ODM5/letsrectify" data-action="share/whatsapp/share">

0 More Answers

  • Answers
Cancel reply

Sidebar

Ask A Question
letsrectify

Categories

  • Technology
  • Food
  • Health
  • Sports
  • Science
  • Politics
  • Marketing

Policies

  • Terms & Conditions
  • Privacy Policy

About Us

  • About Us
  • Contact Us
  • Feedback

© 2025 All Rights Reserved by
Letsrectify.com