Home >Backend Development >PHP Tutorial >Day Host Static App on GitHub Pages
GitHub Pages is designed for hosting static sites, which means it doesn't support PHP applications like Laravel out of the box. However, you can host the static frontend part of your Laravel application by exporting the compiled assets (HTML, CSS, and JavaScript) using Laravel's artisan commands and tools.
Here's how you can adapt a Laravel "Hello World" app for GitHub Pages:
Route::get('/', function () { return view('welcome'); // Or replace 'welcome' with your view file. });
Ensure your app runs locally with php artisan serve.
Use the laravel-export package to export your Laravel views as static HTML files.
Install it via Composer:
composer require spatie/laravel-export
Publish the configuration file:
php artisan vendor:publish --provider="Spatie\Export\ExportServiceProvider"
Run the following command to export your Laravel routes to static HTML files:
php artisan export
The static files will be saved in the storage/export directory by default (you can change the output path in the config/export.php file).
Navigate to the storage/export directory and copy all the files to a new folder in your project, e.g., dist.
Initialize Repo
Commit the Code
Publish the Repo
Your site will be live at https://your-username.github.io/your-repo/.
The above is the detailed content of Day Host Static App on GitHub Pages. For more information, please follow other related articles on the PHP Chinese website!