oriondevelops / larashared
Shared Hosting Deployment Management for Laravel
Requires
- php: ^8.1
- illuminate/contracts: ^9.0
- laravel/framework: ^9.0
- spatie/laravel-package-tools: ^1.9.2
Requires (Dev)
- laravel/pint: ^1.0
- nunomaduro/collision: ^6.0
- nunomaduro/larastan: ^2.0.1
- orchestra/testbench: ^7.0
- pestphp/pest: ^1.21
- pestphp/pest-plugin-laravel: ^1.1
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
- phpunit/phpunit: ^9.5
README
Larashared
Shared Hosting Deployment Management for Laravel
Larashared is a deployment guide and a helper api in shared hosting environments where ssh access is not available.
It allows using basic Artisan commands through an API by sending post requests with a bearer token for authorization. The package can be installed via composer and the configuration file can be published to modify the API path and the token. The package has several endpoints for different Artisan commands like optimizing, enabling/disabling maintenance mode, cache operations, etc.
Disclaimer
Deploying Laravel on shared hosting is not recommended. Check out this article by Pardeep Kumar:
Here’s Why You Should Stay Away From Laravel Shared Hosting
Support me
Installation
You can install the package via composer:
composer require oriondevelops/larashared
You can publish the config file with:
php artisan vendor:publish --tag="larashared-config"
This is the contents of the published config file:
return [ /* |-------------------------------------------------------------------------- | API Path |-------------------------------------------------------------------------- | | This is the URI path where API will be accessible from. Feel free to | change this path to anything you like. | */ 'path' => env('LARASHARED_PATH', 'larashared'), /* |-------------------------------------------------------------------------- | Token |-------------------------------------------------------------------------- | | This value is the token the API will be accessible with. | */ 'token' => env('LARASHARED_TOKEN', '1|gnmyXCnxxN23MAMxx2dCv5BgT4cUOo6ZWSdUPqWT'), ];
Deployment
-
Make a fresh copy of your application 🎁
-
Build your production assets 🔧
# For example npm install npm run build
-
Install dependencies excluding dev packages ↙️
composer install --optimize-autoloader --no-dev
npm install --omit=dev
-
Create the .env and fill it according to your shared hosting settings and add
LARASHARED_TOKEN
to your .env file 🔁 -
You can now copy the default htaccess file and set a random token by the
larashared:install
Artisan command ⚙️php artisan larashared:install
-
Move your application with all files and folders to your root folder by FTP 🚀
-
(Optional) Run your migrations using migration endpoint ↗️
Usage
Authorization
Authorization: Bearer <<Your Token>>
You can now send post requests to the endpoints using your token.
POST /larashared/optimize
<?php $client = new Client(); $request = new Request('POST', 'https://example.com/larashared/optimize'); $res = $client->sendAsync($request)->wait(); echo $res->getBody();
Response
{ "success": true, "data": "Success", "message": "Command successful." }
API Endpoints
Maintenance Mode
Form Data
status
secret
refresh
retry
Status should be "up" or "down", it will be down if not specified.
Others are the same options of the artisan command. More information can be found at Laravel Docs.
To be able to use the api in maintenance mode, do not forget to update following middleware.
// app/http/middleware/PreventRequestsDuringMaintenance.php /** * The URIs that should be reachable while maintenance mode is enabled. * * @var array<int, string> */ protected $except = [ 'larashared/*' ];
Migrate
POST /larashared/migrate
POST /larashared/migrate/fresh
POST /larashared/migrate/refresh
POST /larashared/migrate/rollback
POST /larashared/migrate/reset
Form Data
seed
force
pretend
step
Seed
POST /larashared/seed
Form Data
class
force
Optionally seeder class can be specified by class parameter.
If you plan to seed your application, make sure dev dependencies like fakerphp/faker
are installed.
Credits
License
The MIT License (MIT). Please see License File for more information.