GNU/Linux >> Belajar Linux >  >> Fedora

Cara Menginstal dan Mengkonfigurasi Server OpenLiteSpeed ​​di Fedora 31 bersama dengan MariaDB

OpenLiteSpeed ​​adalah versi ringan dan open-source dari LiteSpeed ​​Server yang dikembangkan oleh LiteSpeed ​​Technologies. Ini mendukung aturan Apache Rewrite, HTTP/2 dan HTTP/3 bersama dengan protokol TLS v1.3 dan QUIC. Muncul dengan panel Administrasi berbasis WebGUI yang membuatnya berbeda dari server lain dan lebih mudah untuk dikelola.

Dalam tutorial ini, kita akan mempelajari cara menginstal OpenLiteSpeed ​​Server di Fedora 31 bersama dengan PHP 7.4 dan server MariaDB.

Prasyarat

  • Server web berbasis Fedora 31.

  • Akun pengguna non-root dengan hak istimewa sudo.

  • Perbarui sistem Anda.

    $ sudo dnf update
    
  • paket libnsl. Paket ini berisi antarmuka klien publik untuk layanan NIS. Untuk menginstalnya, jalankan perintah berikut.

    $ sudo dnf install libnsl -y
    

Langkah 1 - Konfigurasi Firewall

Sebelum kita mulai dengan tutorial, kita perlu mengkonfigurasi Fedora Firewall yang biasanya diaktifkan secara default. Mari kita periksa status firewallnya terlebih dahulu.

$ sudo systemctl status firewalld

Jika tidak berfungsi, maka mulai firewall.

$ sudo systemctl start firewalld

Selanjutnya, kita perlu mengaktifkan SSH, HTTP, HTTPS dan port 7080, 8088 untuk firewall.

$ sudo firewall-cmd --permanent --add-service=ssh
$ sudo firewall-cmd --permanent --add-service=http
$ sudo firewall-cmd --permanent --add-service=https
$ sudo firewall-cmd --permanent --add-port=7080/tcp
$ sudo firewall-cmd --permanent --add-port=8088/tcp

Setelah selesai, Anda dapat melihat daftar pengecualian yang akan diterapkan.

$ sudo firewall-cmd --permanent --list-all

Saat Anda puas dengan perubahannya, muat ulang Firewall untuk membuat perubahan itu hidup.

$ sudo firewall-cmd --reload

Aktifkan firewall sehingga akan dimuat ulang pada setiap bootup.

$ sudo systemctl enable firewalld

Langkah 2 - Instal OpenLiteSpeed

Jalankan perintah berikut untuk mengunduh paket biner OpenLiteSpeed ​​​​dari situs web. Saat menulis tutorial ini, versi terbaru yang tersedia adalah 1.6.4. Periksa versi terbaru dari halaman unduhan dan ubah URL sesuai kebutuhan.

$ wget https://openlitespeed.org/packages/openlitespeed-1.6.4.tgz

Ekstrak arsip.

$ tar -zxvf openlitespeed-1.6.4.tgz

Beralih ke openlitespeed direktori dan jalankan skrip instalasi.

$ cd openlitespeed
$ sudo ./install.sh

Mulai server web.

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

Periksa status server.

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

Buka http://:8088 untuk mengakses server web Anda. Anda akan melihat halaman berikut.

Langkah 3 - Instal PHP

Server OpenLiteSpeed ​​dikirimkan dengan PHP 5.6 yang telah diaktifkan sebelumnya. Tapi kami ingin menggunakan PHP 7.4 jadi kami akan menginstal salinan kami.

Instal repositori REMI yang merupakan repositori Fedora resmi untuk menginstal paket PHP.

$ sudo dnf -y install https://rpms.remirepo.net/fedora/remi-release-31.rpm

Aktifkan remi dan remi-php74 repositori dan nonaktifkan remi-modular gudang. Ini memungkinkan repositori yang diperlukan untuk menginstal paket PHP 7.4.

$ sudo dnf config-manager --set-enabled remi
$ sudo dnf config-manager --set-enabled remi-php74
$ sudo dnf config-manager --set-disabled remi-modular

Instal PHP 7.4 bersama dengan beberapa paket tambahan.

$ sudo dnf install php php-mysqlnd php-gd php-mcrypt php-bcmath php-litespeed

