Mini
Just an extremely simple naked PHP application, useful for small projects and quick prototypes. Some might call it a micro framework :)
Install / Use
/learn @panique/MiniREADME

MINI
MINI is an extremely simple and easy to understand skeleton PHP application, reduced to the max. MINI is NOT a professional framework and it does not come with all the stuff real frameworks have. If you just want to show some pages, do a few database calls and a little-bit of AJAX here and there, without reading in massive documentations of highly complex professional frameworks, then MINI might be very useful for you. MINI is easy to install, runs nearly everywhere and doesn't make things more complicated than necessary.
For a deeper introduction into MINI have a look into this blog post: MINI, an extremely simple barebone PHP application.
Features
- extremely simple, easy to understand
- simple but clean structure
- makes "beautiful" clean URLs
- demo CRUD actions: Create, Read, Update and Delete database entries easily
- demo AJAX call
- tries to follow PSR 1/2 coding guidelines
- uses PDO for any database requests, comes with an additional PDO debug tool to emulate your SQL statements
- commented code
- uses only native PHP code, so people don't have to learn a framework
Forks of MINI
TINY
MINI has a smaller brother, named TINY. It's similar to MINI, but runs without mod_rewrite in nearly every environment. Not suitable for live sites, but nice for quick prototyping.
MINI2
MINI also has a bigger brother, named MINI2. It's even simpler, has been built using Slim and has nice features like SASS-compiling, Twig etc.
MINI3
MINI3 it the successor of MINI, using the original MINI1 native application structure (without Slim under the hood), but with proper PSR-4 autoloading, multiple model classes and real namespaces.
Requirements
- PHP 5.3.0+ (when first released), now it works fine with current stable versions PHP 5.6 and 7.1, 7.2., 7.3 and 7.4. The latest PHP 8.0 is not tested yet but should also work fine.
- MySQL
- mod_rewrite activated (tutorials below, but there's also TINY, a mod_rewrite-less version of MINI)
Installation (in Vagrant, 100% automatic)
If you are using Vagrant for your development, then you can install MINI with one click (or one command on the command line) [Vagrant doc]. MINI comes with a demo Vagrant-file (defines your Vagrant box) and a demo bootstrap.sh which automatically installs Apache, PHP, MySQL, PHPMyAdmin, git and Composer, sets a chosen password in MySQL and PHPMyadmin and even inside the application code, downloads the Composer-dependencies, activates mod_rewrite and edits the Apache settings, downloads the code from GitHub and runs the demo SQL statements (for demo data). This is 100% automatic, you'll end up after +/- 5 minutes with a fully running installation of MINI2 inside an Ubuntu 14.04 LTS Vagrant box.
To do so, put Vagrantfile and bootstrap.sh from _vagrant inside a folder (and nothing else).
Do vagrant box add ubuntu/focal64 to add Ubuntu 20.04 LTS 64bit to Vagrant (unless you already have
it), then do vagrant up to run the box. When installation is finished you can directly use the fully installed demo
app on 192.168.33.44 (you can change this in the Vagrantfile). As this just a quick demo environment the MySQL
root password and the PHPMyAdmin root password are set to 12345678, the project is installed in /var/www/html/myproject.
You can change this for sure inside bootstrap.sh. Shut down the box with vagrant halt
Auto-Installation on Ubuntu 14.04 LTS (in 30 seconds)
You can install MINI including Apache, MySQL, PHP and PHPMyAdmin, mod_rewrite, Composer, all necessary settings and even the passwords inside the configs file by simply downloading one file and executing it, the entire installation will run 100% automatically. Find the tutorial in this blog article: Install MINI in 30 seconds inside Ubuntu 14.04 LTS
Installation
- Edit the database credentials in
application/config/config.php - Execute the .sql statements in the
_install/-folder (with PHPMyAdmin for example). - Make sure you have mod_rewrite activated on your server / in your environment. Some guidelines: Ubuntu 14.04 LTS, Ubuntu 12.04 LTS, EasyPHP on Windows, AMPPS on Windows/Mac OS, XAMPP for Windows, MAMP on Mac OS
MINI runs without any further configuration. You can also put it inside a sub-folder, it will work without any further configuration. Maybe useful: A simple tutorial on How to install LAMPP (Linux, Apache, MySQL, PHP, PHPMyAdmin) on Ubuntu 14.04 LTS and the same for Ubuntu 12.04 LTS.
Server configs for
nginx
server {
server_name default_server _; # Listen to any servername
listen [::]:80;
listen 80;
root /var/www/html/myproject/public;
location / {
index index.php;
try_files /$uri /$uri/ /index.php?url=$uri;
}
location ~ \.(php)$ {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
A deeper discussion on nginx setups can be found here.
Security
The script makes use of mod_rewrite and blocks all access to everything outside the /public folder. Your .git folder/files, operating system temp files, the application-folder and everything else is not accessible (when set up correctly). For database requests PDO is used, so no need to think about SQL injection (unless you are using extremely outdated MySQL versions).
Goodies
MINI comes with a little customized PDO debugger tool (find the code in application/libs/helper.php), trying to emulate your PDO-SQL statements. It's extremely easy to use:
$sql = "SELECT id, artist, track, link FROM song WHERE id = :song_id LIMIT 1";
$query = $this->db->prepare($sql);
$parameters = array(':song_id' => $song_id);
echo Helper::debugPDO($sql, $parameters);
$query->execute($parameters);
Why has the "Error" class been renamed to "Problem"?
The project was written in PHP5 times, but with the release of PHP7 it's not possible anymore to name a class "Error" as PHP itself has a internal Error class now. Renaming was the most simple solution, compared to other options like "ErrorController" etc. which would add new problems like uppercase filenames etc. (which will not work properly on some setups).
License
This project is licensed under the MIT License. This means you can use and modify it for free in private or commercial projects.
My blog
And by the way, I'm also blogging at Dev Metal.
Quick-Start
The structure in general
The application's URL-path translates directly to the controllers (=files) and their methods inside application/controllers.
example.com/home/exampleOne will do what the exampleOne() method in application/controllers/home.php says.
example.com/home will do what the index() method in application/controllers/home.php says.
example.com will do what the index() method in application/controllers/home.php says (default fallback).
example.com/songs will do what the index() method in application/controllers/songs.php says.
example.com/songs/editsong/17 will do what the editsong() method in application/controllers/songs.php says and
will pass 17 as a parameter to it.
Self-explaining, right ?
Showing a view
Let's look at the exampleOne()-method in the home-controller (application/controllers/home.php): This simply shows the header, footer and the example_one.php page (in views/home/). By intention as simple and native as possible.
public function exampleOne()
{
// load view
require APP . 'views/_templates/header.php';
require APP . 'views/home/example_one.php';
require APP . 'views/_templates/footer.php';
}
Working with data
Let's look into the index()-method in the songs-controller (application/controllers/songs.php): Similar to exampleOne, but here we also request data. Again, everything is extremely reduced and simple: $this->model->getAllSongs() simply calls the getAllSongs()-method in application/model/model.php.
public function index()
{
// getting all songs and amount of songs
$songs = $this->model->getAllSongs();
$amount_of_songs = $this->model->getAmountOfSongs();
// load view. within the view files we can echo out $songs and $amount_of_songs easily
require APP . 'views/_templates/header.php';
require APP . 'views/songs/index.php';
require APP . 'views/_templates/footer.php';
}
For extreme simplicity, all data-handling methods are in application/model/model.php. This is for sure not really professional, but the most simple implementation. Have a look how getAllSongs() in model.php looks like: Pure and super-simple PDO.
public function getAllSongs()
