OpenLiteSpeedは、LiteSpeedTechnologiesによって開発されたLiteSpeedサーバーの軽量でオープンソースバージョンです。 WebGUIベースの管理パネルが付属しているため、他のサーバーとは異なり、管理が容易です。
このチュートリアルでは、PHP7.4およびMariaDBサーバーとともにUbuntu20.04にOpenLiteSpeedサーバーをインストールする方法を学習します。
-
Ubuntu20.04ベースのWebサーバー。
-
sudo権限を持つroot以外のユーザーアカウント。
システムを更新します。
$ sudo apt update
$ sudo apt upgrade
チュートリアルを開始する前に、 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
インストールできる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://<YOURSERVERIP>:8088
を開きます Webサーバーにアクセスします。次のページが表示されます。
OpenLiteSpeedサーバーには、事前に有効になっているPHP7.3が付属しています。ただし、PHP 7.4を使用したいので、独自のコピーをインストールします。
PHP7.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を構成します。
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
テストデータベースとアクセス許可を持つユーザーを作成します。 testdb
を置き換えます およびtestuser
セットアップに適切な名前を付けます。 password
を置き換えます 強力なパスワードを使用します。
CREATE DATABASE testdb;
CREATE USER 'testuser' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON testdb.* TO 'testuser';
FLUSH PRIVILEGES;
MySQLシェルを終了します。
exit
管理者パネルの資格情報を設定します。
$ 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]: <username>
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://<YOURSERVERIP>:7080
を開きます。 。
最初のログイン時に、ブラウザは接続がプライベートではないことを示す警告を表示します。 [詳細設定]をクリックし、[リスクを受け入れて続行](Firefoxの場合)または[<YOURSERVERIP>(unsafe)
に進む]をクリックします "(Chromiumベースのブラウザの場合)警告は二度と表示されません。
次の画面が表示されます。
HTTPポートを80に戻します
デフォルトのHTTPポートを80に変更しましょう。http://<YOURSERVERIP>:7080
で管理パネルにログインします。 作成したばかりのクレデンシャルを使用します。
次の画面が表示されます。
リスナーにアクセス 左からセクション。ポート8080のデフォルトのリスナーが表示されます。
[表示]ボタンをクリックして、構成の詳細を表示します。次のページのリスナーのデフォルト>一般 ページで、編集アイコンをクリックし、ポートを8080から80に変更します。
[保存]をクリックし、[グレースフル再起動]ボタンをクリックしてサーバーを再起動します。
このステップでは、PHP7.4のコピーをサーバーに関連付ける必要があります。
サーバー構成をクリックします 左側のセクション、次にタブ外部アプリ 。 PHP7.3用の既存のLiteSpeedアプリが表示されます。 PHP7.4用の独自のLiteSpeedアプリを作成します。必要に応じて、後で簡単に切り替えることができます。
[追加]ボタンをクリックして、新しいアプリを作成します。タイプとして、LiteSpeedSAPIアプリを選択します [次へ]をクリックします。
次に、以下の構成を追加します。他のすべてのフィールドは空白のままにします。
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
終了したら[保存]をクリックします。
独自のPHP7.4ベースのアプリを作成したので、サーバーに使用を開始するように指示する必要があります。
スクリプトハンドラーに移動します タブをクリックして、lsphpハンドラーを編集します。ハンドル名をlsphp74
に切り替えます ドロップダウンメニューから。
[保存]をクリックし、[正常な再起動]をクリックしてサーバーを再起動します ボタン。
PHPが正しく切り替えられたかどうかをテストするには、http://<YOURSERVERIP>/phpinfo.php
にアクセスしてください。 ブラウザで。
まず、仮想ホストのディレクトリを作成する必要があります。
$ 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
完了したら、[保存]をクリックします。次に、ログファイルを選択する必要があります。 ログに移動します セクションをクリックし、仮想ホストログに対して[編集]をクリックします 次の値を入力します。
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
完了したら、[保存]をクリックします。次に、アクセス制御を構成する必要があります セキュリティの下 セクション。次の値を設定します。
Allowed List: *
Denied List: Not set
完了したら、[保存]をクリックします。次に、スクリプトハンドラー定義を設定する必要があります 。次の値を設定します。
Suffixes: php
Handler Type: LiteSpeed SAPI
Handler Name: [Server Level]: lsphp74
次に、書き換え制御を設定する必要があります 書き換えの下 セクション。次の値を設定します。
そして最後に、リスナーを設定する必要があります。 リスナーに移動します セクションをクリックし、デフォルトリスナーに対して[表示]ボタンをクリックします 。次に、仮想ホストマッピングに対して[追加]ボタンをクリックします 新しいマッピングを追加し、次の値を設定します。
完了したら、[保存]をクリックします。次に、グレースフルリスタートをクリックします ボタンをクリックして、上記のすべての変更を適用し、サーバーを再起動します。
OpenLiteSpeedでSSLを設定するには、2つの証明書を設定する必要があります。サーバー全体とLet'sEncryptサイト固有のサーバーの自己署名証明書。
最初に自己署名証明書を作成しましょう。
$ 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リスナーの下のセクションで、[追加]ボタンをクリックし、次の値を入力します。
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
次に、仮想ホスト>> example.com>>SSLタブ>>SSL秘密鍵と証明書に移動します ([編集]ボタン)そして、次の値にLet'sEncryptCertificateを入力します。
Private Key File: /etc/letsencrypt/live/example.com/privkey.pem
Certificate File: /etc/letsencrypt/live/example.com/fullchain.pem
Chained Certificate: Yes
終了したら[保存]をクリックします。
Gracefulrestartボタンをクリックしてサーバーを再起動します。
html
にテストファイルを作成します ディレクトリ。
$ sudo nano /usr/local/lsws/example.com/html/index.php
次のコードをNanoエディターに貼り付けます。
<html>
<head>
<h2>OpenLiteSpeed Server Install Test</h2>
</head>
<body>
<?php echo '<p>Hello,</p>';
// Define PHP variables for the MySQL connection.
$servername = "localhost";
$username = "testuser";
$password = "password";
// Create a MySQL connection.
$conn = mysqli_connect($servername, $username, $password);
// Report if the connection fails or is successful.
if (!$conn) {
exit('<p>Your connection has failed.<p>' . mysqli_connect_error());
}
echo '<p>You have connected successfully.</p>';
?>
</body>
</html>
https://example.com
でサイトにアクセスします ブラウザで次のページが表示されます。
このチュートリアルは以上です。ご不明な点がございましたら、下のコメント欄にご記入ください。