This page looks best with JavaScript enabled

OpenLiteSpeed with PHP Slim Framework

 ·  ☕ 2 min read  ·  🐨 Puliyo


Have PHP Framework Slim v4 running in OpenLiteSpeed v 1.6.12 on CentOS 8.

How To

1. Install OpenLiteSpeed

Install OpenLiteSpeed through repository. Further instruction here.

rpm -Uvh
yum install openlitespeed

2. Access WebAdmin Console

Access to WebAdmin on port 7080. Default password is 123456 however if it does not work, reset it by running the script.



3. Create Virtual Host

In WebAdmin, click on Virtual Hosts, then + button to add virtual host.

Below is my Virtual Host configuration.

Virtual Host Name:	runslim
Virtual Host Root:	/usr/local/lsws/vhosts/$VH_NAME/
Config File:		$SERVER_ROOT/conf/vhosts/$VH_NAME/vhconf.conf
suEXEC User:		user_01
suEXEC Group:		user_01
Document Root:		$VH_ROOT/html/public
Temporary File Path:	$VH_ROOT/tmp
Command: $SERVER_ROOT/lsphp73/bin/lsphp
Enable Rewrite: Yes
Rewrite Rules:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [QSA,L]

Below is my Listener configuration.

IP Address:	Any
Port:		80
	Virtual Host:	runslim
	Domains:	*

Create necessary dirs and change the permission

OpenLiteSpeed needs to have at least read access to Document Root otherwise user will be welcomed with 4xx access denied error message.

When you install OpenLiteSpeed using repo, the system user (and group) will be nobody.

# as root
# cd /usr/local/lsws/vhosts/
# mkdir -p runslim/html/public
# cd runslim
# chown -R user_01:nobody html
# chmod -R 750 html

5. Install Slim

Assumes you have already installed composer.

# as user_01
$ cd /usr/local/lsws/vhosts/runslim/html
$ composer require slim/slim:"4.*"
$ composer require slim/psr7
$ touch public/index.php

Content of public/index.php

use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Slim\Factory\AppFactory;

require __DIR__ . '/../vendor/autoload.php';

$app = AppFactory::create();

$app->get('/', function (Request $request, Response $response, $args) {
    $response->getBody()->write("Hello world!");
    return $response;


6. Start the server and test

Graceful restart OpenLiteSpeed.

Access to the website and you’ll see “Hello world!” on the screen.


Share on
Support the author with