GEMVC Documentation
Complete guide to building modern, secure PHP applications with GEMVC framework
🚀 Quick Start Guide (Dockerized)
Welcome to GEMVC! This guide will help you get your first API up and running in minutes. This guide is for Docker installation.
Prerequisites
- Docker installed on your machine. if you don't have docker, you can install it from here
- Composer installed on your machine. if you don't have composer, you can install it from here
Zero to Running in 60 Seconds with creating empty folder on your machine
1. GEMVC Installation (Dockerized OpenSwoole)
1. go to your newly created folder and install GEMVC with composer:
Tip: be sure you have installed composer and php 8.0 or higher
composer require gemvc/library
2. Initialize your project with gemvc init command:
info: if you want to use apache as webserver, you can choose it in Prompt
(IMPORTANT) choose openswoole as webserver in Propmt
php vendor/bin/gemvc init
4. build and run your development server:
info: GEMVC comes with a ready-to-use Docker setup (PHP, MySQL, Redis, PHPMyAdmin). No manual config needed!
info: be sure your docker desktop is installed and running!
5. build and run your application:
docker-compose up --build
6. run composer updates:
composer update
7. test your installation:
http://localhost:9501
your achivements
info: gemvc create tow service by default in your application , index and user. user is functional example of AAA and CRUD
2. Initialize Database
1. following command will create database in your Mysql :
info: if you want your database has different name rather than gemvc_db you can change database name in .env file before running this command
php vendor/bin/gemvc db:init
Output:
Info: Initializing database...
Info: trying to connect to the database as root on the host localhost...
Success: Connected to the database as root successfully
Success: Database gemvc_db initialized successfully!
2. migrate User Table :
php vendor/bin/gemvc db:migrate UserTable
Output:
Info: trying to connect to the database gemvc_db on the host localhost...
Success: Connected to the database gemvc_db on the host localhost successfully
Info: Table users does not exist. Creating new table...
Success: Table users created successfully!
Success: UserTable migrated successfully!
info: if you want to see table structure you created in database, you can use following command:
php vendor/bin/gemvc db:describe users
info: gemvc use actual table name on database not class name to describe it!
3.Create Your First API
Generate a complete CRUD API for a resource:
php vendor/bin/gemvc create:crud Product
This creates:
3.Create table in Database
Generate Table in Database based on your Table-Layer (in this case app/table/ProductTable.php class):
php vendor/bin/gemvc db:migrate ProductTable
Tip: if you want to see table structure you created in database, you can use following command:
php vendor/bin/gemvc db:describe products
info: GEMVC Table Layer classes have special method getTable() that returns table name , you can define your table name inside this method
4. Test Your API
Try your endpoint:
http://localhost:9501/product/list
Tip: if you choose openswoole as webserver, port is localhost:9501 in apache is localhost:80
Or visit the auto-generated API docs.
Sample response:
{
"response_code": 200,
"message": "OK",
"count": 0,
"service_message": "list of products fetched successfully"
"data": [],
}