Skip to main content
Version: 5.x

Installing BowPHP

Introduction​

BowPHP is a modern and elegant PHP micro-framework. Before creating your first application, make sure your environment meets the following requirements.

System requirements​

  • PHP >= 8.2
  • OpenSSL PHP Extension
  • PDO PHP Extension
  • Mbstring PHP Extension
  • XML PHP Extension
  • JSON PHP Extension
Development environments

If you use Laragon (Windows), XAMPP, or MAMP, these extensions are generally already installed and configured.

Creating a project​

BowPHP uses Composer to manage its dependencies. Make sure Composer is installed on your machine before continuing.

Installation via Composer​

composer create-project --prefer-dist bowphp/app nom-du-projet
Installing Composer

We recommend installing Composer globally on your machine. See the official documentation for installation instructions.

If you are new to Composer, take the time to read through its documentation to understand how it works.

asciicast

Starting your project​

Go to the root of your project and start the development server:

cd nom-du-projet
php bow run:server --port=8080 --host=0.0.0.0

Open your browser and go to http://localhost:8080.

Default port

If you do not specify a port, the server starts on port 5000 by default:

php bow run:server
# Accessible at http://localhost:5000

Configuration​

Public directory​

After installation, configure your web server's document root to point to the public directory.

The index.php file located in this directory serves as the single entry point for all HTTP requests (the Front Controller pattern).

Configuration files​

All of BowPHP's configuration files are located in the config directory. Each option is documented to make it easier to customize your application.

Structure of the config directory:

  • app.php: Application configuration
  • database.php: Database configuration
  • mail.php: Email sending configuration
  • And many more...

Directory permissions​

The directories contained in var must have write permissions for the web server:

# On Linux/macOS
chmod -R 775 var/
chown -R www-data:www-data var/
Important

Make sure the web server has write permissions on the var directory so that logs, cache, and sessions work correctly.

Web server configuration​

Apache​

Bow includes a public/.htaccess file that handles URL rewriting to the front controller.

Requirement: The mod_rewrite module must be enabled.

# Enable mod_rewrite on Ubuntu/Debian
sudo a2enmod rewrite
sudo systemctl restart apache2

If the default .htaccess file does not work, try this alternative configuration:

Options +FollowSymLinks
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

Nginx​

For Nginx, add this configuration to your site file:

/etc/nginx/sites-available/bow-app
server {
listen 80;
server_name example.com www.example.com;
root /var/www/bow-app/public;
index index.php;

# Logs
access_log /var/log/nginx/bow-app.access.log;
error_log /var/log/nginx/bow-app.error.log;

# Security - Headers
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-Content-Type-Options "nosniff" always;
add_header X-XSS-Protection "1; mode=block" always;
add_header Referrer-Policy "strict-origin-when-cross-origin" always;

# Gzip compression
gzip on;
gzip_vary on;
gzip_min_length 1024;
gzip_types text/plain text/css text/xml text/javascript
application/javascript application/json application/xml;

# Front Controller
location / {
try_files $uri $uri/ /index.php?$query_string;
}

# PHP-FPM
location ~ \.php$ {
fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
fastcgi_hide_header X-Powered-By;
}

# Static assets cache
location ~* \.(css|js|jpg|jpeg|png|gif|ico|svg|woff|woff2|ttf|eot)$ {
expires 1y;
add_header Cache-Control "public, immutable";
access_log off;
}

# Block access to sensitive files
location ~ /\.(env|git|htaccess) {
deny all;
}

location ~ ^/(var|vendor|config|migrations|seeders)/ {
deny all;
}
}

Nginx with SSL (HTTPS)​

/etc/nginx/sites-available/bow-app-ssl
server {