Verifikasi instalasi PHP Anda.

$ php -v
PHP 7.4.0 (cli) (built: Nov 26 2019 20:13:36) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
   with Zend OPcache v7.4.0, Copyright (c), by Zend Technologies

Anda dapat memeriksa modul PHP yang diaktifkan.

$ php --modules

Kami akan mengonfigurasi PHP untuk bekerja dengan OpenLiteSpeed ​​nanti.

Langkah 4 - Instal MariaDB

Instal server MariaDB.

$ sudo dnf install mariadb-server

Mulai dan aktifkan layanan MariaDB.

$ sudo systemctl start mariadb
$ sudo systemctl enable mariadb

Amankan instalasi MariaDB Anda. Skrip ini akan mengatur kata sandi root Anda, menghapus pengguna anonim, melarang login root jarak jauh dan menjatuhkan tabel uji. Pilih sandi yang kuat dan jawab pertanyaan seperti yang dijelaskan di bawah ini.

$ 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!

Setelah ini selesai, Anda dapat masuk ke shell MySQL menggunakan perintah berikut.

$ sudo mysql -u root -p

Buat database pengujian dan pengguna dengan izin akses. Ganti testdb dan testuser dengan nama yang sesuai untuk pengaturan Anda. Ganti password dengan kata sandi yang kuat.

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

Keluar dari shell MySQL.

exit

Langkah 5 - Konfigurasi OpenLiteSpeed

Konfigurasi Panel Admin

Setel kredensial panel Administrator.

$ sudo /usr/local/lsws/admin/misc/admpass.sh

Anda dapat mengatur nama pengguna dan kata sandi menggunakan perintah ini. Anda juga dapat menggunakan perintah ini jika Anda lupa detail login Anda.

Untuk mengakses panel administrasi, buka http://:7080 .

Ganti port HTTP kembali ke 80

Mari kita ubah port HTTP default menjadi 80. Masuk ke panel administrasi Anda di http://:7080 dengan kredensial yang baru saja Anda buat.

Anda akan disambut oleh layar berikut.

Kunjungi bagian Pendengar dari kiri. Anda akan melihat pendengar default dengan port 8080.

Klik Lihat tombol untuk melihat detail konfigurasi. Pada halaman berikutnya di bawah Default Pendengar> Halaman Umum , klik ikon Edit dan ubah port dari 8088 menjadi 80.

Klik Simpan, lalu mulai ulang server dengan mengeklik Mulai ulang dengan anggun tombol.

Langkah 6 - Konfigurasi PHP

Pada langkah ini, kita perlu mengaitkan salinan PHP 7.4 kita dengan server.

Klik Konfigurasi Server bagian di sebelah kiri lalu pada tab Aplikasi Eksternal . Anda akan melihat Aplikasi LiteSpeed ​​​​yang ada untuk PHP 5.6. Kami akan membuat Aplikasi LiteSpeed ​​kami sendiri untuk PHP 7.4. Anda dapat dengan mudah beralih di antara mereka nanti jika Anda mau.

Klik tombol Tambah untuk membuat aplikasi baru. Untuk jenisnya, pilih LiteSpeed ​​SAPI App dan klik Berikutnya.

Selanjutnya, tambahkan konfigurasi di bawah ini. Kosongkan semua bidang lainnya.

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: /usr/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

Klik Simpan setelah selesai.

Sekarang kita telah membuat aplikasi berbasis PHP 7.4 kita sendiri, kita perlu memberi tahu server untuk mulai menggunakannya.

Buka Penangan Skrip tab dan edit penangan lsphp . Ganti nama Handle ke lsphp74 dari menu tarik-turun.

Klik Simpan, lalu mulai ulang server dengan mengeklik Mulai ulang dengan anggun tombol.

Untuk menguji apakah PHP Anda telah dialihkan dengan benar, kunjungi http:///phpinfo.php di browser Anda.

Langkah 7 - Siapkan Virtual Host

Pertama, kita perlu membuat direktori untuk virtual host kita.

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

html direktori akan menyimpan file publik dan logs direktori akan berisi log server.

Selanjutnya, buka konsol Admin dan akses Virtual Host bagian dari kiri dan klik tombol Tambah.

Isi nilai sesuai yang ditentukan

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

