Getting Started with OriginPHP

What is OriginPHP?

OriginPHP is a web application framework written in PHP that uses a number of well known software design patterns, including convention over configuration, MVC (Model View Controller), association data mapping, and front controller.

Installation

Download and install Composer, then run the following command to create a new project

$ composer create-project originphp/app <folder>

OriginPHP comes with both a built-in development server and a dockerized development environment (dde) which works exactly like a real server would work and includes MySQL. Its very easy to setup and work with and it will give you consistent results.

Built-in Development server

To run the built-in development server:

$ cd <folder>
$ bin/server 8000

Then open your web browser and go to http://localhost:8000 which will show you a status page that all is working okay.

Dockerized Development Environment

To work with Docker, install Docker Desktop then build the docker containers, this must be done from within the project folder. The build process takes a couple of minutes but only needs to be done once.

$ cd <folder>
$ docker-compose build

Once the Docker container has been built, you will use the up and down commands to start and stop the docker container which takes seconds.

$ docker-compose up

Then open your web browser and go to http://localhost:8000 which will show you a status page that all is working okay.

The configuration settings for MySQL are:

  • host: db (from within the Docker container)
  • username: root
  • password: root

To access the Docker container (linux prompt).

$ docker-compose run app bash

You can also access the MySql server using any database management application using localhost port 3306. Mac users can use Sequel Pro or Windows users can use Heidi SQL.

If you want to work with PostgreSQL then see the dockerized development environment (dde) guide for information on how to set this up.

Configure the Database Connection

When you create the project with Composer, it will create a copy of config/.env.php.default and save as config/.env.php file, this contains the environment vars for this installation, if you are not using Dockerized Development Environment you will need to adjust the database settings.

/**
 * Database Settings
 */
'DB_HOST' => 'db',
'DB_USERNAME' => 'root',
'DB_PASSWORD' => 'root',
'DB_ENGINE' => 'mysql',

Next you need to run the db:setup command, if you are using the Dockerized Development Environment, you will need to access the container first, this is because the hostname for accessing the MySQL server is different from within the container.

To access the Docker container:

$ docker-compose run app bash

Then run the db:setup command to set everything up for you.

$ bin/console db:setup

The db setup command will :

  • Create the database
  • Load the schema from database/schema.sql file (if its found)
  • Seed the database with records from the database/seed.sql file if its found

If all went well when you go to http://localhost:8000 it should now say that it is connected to the database.