サーバー設定 · 7 min read · Nov 24, 2025

Ubuntu 20.04にMariaDBとPHPを使用してOpenLiteSpeedサーバーをインストールおよび構成する方法

OpenLiteSpeedは、LiteSpeed Technologiesによって開発されたLiteSpeedサーバーの軽量でオープンソースのバージョンです。これは、他のサーバーとは異なり、管理が容易なWebGUIベースの管理パネルを備えています。

このチュートリアルでは、Ubuntu 20.04にPHP 7.4とMariaDBサーバーと共にOpenLiteSpeedサーバーをインストールする方法を学びます。

前提条件

  • Ubuntu 20.04ベースのWebサーバー。
  • sudo権限を持つ非rootユーザーアカウント。

システムを更新します。

$ sudo apt update
$ sudo apt upgrade

ステップ1 - ファイアウォールの構成

チュートリアルを始める前に、通常デフォルトで有効になっているUncomplicated Firewall(UFW)を構成する必要があります。まず、ファイアウォールの状態を確認しましょう。

SSH、HTTP、HTTPS、およびポート7080、8088をファイアウォールで有効にする必要があります。

$ sudo ufw allow OpenSSH
$ sudo ufw allow http
$ sudo ufw allow https
$ sudo ufw allow 7080/tcp
$ sudo ufw allow 8088/tcp

ファイアウォールの状態を確認します。

$ sudo ufw status
Status: active

To                         Action      From
--                         ------      ----
OpenSSH                    ALLOW       Anywhere                  
80/tcp                     ALLOW       Anywhere                  
443/tcp                    ALLOW       Anywhere                  
7080/tcp                   ALLOW       Anywhere                  
8088/tcp                   ALLOW       Anywhere                  
OpenSSH (v6)               ALLOW       Anywhere (v6)             
80/tcp (v6)                ALLOW       Anywhere (v6)             
443/tcp (v6)               ALLOW       Anywhere (v6)             
7080/tcp (v6)              ALLOW       Anywhere (v6)             
8088/tcp (v6)              ALLOW       Anywhere (v6)     

動作していない場合は、ファイアウォールを起動します。

$ sudo ufw enable

ステップ2 - OpenLiteSpeedのインストール

インストールできるOpenLiteSpeedのバージョンはいくつかあります。推奨されるバージョンは、このチュートリアル執筆時点で1.6.xまたは1.7.xシリーズのものです。

このチュートリアルでは、1.6.xバージョンのみを維持するOpenLiteSpeedの公式リポジトリを使用します。

OpenLiteSpeedリポジトリキーを追加します。

$ wget -qO - https://rpms.litespeedtech.com/debian/lst_repo.gpg | sudo apt-key add -

リポジトリを追加します。

$ echo "deb http://rpms.litespeedtech.com/debian/ focal main" | sudo tee /etc/apt/sources.list.d/openlitespeed.list

リポジトリを更新します。

$ sudo apt update

OpenLiteSpeedをインストールします。

$ sudo apt install openlitespeed

サーバーの状態を確認します。

$ sudo /usr/local/lsws/bin/lswsctrl status
litespeed is running with PID 21825.

動作していない場合は、次のコマンドで起動できます。

$ sudo /usr/local/lsws/bin/lswsctrl start

http://:8088を開いてWebサーバーにアクセスします。次のページが表示されるはずです。

OpenLiteSpeedのデフォルトページ

ステップ3 - PHPのインストール

OpenLiteSpeedサーバーには、事前に有効化されたPHP 7.3が付属しています。しかし、PHP 7.4を使用したいので、独自のコピーをインストールします。

追加のパッケージと共にPHP 7.4をインストールします。

$ sudo apt install lsphp74 lsphp74-common lsphp74-mysql lsphp74-curl

PHPインストールを確認します。

$ /usr/local/lsws/lsphp74/bin/php7.4 -v
PHP 7.4.5 (cli) (built: May  7 2020 23:08:38) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.5, Copyright (c), by Zend Technologies

有効なPHPモジュールを確認できます。

$ /usr/local/lsws/lsphp74/bin/php7.4 --modules

後でOpenLiteSpeedと連携するようにPHPを構成します。

ステップ4 - MariaDBのインストール

MariaDBサーバーをインストールします。

$ sudo apt install mariadb-server

MariaDBサービスを開始し、有効にします。

$ sudo systemctl start mariadb
$ sudo systemctl enable mariadb

