lavarel 10 being download on cpanel server

To install Laravel 10 on shared hosting and handle the issue with the public directory, you can follow these steps:

  1. Upload Your Laravel Application:
    • Compress your Laravel application into a zip file.
    • Upload the zip file to your shared hosting account, usually through a cPanel file manager or via FTP.
    • Extract the zip file to the desired directory on your shared hosting.
  2. Modify the public Directory:
    • Since you can’t change the document root, you’ll need to move the contents of the public directory to the root directory of your domain (often public_html or htdocs).
    • Move the .htaccess and index.php files from the public directory to the root directory.
  3. Update index.php:
    • Edit the index.php file in the root directory to update the paths to autoload.php and app.php:
    Copyrequire __DIR__.'/../vendor/autoload.php'; $app = require_once __DIR__.'/../bootstrap/app.php'; Change these lines to (assuming that the rest of your Laravel app is one level above the public_html):Copyrequire __DIR__.'/../your-laravel-directory/vendor/autoload.php'; $app = require_once __DIR__.'/../your-laravel-directory/bootstrap/app.php';
  4. Create or Modify the Root .htaccess File:
    • If you don’t already have a .htaccess file in your root directory, create one.
    • Add the following rules to handle the redirection and removal of the /public from the URL:
    Copy<IfModule mod_rewrite.c> RewriteEngine On RewriteRule ^(.*)$ public/ [L] </IfModule>
    • If you’re facing issues with trailing slashes, you can add the following rules to handle that:
    Copy<IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} (.+)/$ RewriteRule ^ %1 [L,R=301] RewriteRule ^(.*)$ public/ [L] </IfModule> This will remove the trailing slash for non-directory requests and then rewrite the request to the public directory.
  5. Secure Sensitive Directories:
    • To prevent public access to sensitive directories like /vendor or your .env file, you can add additional rules to your .htaccess file:
    Copy<IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{REQUEST_URI} ^/(vendor|storage|.env)(/|$) RewriteRule ^ - [F,L,NC] </IfModule>
  6. Test Your Application:
    • After making these changes, visit your website and test to ensure that everything is working correctly.
    • Check different routes and add trailing slashes to see if the redirection works as expected.

Remember to replace your-laravel-directory with the actual directory name where your Laravel application resides on the server. Also, ensure that your server meets all the requirements for running Laravel 10, such as PHP version and necessary PHP extensions.


Discover more from Soa Technology | Aditya Website Development Designing Company

Subscribe to get the latest posts sent to your email.



Leave a Reply

Discover more from Soa Technology | Aditya Website Development Designing Company

Subscribe now to keep reading and get access to the full archive.

Continue reading