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
Terminal
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

Terminal
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:

Terminal
docker-compose up --build

6. run composer updates:

Terminal
composer update

7. test your installation:

Terminal
http://localhost:9501

your achivements

Dockerized Application: you have a dockerized application with php, mysql, redis, phpMyAdmin
to Access api: if you choose open swoole you can access to localhost:9504 and if you choose apache you have access to it on localhost:8080
To Access database: you can access to database with phpMyAdmin on localhost:8080 USERNAME: root and PASSWORD: rootpassword
To Access redis: you can access to redis with redis-cli on localhost:6379 PASSWORD: rootpassword
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
Terminal
php vendor/bin/gemvc db:init

Output:

Terminal
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 :

Terminal
php vendor/bin/gemvc db:migrate UserTable

Output:

Terminal
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:
Terminal
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:

Terminal
php vendor/bin/gemvc create:crud Product

This creates:

app/api/Product.php
API endpoints for your resource
app/controller/ProductController.php
Business logic and request handling
app/model/ProductModel.php
Data model for your resource
app/table/ProductTable.php
Database schema definition

3.Create table in Database

Generate Table in Database based on your Table-Layer (in this case app/table/ProductTable.php class):

Terminal
php vendor/bin/gemvc db:migrate ProductTable
Tip: if you want to see table structure you created in database, you can use following command:
Terminal
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:

Terminal
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:

JSON
{ 
"response_code": 200,
"message": "OK",
"count": 0,
"service_message": "list of products fetched successfully"
"data": [],
}