You don't have to install ruby/Node.JS stack no more.
You need only to install the PHP and Compile .scss and .sass files using PHP.
php-sass provides a PHP interface to libsass, a fairly complete Sass compiler written in C++.
<?php
$sass = new Sass();
$str = <<<'SASS'
div {
a {
color: black
}
}
div a {
color: black;
}
SASS;
$str = $sass->compile($str);
var_dump($str);
<?php
$file = 'input.sass';
$sass = new Sass();
$css = $sass->compileFile($file);
var_dump($css);
<?php
$file = 'input.sass';
$sass = new Sass();
// saved 'css-output-dir/input.css'
$css = $sass->compileFile($file, 'css-output-dir');
var_dump($css);
<?php
$file = 'input.sass';
$sass = new Sass();
$sass->setOutputStyle(Sass::STYLE_COMPRESSED);
// saved 'css-output-dir/input.css'
$css = $sass->compileFile($file, 'css-output-dir');
var_dump($css);
<?php
$file = "input/base.scss";
$sass = new Sass();
//$sass->setVerboseLevel(Sass::VERBOSE_LEVEL_TRACE);
// Emit source map to 'map' dir
$sass->setSourceMapPath('map');
// STYLE_COMPRESSED, STYLE_COMPACT,STYLE_EXPANDED, STYLE_NESTED
$sass->setOutputStyle(Sass::STYLE_EXPANDED);
// Emit comments showing original line numbers.
$sass->setSourceComment(true);
// Omits the source map url comment.
$sass->setOmitSourceMapUrl(true);
// Set the precision for numbers.
$sass->setPrecision(5);
// Set Sass import path.
$sass->setLoadPath('include');
// Set path to autoload plugins.
$sass->setPluginPath('plugin');
// saved to 'css/base.css' and 'map/base.css.map'
$css = $sass->compileFile($file, 'css');
var_dump($css);
- download latest pre-built binary
- extract it
tar zxvf php-sass.tar.gz
- run install script as root.
sudo ./install.sh
- gcc/g++ 4.8 or above(libsass requires gcc 4.8)
- php 5.5 or above
- php devel package(The package name is different for each distro.)
- PHP-CPP
- libsass
sudo apt-get install gcc g++ php7.0-dev
sudo apt-get install gcc g++ php5-dev
yum install gcc gcc-c++ php70w-cli php70w-devel
Mac OS X users need install gcc6.
brew install gcc6 --enable-cxx
-
checkout project
git clone --recurse-submodules https://github.com/lesstif/php-sass cd php-sass
-
build libsass
-
change directory
bash cd libsass
-
check out stable version.
```bash
git checkout 3.3.6
```
- build libsass shared library.
```bash
BUILD="shared" make
```
- install libsass shared library to /usr/local/lib.
```bash
sudo BUILD="shared" make install
```
-
build PHP-CPP
-
change directory
bash cd ../PHP-CPP
-
Linux User
1. build PHP-CPP for PHP 5.6 or below (need v1.5.3 branch)
```bash
git checkout v1.5.3
make PHPCPP_15=1
```
1. PHP 7.0 or above users just run make.
```bash
make
```
-
Mac OS X User
-
open the Makefile and change -soname option to -install_name .
-
add LINKER_FLAGS*-undefined dynamic_lookup*
LINKER_FLAGS = -shared -undefined dynamic_lookup
-
run make
make CXX=g++-6
-
-
install PHP-CPP library to /usr/local/lib.
```bash
sudo make install
```
-
build PHP-CPP (Mac OS X)
-
appending below line to the shell config file(ex: .profile, .bash_profile) in your home directory; then log out and log in again.
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
-
build php-sass module.
-
change directory
```bash
cd ../
```
-
build
make
```
if you are using RHEL derived distro, make with custom option.
```bash
make CENTOS=1
```
if you are using Mac OS X, make with *CXX=g++-6* and *MACOS=1* option.
```bash
make CXX=g++-6
```
-
install php-sass to PHP modules directory.
sudo make install
php -r "phpinfo(INFO_MODULES);"|grep -i sass
- Tested with below environments.
- PHP 7.0 on ubuntu 16LTS
- PHP 5.6 on ubuntu 14LTS
- PHP 7.0( WebTatic Resository) on CentOS 7