MariaDBインストールを保護します。このスクリプトは、rootパスワードを設定し、匿名ユーザーを削除し、リモートrootログインを禁止し、テストテーブルを削除します。強力なパスワードを選択し、以下の質問に答えてください。

$ sudo mysql_secure_installation
[sudo] password for username: 

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none): 
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB 
root user without the proper authorisation.

Set root password? [Y/n] y
New password: 
Re-enter new password: 
Password updated successfully!
Reloading privilege tables..
 ... Success!

By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] y
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] y
 ... Success!

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

これが完了したら、次のコマンドを使用してMySQLシェルにログインできます。

$ sudo mysql -u root -p

アクセス権を持つテストデータベースとユーザーを作成します。testdbtestuserを設定に適した名前に置き換えます。passwordを強力なパスワードに置き換えます。

CREATE DATABASE testdb;
CREATE USER 'testuser' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON testdb.* TO 'testuser';
FLUSH PRIVILEGES;

MySQLシェルを終了します。

exit

ステップ5 - OpenLiteSpeedの構成

管理パネルの構成

管理者パネルの資格情報を設定します。

$ sudo /usr/local/lsws/admin/misc/admpass.sh
Please specify the user name of administrator.
This is the user name required to login the administration Web interface.

User name [admin]: 

Please specify the administrator's password.
This is the password required to login the administration Web interface.

Password: 
Retype password: 
Administrator's username/password is updated successfully!

ログイン情報を忘れた場合は、このコマンドも使用できます。

管理パネルにアクセスするには、http://:7080を開きます。

最初のログイン時に、ブラウザが接続がプライベートでないという警告を表示します。詳細をクリックし、「リスクを受け入れて続行」をクリックします(Firefoxの場合)または「(unsafe)に進む」をクリックします(Chromiumベースのブラウザの場合)。再度警告は表示されません。

次の画面が表示されます。

OpenLiteSpeedログインページ

HTTPポートを80に戻す

デフォルトのHTTPポートを80に変更しましょう。作成した資格情報でhttp://:7080の管理パネルにログインします。

次の画面が表示されます。

OpenLiteSpeed管理ホーム

左側のリスナーセクションに移動します。ポート8080のデフォルトリスナーが表示されます。

OpenLiteSpeedリスナー

詳細設定を表示するには、表示ボタンをクリックします。次のページのリスナーのデフォルト > 一般ページで、編集アイコンをクリックし、ポートを8080から80に変更します。

OpenLiteSpeedデフォルトリスナー

OpenLiteSpeedリスナー編集

保存をクリックし、グレースフル再起動ボタンをクリックしてサーバーを再起動します。

ステップ6 - PHPの構成

このステップでは、サーバーにPHP 7.4のコピーを関連付ける必要があります。

左側のサーバー構成セクションをクリックし、次に外部アプリタブをクリックします。PHP 7.3の既存のLiteSpeedアプリが表示されます。PHP 7.4の独自のLiteSpeedアプリを作成します。後で簡単に切り替えることができます。

外部アプリケーション

新しいアプリを作成するには、追加ボタンをクリックします。タイプとしてLiteSpeed SAPIアプリを選択し、次へをクリックします。

外部アプリ構成

次に、以下の構成を追加します。他のフィールドは空白のままにします。

Name: lsphp74
Address: uds://tmp/lshttpd/lsphp.sock
Max Connections: 35
Environment: PHP_LSAPI_MAX_REQUESTS=500
             PHP_LSAPI_CHILDREN=35
             LSAPI_AVOID_FORK=200M
Initial Request Timeout (secs): 60
Retry Timeout : 0
Persistent Connection: Yes
Response Buffering: no
Start By Server: Yes(Through CGI Daemon)
Command: lsphp74/bin/lsphp
Back Log: 100
Instances: 1
Priority: 0
Memory Soft Limit (bytes): 2047M
Memory Hard Limit (bytes): 2047M
Process Soft Limit: 1400
Process Hard Limit: 1500

完了したら保存をクリックします。

LiteSpeed SAPIアプリ

独自のPHP 7.4ベースのアプリを作成したので、サーバーに使用を開始するように指示する必要があります。

スクリプトハンドラータブに移動し、lsphpハンドラーを編集します。ドロップダウンメニューからハンドル名をlsphp74に切り替えます。

スクリプトハンドラー定義

保存をクリックし、グレースフル再起動ボタンをクリックしてサーバーを再起動します。

