Configurations

PHP-Fast has a simple and flexible configuration system. The main configuration file is located at application/Config/Config.php, where you can set up important options for your application, such as app settings, database connections, email, caching, and themes.

Basic Configuration

Below is an overview of the key settings available in config.php:

Application Settings

  • debug – Enable (true) for development, disable (false) for production.

  • environment – Defines the application environment (development, production, etc.).

  • app_url – Sets the base URL of your application.

  • app_name – Specifies the name of your application.

  • app_timezone – Configure the application's default timezone.

'app' => [
    'debug'         => true,
    'environment'   => 'development',
    'app_url'       => 'https://php-fast.net/',
    'app_name'      => 'phpfast',
    'app_timezone'  => 'UTC'
]

Files Settings

  • path – Specifies the directory uploaded files will be stored.

  • allowed_types – Defines the file types that are allowed for upload.

  • max_file_size – Sets the maximum file size that can be uploaded.

  • images_types – Specifies the image formats that can be uploaded.

  • max_file_count – Limits the number of files a user can upload at once.

  • limit – Restricts the total number of files a user can upload over time.

'files' => [
    'path'             => 'writeable/uploads',
    'allowed_types'    => ['jpg', 'jpeg', 'png', 'gif', 'webp'],
    'max_file_size'    => 10485760, 
    'images_types'     => ['jpg', 'jpeg', 'png', 'gif', 'webp','ico','svg'], 
    'max_file_count'   => 10,
    'limit'            => 40, 
]

Security Settings

  • app_id – A unique identifier assigned to your application.

  • app_secret – A private key used to enhance your application's security.

'security' => [
    'app_id'     => '123456',
    'app_secret' => 'keysecret',
]

Database Configuration

  • db_driver – The type of database you are using (e.g., MySQL, PostgreSQL).

  • db_host, db_port – The address and port number of your database server.

  • db_username, db_password – The login details needed to connect to the database.

  • db_database – The database's name .

  • db_charset – The character encoding used for storing and retrieving data.

 'db' => [
    'db_driver'   => 'mysql',
    'db_host'     => '127.0.0.1',
    'db_port'     => 3306,
    'db_username' => 'root',
    'db_password' => '',
    'db_database' => 'phpfast',
    'db_charset'  => 'utf8mb4',
    'db_collate'  => 'utf8mb4_unicode_ci',
]

Email Settings

  • mail_mailer – Specifies the email sending method.

  • mail_host – Defines the SMTP server address.

  • mail_port – Sets the port number used to connect to the SMTP server.

  • mail_username, mail_password – The details used to authenticate with the SMTP server.

  • mail_encryption – Defines the encryption type for secure email transmission.

  • mail_charset – Specifies the character encoding for emails.

  • mail_from_address – Sets the "From" email address for outgoing emails.

  • mail_from_name – Defines the sender's name that appears in the recipient’s inbox.

'email' => [
    'mail_mailer'         => 'smtp',
    'mail_host'           => 'smtp.gmail.com',
    'mail_port'           => 587,
    'mail_username'       => '[email protected]',
    'mail_password'       => 'your_password',
    'mail_encryption'     => 'tls', // Or 'ssl'
    'mail_charset'        =>  'UTF-8',
    'mail_from_address'   => '[email protected]',
    'mail_from_name'      => 'Your name',
]

Cache Settings

  • cache_driver – The storage method for caching data (e.g., Redis, file storage).

  • cache_host, cache_port – The server address and port where the cache is stored.

  • cache_username, cache_password – Login credentials for accessing the cache server (if needed).

  • cache_database – The specific database index used for caching (mainly in Redis).

'cache' => [
    'cache_driver'     => 'redis',
    'cache_host'       => '127.0.0.1',
    'cache_port'       => 6379,
    'cache_username'   => '',
    'cache_password'   => '',
    'cache_database'   => 0,
]

Theme Settings

  • theme_path:The path to the theme directory.

  • theme_name: The theme currently in use.

'theme' => [
    'theme_path' => 'application/Views',
    'theme_name' => 'default'
]

Production Configuration

Web Server Configuration

  • Apache: Set up a virtual host for your application, pointing the DocumentRoot to the public/ directory.

    <VirtualHost *:80>
        ServerName phpfast.net
        DocumentRoot /home/phpfast.net/public_html/public
    
        <Directory /home/phpfast.net/public_html/public>
            AllowOverride All
            Require all granted
        </Directory>
    
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
    </VirtualHost>

.htaccess file:

<IfModule mod_rewrite.c>
    RewriteEngine On

    # Redirect all non-existing files or directories to index.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L,QSA]

    # Ensure index.php is always used as the front controller
    DirectoryIndex index.php
</IfModule>
  • Nginx: Set up a server block for your application, pointing root to the public/ directory.

    server {
        listen 80;
        server_name phpfast.net;
        root /home/phpfast.net/public_html/public;
    
        index index.php index.html index.htm;
    
        location / {
            try_files $uri $uri/ /index.php?$query_string;
        }
    
        location ~ \.php$ {
            include snippets/fastcgi-php.conf;
            fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi_params;
        }
    
        location ~ /\.ht {
            deny all;
        }
    }

Or you can upload all script into /home/phpfast.net/ and public into public_html directory. And change root into this:

root /home/phpfast.net/public_html;

Bootstrapping the App

There are situations where you may need to load the framework without executing the entire application. This is especially useful for unit testing, but it can also be beneficial when using third-party tools to analyze and modify your code.

To accommodate this, the framework includes a dedicated bootstrap script designed specifically for this purpose: system/Core/Bootstrap.php.

During the bootstrap process, most project paths are defined automatically. While you can override these paths using predefined constants, it is important to ensure that your directory structure aligns with the expected layout if you're using the default configuration.

Last updated

Was this helpful?