Klik tombol Simpan jika sudah selesai. Anda akan mendapatkan kesalahan berikut karena file konfigurasi tidak ada sampai sekarang. Klik tautan untuk membuat file konfigurasi.

Klik tombol Simpan lagi untuk menyelesaikan pembuatan Virtual Host.

Setelah virtual host dibuat, buka Virtual Hosts -> Pilih Virtual Host(example.com) -> General dan ubah konfigurasi seperti yang diberikan.

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

Klik tombol Simpan jika sudah selesai. Selanjutnya, kita perlu mengatur file indeks. Klik tombol edit terhadap file Indeks di bawah Bagian Umum. Setel opsi berikut.

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

Klik Simpan setelah selesai. Selanjutnya, kita perlu memilih file Log. Buka bagian Log dan klik Edit terhadap Log Host Virtual dan isi nilai berikut.

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

Anda dapat memilih Level Log sebagai DEBUG jika Anda menggunakan mesin produksi/pengembangan.

Klik Simpan, lalu buka Log Akses bagian. Isi nilai berikut.

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

Klik Simpan setelah selesai. Selanjutnya, kita perlu mengonfigurasi Access Control di bawah Keamanan bagian. Tetapkan nilai berikut.

Allowed List: *
Denied List: Not set

Klik Simpan setelah selesai. Selanjutnya, kita perlu mengatur handler skrip. Tetapkan nilai berikut.

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

Selanjutnya, kita perlu mengatur Rewrite Control di bawah bagian Tulis Ulang. Tetapkan nilai berikut.

Enable Rewrite: Yes
Auto Load from .htaccess: Yes
Log Level: Not Set

Dan terakhir, kita perlu mengatur Listeners. Buka bagian Pendengar dan klik tombol Lihat melawan Pendengar Default . Kemudian, klik tombol Tambah pada Pemetaan Host Virtual untuk menambahkan pemetaan baru dan menetapkan nilai berikut.

Virtual Host: example.com
Domains: example.com

Klik Simpan setelah selesai. Sekarang, klik tombol Graceful restart untuk menerapkan semua perubahan di atas dan restart server.

Langkah 8 - Siapkan SSL

Untuk menggunakan Let's Encrypt, kita perlu menginstal alat Certbot.

$ sudo dnf install certbot

Dapatkan sertifikat SSL.

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

Ikuti perintah Interaktif.

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-03-07. 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

Sekarang buka konsol Admin dan buka Listeners>> Add New Listener dan tambahkan nilai berikut.

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

Klik Simpan setelah selesai. Selanjutnya, buka Pemetaan Host Virtual bagian di bawah SSL Listener , klik tombol Tambah dan isi nilai berikut.

Virtual Host: example.com
Domains: example.com

Klik Simpan setelah selesai.

Selanjutnya buka Listeners>> SSL Listener>> Tab SSL>>SSL Private Key &Certificate (tombol Edit) dan isi nilai berikut

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

Klik Simpan setelah selesai. Restart server dengan mengklik tombol Graceful restart.

Langkah 9 - Situs Uji

Buat file Tes di html . Anda direktori.

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

Rekatkan kode berikut di editor 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>

Kunjungi situs Anda di https://example.com di browser dan Anda akan melihat halaman berikut.

Itu saja untuk tutorial ini. Jika Anda memiliki pertanyaan, tulis di komentar di bawah.


Fedora
  1. Cara Menginstal dan Mengkonfigurasi Mysql Server 8 di Fedora 34/35

  2. Cara menginstal dan mengkonfigurasi Redis 6 di Fedora 34

  3. Cara Menginstal dan Mengonfigurasi Postgres 14 di Fedora 34

  1. Cara Menginstal dan Mengkonfigurasi OpenLiteSpeed ​​dengan PHP 7.4 di CentOS 8

  2. Cara Menginstal dan Mengonfigurasi Ansible di Fedora 35

  3. Cara menginstal dan Konfigurasi Mariadb di Fedora 35

  1. Cara Menginstal dan Mengkonfigurasi OpenLiteSpeed ​​dengan PHP 7 di CentOS 7

  2. Cara Menginstal dan Mengkonfigurasi OpenLiteSpeed ​​Server di Ubuntu 18.04 bersama dengan MariaDB

  3. Cara Menginstal Nginx dengan PHP dan MariaDB (LEMP Stack) di Fedora 31