Laravel 10 cPanel Instuctions

Body
The following steps highlight the process for correctly getting Laravel 10 installed on cPanel shared hosting. This moves the Laravel PHP Framework above the browser accessible directory and does not introduce latency due to .htaccess methods which leave the Laravel within the document root and cause redirects on every page load.

Authored on

Framework
  • Install Laravel in the /home/USERNAME folder
    • You should be the directory above public_html
    • Follow the typical install directions
      • composer create-project laravel/laravel laravel-core
  • Delete public_html directory - it should be empty at this point anyway.
  • Symlink public to public_html
    • ln -s /home/user/laravel-core/public /home/user/public_html
  • Symlink storage
    • ln -s /home/user/laravel-core/storage/app/public /home/user/public_html/storage
  • Run storage link
    • php artisan storage:link
  • Change into the config directory
    • cd config
  • Edit database.php (if using MySQL)
    • In the MySQL section change:
      • 'engine' => '', to
      • 'engine' => 'InnoDB',
  • Keep in mind the .env file will need the database credentials added

These are the primary steps needed to move Laravel above the document root in cPanel, thereby removing the public/ from the Laravel URL while also providing better security and speed.

Local Laravel 10.x+ development on Windows

  • If it exists, remove or rename the public_html folder in the site root
  • Copy the entire laravel-core/public directory to /home/USERNAME/
  • rename the /home/USERNAME/public folder to /home/USERNAME/public_html
  • Move to the public_html directory and edit the index.php file
    • Search and replace the three occurrences of __DIR__.'/../ with dirname(__FILE__, 2).'/laravel-core/ 
    • Example replacements we used:
      • dirname(__FILE__, 2).'/laravel-core/storage/framework/maintenance.php'
      • require dirname(__FILE__, 2).'/laravel-core/vendor/autoload.php';
      • $app = require_once dirname(__FILE__, 2).'/laravel-core/bootstrap/app.php';
  • PHPStorm and Laravel Idea Plugin considerations

    If Laravel Idea is not activating in the main menu and in the context menu, ensure it is enabled in Settings->Plugins. Next verify Languages & Frameworks->Laravel Idea->General->Laravel Directory is pointing to the directory containing Laravel. It should not be pointing to public_html or the site root in most instances. In this example it would be pointing to laravel-core.