Slim Example Project Installation Guide

Table of contents

Loading...

Requirements

To install and run the slim-example-project, you need to have PHP 8.2 or higher, Composer, and a MariaDB or MySQL server installed and running on your machine.

XAMPP or DDEV are easy options to quickly set up a local development environment with all the necessary parts.

1. Create project

Navigate to the directory you want to create the project in and run the following command, replacing project-name with the desired name for your project:

composer create-project samuelgfeller/slim-example-project project-name

This will create a new directory with the specified name and install all necessary dependencies.

Alternatively, you can use GitHub's Use this template feature to quickly create a repository with the code of this project. Checkout this repository in your preferred IDE before proceeding.

2. Set up the database

After opening the project in your IDE, rename the file config/env/env.example.php to config/env/env.php and fill in your database credentials.

Then, create the database for the project on the MySql server (e.g. via phpMyAdmin) and add the name to the config/env/env.dev.php file, like this:

$settings['db']['database'] = 'my_database_name';

After that, create a separate database for testing and add the name to the config/env/env.test.php file. The name must contain the word "test" as a safety measure to prevent accidentally truncating the development database while testing:

$settings['db']['database'] = 'my_database_name_test';

3. Run migrations

Open the terminal in the project's root directory and run the following command to create the necessary tables for the project:

composer migrate

4. Insert data

You can choose to insert only the minimal required data for the app to function such as an admin user and user roles, or also include some dummy example data.

To insert the minimal data, run:

composer seed

To insert both minimal and dummy data, run:

composer seed:extended

5. Update GitHub workflows

Build testing
To run the project's tests automatically when pushing, update the .github/workflows/build.yml file.
Replace the matrix value "test-database" with the name of your test database as specified in config/env/env.test.php.

Update timezone
If you are not in the Europe/Zurich or +01:00 timezone, update the database-time-zone matrix value in .github/workflows/build.yml and config/defaults.php to your timezone.

Scrutinizer
If you don't plan on using Scrutinizer, remove the .scrutinizer file at the root of the project, otherwise you can follow this guide on how to set it up.

Deployment
If you are not planning on deploying your app, delete or comment out the contents of the .github/workflows/deploy.yml file.

To deploy your app, update the .github/workflows/deploy.yml file according to your needs and add your server's credentials to GitHub's Actions secrets.

Done!

That's it! Your project should now be fully set up and ready to use.
If you are using XAMPP and installed the project in the htdocs folder, you can access it via http://localhost/project-name.
Or you can serve it locally by running php -S localhost:8080 -t public/ in the project's root directory.

^