Getting Acquainted with the Mako Framework in PHP

n0nag0n

n0nag0n

Posted on July 29, 2023

Getting Acquainted with the Mako Framework in PHP

I've recently discovered a great little framework called Mako. It's fast, quick, simple to understand, and I love the engineering and thought put into it (unit testing is a breeze and makes sense!).

Here's a simple "Hello, World!" example using the Mako PHP framework. This guide assumes you have PHP 8.0.0 or higher installed along with ext-json and ext-mbstring. If you plan to use the database library, you'll also need to install ext-pdo. If you have PHP 7.4, you can easily use Mako Framework version 8.*

Creating a Hello World App with Mako Framework

Step 1: Installation

First, you'll need to install the Mako framework. You can do this using composer:

composer create-project mako/app hello_world
Enter fullscreen mode Exit fullscreen mode

This will create a new project named hello_world.

Next, you'll need to make the app/storage/* directories writable. The command may vary depending on your system, but here's a common example:

chmod 0777 -R hello_world/app/storage
Enter fullscreen mode Exit fullscreen mode

In the real world, you would never do 0777 permissions! But in a test environment when learning about a framework, it's totally acceptable!

Step 2: Configuration

By default, only the most essential services are enabled. You can enable the ones you need by uncommenting them in the hello_world/app/config/application.php configuration file.

Step 3: Creating a Hello World Route

In Mako, you can define a route in the app/routing/routes.php file. Let's create a simple route that returns "Hello, World!".

$routes->get('/', function()
{
    return 'Hello, World!';
});
Enter fullscreen mode Exit fullscreen mode

Step 4: Running the App

Mako includes a simple development server which can be started with the following command:

php hello_world/app/reactor app:server
Enter fullscreen mode Exit fullscreen mode

Now, if you open http://localhost:8000 in your browser, you should see "Hello, World!".

Step 5: Updating the Framework

Mako and all your other dependencies can easily be updated when a new patch release is made available using the following command:

composer update
Enter fullscreen mode Exit fullscreen mode

If you want to bump the Mako version (e.g. from 9.0.* to 9.1.*) then you'll have to update your composer.json file before running the update command.

That's it! You've just created a simple "Hello, World!" app using the Mako PHP framework. Happy coding!

Note: The included development server is great when getting started and for quick prototyping but you should probably use a VM or Docker setup that closely resembles your production environment for advanced projects.

💖 💪 🙅 🚩
n0nag0n
n0nag0n

Posted on July 29, 2023

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related