PHPが正しく切り替わったかどうかをテストするには、ブラウザでhttp:///phpinfo.phpにアクセスします。

PHP情報

ステップ7 - バーチャルホストの設定

まず、バーチャルホスト用のディレクトリを作成する必要があります。

$ sudo mkdir /usr/local/lsws/example.com/{html,logs} -p

htmlディレクトリには公開ファイルが格納され、logsディレクトリにはサーバーログが格納されます。

次に、管理コンソールを開き、左側のバーチャルホストセクションにアクセスし、追加ボタンをクリックします。

バーチャルホストの概要

指定された値を入力します。

Virtual Host Name: example.com
Virtual Host Root: $SERVER_ROOT/example.com/
Config File: $SERVER_ROOT/conf/vhosts/$VH_NAME/vhconf.conf
Follow Symbolic Link: Yes
Enable Scripts/ExtApps: Yes
Restrained: Yes
External App Set UID Mode: Server UID

バーチャルホスト設定

完了したら保存ボタンをクリックします。現在、構成ファイルが存在しないため、次のエラーが表示されます。リンクをクリックして構成ファイルを作成します。

バーチャルホスト構成

バーチャルホストの作成が完了したら、バーチャルホスト -> バーチャルホストを選択(example.com) -> 一般に移動し、以下のように構成を変更します。

Document Root: $VH_ROOT/html/
Domain Name: example.com
Enable Compression: Yes

バーチャルホスト一般セクション

完了したら保存ボタンをクリックします。次に、インデックスファイルを設定する必要があります。一般セクションの下にあるインデックスファイルに対して編集ボタンをクリックします。次のオプションを設定します。

Use Server Index Files: No
Index files: index.php, index.html, index.htm
Auto Index: No

OpenliteSpeedインデックスファイル

完了したら保存をクリックします。次に、ログファイルを選択する必要があります。ログセクションに移動し、バーチャルホストログに対して編集ボタンをクリックし、次の値を入力します。

Use Server’s Log: Yes
File Name: $VH_ROOT/logs/error.log
Log Level: ERROR
Rolling Size (bytes): 10M

バーチャルホストログ

本番/開発マシンの場合は、ログレベルDEBUGに設定できます。

完了したら保存をクリックし、アクセスログセクションでプラス記号をクリックして新しいエントリを追加します。次の値を入力します。

Log Control: Own Log File
File Name: $VH_ROOT/logs/access.log
Piped Logger: Not Set
Log Format: Not Set
Log Headers: Not Set
Rolling Size (bytes): 10M
Keep Days: 30
Bytes log: Not Set
Compress Archive: Yes

OpenliteSpeedアクセスログ

完了したら保存をクリックします。次に、セキュリティセクションのアクセス制御を構成する必要があります。次の値を設定します。

Allowed List: *
Denied List: Not set

OpenliteSpeedアクセス制御

完了したら保存をクリックします。次に、スクリプトハンドラー定義を設定する必要があります。次の値を設定します。

Suffixes: php
Handler Type: LiteSpeed SAPI
Handler Name: [Server Level]: lsphp74

スクリプトハンドラー定義

次に、リライトセクションのリライト制御を設定する必要があります。次の値を設定します。

リライト制御

最後に、リスナーを設定する必要があります。リスナーセクションに移動し、デフォルトリスナーに対して表示ボタンをクリックします。次に、バーチャルホストマッピングに対して追加ボタンをクリックして新しいマッピングを追加し、次の値を設定します。

完了したら保存をクリックします。次に、グレースフル再起動ボタンをクリックして、上記のすべての変更を適用し、サーバーを再起動します。

ステップ8 - SSLの設定

OpenLiteSpeedでSSLを設定するには、2つの証明書を設定する必要があります。全体のサーバー用の自己署名証明書と、Let’s Encryptのサイト固有のサーバーです。

まず、自己署名証明書を作成しましょう。

$ openssl req -x509 -days 365 -newkey rsa:4096 -keyout key.pem -out cert.pem -nodes
Generating a RSA private key
..++++
......................++++
writing new private key to 'key.pem'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:
State or Province Name (full name) [Some-State]:
Locality Name (eg, city) []:
Organization Name (eg, company) [Internet Widgits Pty Ltd]:
Organizational Unit Name (eg, section) []:
Common Name (e.g. server FQDN or YOUR name) []:
Email Address []:

