PHPackages                             terdelyi/phanstatic - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [CLI &amp; Console](/categories/cli)
4. /
5. terdelyi/phanstatic

ActivePackage[CLI &amp; Console](/categories/cli)

terdelyi/phanstatic
===================

A simple, lightweight and CLI based static site generator

1.1.0(6mo ago)044[1 PRs](https://github.com/terdelyi/phanstatic/pulls)MITPHPPHP &gt;=8.2CI passing

Since Oct 7Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/terdelyi/phanstatic)[ Packagist](https://packagist.org/packages/terdelyi/phanstatic)[ RSS](/packages/terdelyi-phanstatic/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (10)Versions (5)Used By (0)

[![Phanstatic](https://github.com/terdelyi/phanstatic/raw/main/art/logo.png)](https://phanstatic.com)

[![Total Downloads](https://camo.githubusercontent.com/f69d4247ce4909c43b77a075e22e414d24e79832c21bc27e36e525d97ea25c7e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f74657264656c79692f7068616e737461746963)](https://packagist.org/packages/terdelyi/phanstatic)[![Latest Stable Version](https://camo.githubusercontent.com/069e8600c4c94a716ea5b84281c6f6c62eedf2a5f075fa556a6c3503917150ff/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f74657264656c79692f7068616e737461746963)](https://packagist.org/packages/terdelyi/phanstatic)[![License](https://camo.githubusercontent.com/c731591a0e62d6c019e2ae5baca5f174c0984e487ffcbba294ce8b3dde7a1e61/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f74657264656c79692f7068616e737461746963)](https://packagist.org/packages/terdelyi/phanstatic)

Phanstatic is a simple, lightweight, CLI-based static site generator written in PHP, without additional frameworks or template engines.

You don't need to learn any new APIs or syntax: it's just basic PHP pages and Markdown files placed in a `content` directory, which will then be compiled into fast, portable HTML files, ready to deploy on any web server with minimal effort.

Install
-------

[](#install)

To create a new project, run:

```
composer create-project terdelyi/phanstatic

```

If you already have a project with a `content` folder, install Phanstatic with:

```
composer require terdelyi/phanstatic

```

Build
-----

[](#build)

To generate static files from the content in your `content` directory, run the following command from your project root:

```
php ./vendor/bin/phanstatic build

```

The generated files will be placed in the `dist` folder.

Preview
-------

[](#preview)

To preview your site directly from the `content` folder in a browser, run:

```
php ./vendor/bin/phanstatic preview

```

In this mode, you can edit your PHP files, and changes will appear in the browser after refreshing the page.

To preview the built files from the `dist` folder, use:

```
php ./vendor/bin/phanstatic preview --dist

```

You can also customise the host and port with the `--host` and `--port` options. The default values are *localhost*and *8080*.

Configuration
-------------

[](#configuration)

Configuration is optional. You can create a configuration file at `content/config.php`, which must return a `ConfigBuilder` object, for example:

```
use Terdelyi\Phanstatic\Models\Config;
use Terdelyi\Phanstatic\Models\CollectionConfig;

return new Config(
    baseUrl: (string) getenv('BASE_URL'),
    title: 'My super-fast static site',
    collections: [
        'posts' => new CollectionConfig(
            title: 'Posts',
            slug: 'posts',
            pageSize: 10
        ),
    ],
);
```

If no `config.php` file exists, Phanstatic will use the default settings. Your IDE can help you explore the available configuration options, showing the properties and their types.

Content basics
--------------

[](#content-basics)

Organizing your content is simple. The content folder contains your pages, collections, and assets:

- `content/pages`: Place your page templates here using the `.php` extension.
- `content/collections`: Store collections in subdirectories, with individual items as `.md` files.
- `content/assets`: Any files here will be published to `dist/assets`.

You can also use partials: any folder or file starting with an underscore `_` will be ignored during the build. Include these partials in your pages using PHP's `include()` function.

### Example project structure

[](#example-project-structure)

```
├── content
│   ├── assets
│   │   ├── images
│   │   ├── css
│   │   ├── js
│   ├── collections
│   │   ├── posts
│   │   │   ├── my-first-blog-post.md
│   ├── pages
│   │   ├── _partials
│   │   │   ├── header.php
│   │   │   ├── footer.php
│   │   ├── about.php
│   │   ├── index.php
│   ├── config.php
├── composer.json
├── composer.lock

```

If you create a folder under collections, **you must register it in your configuration file**. Otherwise, you will get a "Configuration for collection 'Collection' is missing" error.

Frontend
--------

[](#frontend)

Phanstatic does not include frontend or theme support. You can add your CSS and other assets freely under the assets/ folder, and reference them in your pages using:

```
