Tutorials

PHP 7 Compile SCSS to CSS Code in Command Line Using scssphp Library

scssphp is a free and open source compiler for SCSS that is written using PHP programming language.

Basically, SCSS is a CSS preprocessor language that gives us additional features like variables, functions, mixins, imports, control directives, nesting, and color manipulation.

You can easily use scssphp in any existing or new PHP-based project. It is packed with a command line tool that enables us to execute the compiler from a terminal/shell script.

Install scssphp

The source code of scssphp is available on GitHub. To install scssphp, simply select the latest release and download it on your computer.

If you use Packagist for installing packages, then update your composer.json file as mentioned below:

{
    "require": {
        "scssphp/scssphp": "^1.10.3"
    }
}

Command Line Tool

A really basic command line tool is included for integration with scripts. It is called pscss. It reads SCSS from either a named input file or standard in, and returns the CSS to standard out.

Usage: bin/pscss [options] [input-file] [output-file]

Available Options

If passed the flag -h (or --help), input is ignored and a summary of the command’s usage is returned.

If passed the flag -v (or --version), input is ignored and the current version is returned.

The flag -s (or --style) can be used to set the output style:

<span class="nv">$ </span>bin/pscss <span class="nt">-s</span> compressed styles.scss

The flag -I (or --load_path) can be used to set import paths for the loader. On Unix/Linux systems, the paths are colon-separated. On Windows, they are separated by a semi-colon.

SCSSPHP Library Reference

To use the scssphp library either require scss.inc.php or use your composer generated auto-loader, and then invoke the \ScssPhp\ScssPhp\Compiler class:

require_once "scssphp/scss.inc.php";

use ScssPhp\ScssPhp\Compiler;

$compiler = new Compiler();

echo $compiler->compileString('
  $color: #abc;
  div { color: lighten($color, 20%); }
')->getCss();

The compileString method takes the SCSS source code as a string and an optional path of the input file (to resolve relative imports), and returns a CompilationResult value object containing the CSS and some additional data. If there is an error when compiling, a \ScssPhp\ScssPhp\Exception\SassException is thrown with an appropriate message.

Furqan

Well. I've been working for the past three years as a web designer and developer. I have successfully created websites for small to medium sized companies as part of my freelance career. During that time I've also completed my bachelor's in Information Technology.

Recent Posts

ChatGPT Atlas vs Google Chrome: Which Browser Should You Choose in 2025?

Google Chrome has dominated web browsing for over a decade with 71.77% global market share.…

October 25, 2025

Is Perplexity Comet Browser Worth It? The Honest 2025 Review

Perplexity just made its AI-powered browser, Comet, completely free for everyone on October 2, 2025.…

October 25, 2025

Is ChatGPT Atlas Worth It? A Real Look at OpenAI’s New Browser

You've probably heard about ChatGPT Atlas, OpenAI's new AI-powered browser that launched on October 21,…

October 25, 2025

Perplexity Comet Browser Alternatives: 7 Best AI Browsers in 2025

Perplexity Comet became free for everyone on October 2, 2025, bringing research-focused AI browsing to…

October 25, 2025

ChatGPT Atlas Alternatives: 7 Best AI Browsers in 2025

ChatGPT Atlas launched on October 21, 2025, but it's only available on macOS. If you're…

October 25, 2025

ChatGPT Atlas vs Comet Browser: Best AI Browser in 2025?

Two AI browsers just entered the ring in October 2025, and they're both fighting for…

October 25, 2025