すべてのフィールドを空白のままにしてEnterを押すことができます。

証明書は現在/home/userディレクトリに保存されています。この情報は後で必要になります。

Let’s Encryptを使用するには、Certbotツールをインストールする必要があります。

$ sudo apt install certbot

SSL証明書を取得します。

$ sudo certbot certonly --webroot -w /usr/local/lsws/example.com/html/ -d example.com

インタラクティブプロンプトに従います。

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator webroot, Installer None
Enter email address (used for urgent renewal and security notices) (Enter 'c' to
cancel): [email protected]
Starting new HTTPS connection (1): acme-v01.api.letsencrypt.org

-------------------------------------------------------------------------------
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must agree
in order to register with the ACME server at
https://acme-v02.api.letsencrypt.org/directory
-------------------------------------------------------------------------------
(A)gree/(C)ancel: A

-------------------------------------------------------------------------------
Would you be willing to share your email address with the Electronic Frontier
Foundation, a founding partner of the Let's Encrypt project and the non-profit
organization that develops Certbot? We'd like to send you email about our work
encrypting the web, EFF news, campaigns, and ways to support digital freedom.
-------------------------------------------------------------------------------
(Y)es/(N)o: N
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for example.com
Using the webroot path /usr/local/lsws/example.com/html for all unmatched domains.
Waiting for verification...
Cleaning up challenges

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/example/fullchain.pem. Your key file has 
   been saved at:
   /etc/letsencrypt/live/linode.nspeaks.com/privkey.pem Your cert will
   expire on 2020-09-04. To obtain a new or tweaked version of this
   certificate in the future, simply run certbot again. To
   non-interactively renew *all* of your certificates, run "certbot
   renew"
 - Your account credentials have been saved in your Certbot
   configuration directory at /etc/letsencrypt. You should make a
   secure backup of this folder now. This configuration directory will
   also contain certificates and private keys obtained by Certbot so
   making regular backups of this folder is ideal.
 - If you like Certbot, please consider supporting our work by:

   Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
   Donating to EFF:                    https://eff.org/donate-le

次に、管理コンソールを開き、リスナー >> 新しいリスナーを追加に移動し、次の値を追加します。

Listener Name: SSL
IP Address: ANY
Port: 443
Secure: Yes

SSLリスナー

完了したら保存をクリックします。次に、SSLリスナーのバーチャルホストマッピングセクションに移動し、SSLをクリックして追加ボタンをクリックし、次の値を入力します。

Virtual Host: example.com
Domains: example.com

完了したら保存をクリックします。

次に、リスナー >> SSLリスナー >> SSLタブ >> SSLプライベートキーと証明書(編集ボタン)に移動し、以前に作成した自己署名証明書の次の値を入力します。

Private Key File: /home/user/key.pem
Certificate File: /home/user/cert.pem
Chained Certificate: Yes

自己署名SSLキーと証明書

次に、バーチャルホスト >> example.com >> SSLタブ >> SSLプライベートキーと証明書(編集ボタン)に移動し、Let’s Encrypt証明書の次の値を入力します。

Private Key File: /etc/letsencrypt/live/example.com/privkey.pem
Certificate File: /etc/letsencrypt/live/example.com/fullchain.pem
Chained Certificate: Yes

Let's Encrypt SSLキーと証明書

完了したら保存をクリックします。

グレースフル再起動ボタンをクリックしてサーバーを再起動します。

ステップ9 - サイトのテスト

htmlディレクトリにテストファイルを作成します。

$ sudo nano /usr/local/lsws/example.com/html/index.php

Nanoエディタに次のコードを貼り付けます。



    

OpenLiteSpeedサーバーインストールテスト

こんにちは、

'; // MySQL接続のためのPHP変数を定義します。 $servername = "localhost"; $username = "testuser"; $password = "password"; // MySQL接続を作成します。 $conn = mysqli_connect($servername, $username, $password); // 接続が失敗したか成功したかを報告します。 if (!$conn) { exit('

接続に失敗しました。

' . mysqli_connect_error()); } echo '

正常に接続されました。

'; ?>

ブラウザでhttps://example.comにアクセスすると、次のページが表示されるはずです。

OpenLiteSpeedサイトテスト

このチュートリアルは以上です。質問がある場合は、下のコメントでお知らせください。

Share: X/Twitter LinkedIn

新しい投稿を受信箱で受け取る

スパムはありません。いつでも購読を解除できます。