Home

Awesome

apidocs packagist

logo

StaticPHP

Simple, modular php framework. README.md needs to be updated.

Requirements

Installation

There are two ways to start using StaticPHP framework:

  1. Docker <- Suggested one
  2. Composer

1. Using Docker

  1. docker compose build develop
  2. docker compose up -d --remove-orphans develop
  3. Open in vscode using Remote containers

2. Using composer

Run composer create-project 4apps/staticphp ./ for stable version and composer create-project 4apps/staticphp ./ master-dev for latest development version from github. Composer will install all the dependecies for you.

How to install composer?

Npm for SCSS and Javascript

Install node and npm run npm install

How to install node?

* Remember to set correct permissions for Cache directory. For example: chown www-data:www-data ./src/Application/Cache/ or chmod 777 ./src/Application/Cache/

Most quickest way to run your project is to use php's in-built server. To do that, cd into the ./somedir/src/Application/Public and run php -S 0.0.0.0:8081. Now open your server_ip:8081 (or 127.0.0.1:8081) and StaticPHP first page should show up.

or

run npm start

By default, running StaticPHP with php's cli server, turns debugging on, but you can configure that in ./somedir/Applications/Config/Config.php by setting $config['environment'] or $config['debug'] variables.

* Take a look at home controller in ./somedir/src/Application/Modules/Controllers/Welcome.php and views in ./somedir/src/Application/Modules/Views/ for basic framework usage.

Assets

All assets are stored in ./somedir/src/Application/Public/assets/ directory. StaticPHP uses npm to handle css (using SCSS) and js assets, but you can also do it manually.

Cron

Running controller from command line can be done this way: php -f /srv/sites/gm.lv/sla/src/Application/Public/index.php -- --query /defaults/console/refresh

Api

Api documentation*

* Work in progress

Example app

A simple todo application based on sessions. To view the source, checkout the "example" branch.

PHPUnit

To run phpunit tests, install composer dev dependecies (composer install --dev) and then run ./Vendor/bin/phpunit ./src/Application/

ApiGen api documentation

To generate api documentation, install composer dev dependecies (composer install --dev), run ./Vendor/bin/apigen generate ./ --destination ./src/Application/Public/docs ./src or npm run docs and open http://127.0.0.1:8081/docs/

Basic Nginx configuration

server {
    listen       80;
    listen       443 ssl;
    server_name  staticphp.gm.lv;

    root  /www/sites/gm.lv/staticphp/src/Application/Public;
    index index.php index.html index.htm;

    # Error responses
    error_page 403 /errors/E403.html;
    error_page 404 405 =404 /errors/E404.html;
    error_page 500 501 502 503 504 =500 /errors/E500.html;

    # Handle error responses
    location ~ /errors/(E[0-9]*.html) {
        alias /www/sites/gm.lv/staticphp/System/Modules/Core/Views/Errors/$1;
    }

    # Base location
    location / {
        if (!-e $request_filename)
        {
            rewrite  ^(.*)$  /index.php?/$1  last;
        }
    }

    # Allow font origin (for webfonts and similar)
    location ~* \.(eot|ttf|woff|svg)$ {
        add_header Access-Control-Allow-Origin *;
    }

    # Set assets expiration headers to max
    location ~ ^/assets/ {
        expires max;
    }

    # Handle php files
    location ~ \.php(/|$) {
        fastcgi_split_path_info ^(.+?\.php)(/.*)$;
        if (!-f $document_root$fastcgi_script_name) {
            return 404;
        }

        fastcgi_pass  127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO       $fastcgi_path_info;
        fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
        include /etc/nginx/fastcgi_params;

        # To intercept errors from fastcgi and show our error pages instead, otherwise nginx will send to browser whatever response there was from fastcgi
        fastcgi_intercept_errors on;
    }

    # Show 404 for hidden files
    location ~ /\. {
        return 404;
    }
}

TODO and ideas

History

####v1.2.0

####v1.2.0

####v1.1.0

####v1.0.0

####v0.9.5

####v0.9.4

####v0.9.3

####v0.9.2

####v0.9.1

####v0.9

####v0.8