SucklessPHP - Another PHP framework that sucks less
This framework is my laser cannon that I used to develope dozen of very-different Content Management Systems made from scratch.
Note that I very often deprecate and kill stuff depending on how I feel in the morning.
I can create a RDBMS CMS with these features:
- efficient (very tiny footprint)
- on demand resource loader (e.g. DB connection is instantiated only if you use it, etc.)
- query builder
- associative options
- database table prefix
- login and user capabilities (WITHOUT the need of PHP sessions)
- secure file uploads with MIME type checks etc.
- multilanguage (using the widely used GNU Gettext native or high-level)
Obviously a webserver with PHP and MySQL or MariaDB working. Personally I have a simple GLAMP machine (GNU/Linux + Apache + PHP + MySQL or MariaDB). Extra packages suggested:
libmagic-dev package is in the main Debian GNU/Linux repository and so I think it is in all other GNU/Linux distributions. It is needed only if you need to upload files.
Simplest shared installation
As a shared library: one can serve many sites with a simple
require. Start cloning the source-code in a shared folder as
sudo git clone https://github.com/valerio-bozzolan/suckless-php.git /usr/share/php/suckless-php
That's it! Leave that folder as is, you don't have to touch it anymore.
Go to your website folder (e.g.
/var/www/blog), and create your friendly config file. I use to call it
load.php and please do so. Write in something as:
<?php $username = 'Your database username'; $password = 'The password of your database user'; $database = 'Your database name'; $location = 'localhost'; // Table prefix, if any! $prefix = 'blog_'; // To avoid the auto-load of your local load-post.php // define('REQUIRE_LOAD_POST', false); // That's it! This will load the framework with the above configurations require '/usr/share/php/suckless-php/load.php';
And now create your first file e.g.
<?php require 'load.php'; $row = query_row("SELECT NOW() as time"); echo $row->time; echo "If you see the datetime, the database works!";
You can add support for user autentication / user permissions and associative options importing the database schema into your database. To do it you should have received a file called
example-schema.sql in the
examples framework folder. Import it into your database. Actually there are only two tables.
Have to specify these:
string) The database username.
string) The password of the database username.
string) The database name.
string) The database location.
string) The database table prefix.
string) The absolute pathname of your site (
__DIR__is your friend). No trailing slash.
string) The absolute request pathname (something as
/blogor simply an empty string). No trailing slash.
Definibles (as (
false: Enable verbose debugging.
false: The queries are logged, and also printed when also
string): Default is the protocol of the request (
https://). It builds the
string): Default is your domain name. You can override it. It builds the
string): Default is
PROTOCOL . DOMAIN . ROOT.
string: As default it's
ABSPATH . '/load-post.phpand it's a file that describes your CMS.
What you have then
Well. I hope to auto-document it with inline comments. For now you can just see
functions.php in the framework folder.
Own functions / stuff
It's normal to have your own custom configuration of this framework. So the
load-post.php file is made for you. Create it and write in it what you want:
Copyright (c) 2015-2019 Valerio Bozzolan
This is a Free as in Freedom project. It comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under the terms of the GNU General Public License v3+.