Authored on
Danger
These instructions are for a newly created website, as such following them may delete files and content. Use at your own risk.
- 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',
- In the MySQL section change:
- 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
- Search and replace the three occurrences of
__DIR__.'/../
withdirname(__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';
Warning
The build directory provides the required CSS and JS assets for page presentation. If pages are not appearing, (e.g, the login or register page) make sure the .htaccess file is in the same folder as the index.php as it handles the friendly URLs.
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
.