A simple MVC scaffold for PHP and REST API for MySQL/MariaDB. Using this as a learning experience.
[!NOTE] There is support for a 3-component system on one server: Application, API, and a public-facing website. However, the public-facing website is not part of this codebase.
.env
file in root directory and configure variablesapp/inc/global.php
and api/inc/global.php
APP_DB_HOST
, APP_DB_NAME
, APP_DB_USER
, and APP_DB_PASS
API_DB_HOST
, API_DB_NAME
, API_DB_USER
, and API_DB_PASS
uuid_unbin()
: CREATE FUNCTION uuid_unbin(uuid BINARY(16)) RETURNS VARCHAR(36) RETURN LOWER(CONCAT(SUBSTR(HEX(uuid), 1, 8), '-',SUBSTR(HEX(uuid), 9, 4), '-',SUBSTR(HEX(uuid), 13, 4), '-',SUBSTR(HEX(uuid), 17, 4), '-',SUBSTR(HEX(uuid), 21)));
[!TIP] If using MySQL 8.0 or higher, it is advisable to replace
UNHEX(REPLACE(UUID(),'-','')
and its parameterized version,UNHEX(REPLACE(?,'-',''))
withUUID_TO_BIN(UUID())
andUUID_TO_BIN(?)
, repsectively. When selecting UUIDs, you can then useBIN_TO_UUID()
instead of theuuid_unbin()
stored function.
The API is completely separable from the framework (i.e., they do not have to live on the same server). The default configuration works (and looks) best with the api
directory is configured as a subdomain.
api
and public_html/api
directories into another domain folder.public_html/api
to public_html
and delete the now-empty api
directory..htaccess
, compsoer.json
, composer.lock
and your environment variable config (.env
) to the new root directory.HOST
constant is accurate in inc/global.php