- Install Laravel and the API platform
- Configure the API
- Host the API on Cloudways
- How to install Laravel
composer create-project laravel/laravel books-app
cd books-app- How to install API platform
# Install api-platform
composer require api-platform/laravel
# publish assets
php artisan api-platform:install
# Serve website
php artisan serve
# Publishing api-platform config
php artisan api-platform:install- How to update the database
# Create book model
php artisan make:model Book
# Create book migration
php artisan make:migration create_books_table
# Add to database/migrations/<timestamp>_create_books_table.php migration
$table->string('isbn')->nullable();
$table->string('title');
$table->text('description');
$table->string('author');
$table->date('publication_date')->nullable();
# Run migration
php artisan migrate- Updating model
# Update app/Models/Book.php
# Add namespace
# use ApiPlatform\Metadata\ApiResource
# Add class attribute
#[ApiResource]
-
Open site http://127.0.0.1:8000/api/ in browser
-
Make requests to http://127.0.0.1:8000/api/books via Postman
- Login to Cloudways and add a server with the following details:
- Application = PHP Custom App
- Application name = book-app
- Server name = demo
- Project = book-app
- Server = DigialOcean
- Server size = 1GB
- Location = London
-
From Servers -> demo -> Settings and Packages -> Packages update the PHP version to PHP 8.3
-
From Applications -> book-app -> Application Settings Change the webroot from
public_htmltopublic_html/public -
From Applications -> book-app -> Deployment via Git click on Generate SSH Keys
-
Once SSH keys have been created view and copy key
-
Log in to GitHub and go to repository
https://github.com/howToCodeWell/laravel-book-api -
From Settings -> Deploy keys click add deploy key
-
Paste copied key and give it the title of
Cloudways. Click on add key.
-
From Applications -> book-app -> Deployment via Git add git remote address
git@github.com:howToCodeWell/laravel-book-api.gitand click authenticate -
From Applications -> book-app -> Deployment via Git select main branch and click start deployment
-
SSH onto the VPN use credentials found in Servers -> demo -> Master Credentials
-
Go to applications//public_html
-
SSH onto the VPS copy
.env.testto.env -
Create database file
touch database/database.sqlite -
Install composer
composer install -
Install assets
php artisan api-platform:install -
Migrate the database
php artisan migrate -
View app in browser