安裝 Apache + MariaDB + PHP(Rocky Linux 9 及 Ubuntu Server 24.04)

在私有雲與檔案同步服務日益受到重視的今天,Nextcloud 成為眾多企業與機關首選的自建雲端平台方案,為了確保其穩定性與相容性,最常見的部署架構便是以 Apache 作為網頁伺服器、MariaDB 作為資料庫系統、PHP 作為應用執行環境的 LAMP 組合。

本文件將分別介紹如何在 Rocky Linux 9Ubuntu 24.04 上安裝與設定 Apache、MariaDB 與 PHP,為後續部署 Nextcloud 奠定穩固基礎。無論是初次接觸或欲重新部署的管理者,皆可依據本文件逐步完成基本環境建置。

image.png

安裝及設定 Apache 伺服器

安裝指令如下所示:

$ sudo yum install httpd mod_ssl

一次連同 SSL 套件都安裝,結果如下:

Last metadata expiration check: 2:55:53 ago on Wed May 14 12:14:46 2025.
Dependencies resolved.
================================================================================================================================
 Package                           Architecture           Version                               Repository                 Size
================================================================================================================================
Installing:
 httpd                             x86_64                 2.4.62-1.el9_5.2                      appstream                  45 k
 mod_ssl                           x86_64                 1:2.4.62-1.el9_5.2                    appstream                 109 k
Installing dependencies:
 apr                               x86_64                 1.7.0-12.el9_3                        appstream                 122 k
 apr-util                          x86_64                 1.6.1-23.el9                          appstream                  94 k
 apr-util-bdb                      x86_64                 1.6.1-23.el9                          appstream                  12 k
 httpd-core                        x86_64                 2.4.62-1.el9_5.2                      appstream                 1.4 M
 httpd-filesystem                  noarch                 2.4.62-1.el9_5.2                      appstream                  12 k
 httpd-tools                       x86_64                 2.4.62-1.el9_5.2                      appstream                  79 k
 mailcap                           noarch                 2.1.49-5.el9                          baseos                     32 k
 rocky-logos-httpd                 noarch                 90.15-2.el9                           appstream                  24 k
 sscg                              x86_64                 3.0.0-7.el9                           appstream                  45 k
Installing weak dependencies:
 apr-util-openssl                  x86_64                 1.6.1-23.el9                          appstream                  14 k
 mod_http2                         x86_64                 2.0.26-2.el9_4.1                      appstream                 163 k
 mod_lua                           x86_64                 2.4.62-1.el9_5.2                      appstream                  59 k

Transaction Summary
================================================================================================================================
Install  14 Packages

Total download size: 2.2 M
Installed size: 6.5 M
Is this ok [y/N]:

請輸入 y 並按下 Enter 鍵進行安裝,安裝完成後,請設定預設開機啟動 Apache 伺服器及手動啟用服務。

$ sudo systemctl restart httpd
[ossii@nextcloud ~]$ sudo systemctl enable httpd
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.

利用 systemctl 指令查看一下相關服務的啟用情況。

$ sudo systemctl status httpd
● httpd.service - The Apache HTTP Server
     Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; preset: disabled)
     Active: active (running) since Wed 2025-05-14 15:12:50 CST; 52s ago
       Docs: man:httpd.service(8)
   Main PID: 1410 (httpd)
     Status: "Total requests: 0; Idle/Busy workers 100/0;Requests/sec: 0; Bytes served/sec:   0 B/sec"
      Tasks: 177 (limit: 11112)
     Memory: 28.7M
        CPU: 92ms
     CGroup: /system.slice/httpd.service
             ├─1410 /usr/sbin/httpd -DFOREGROUND
             ├─1411 /usr/sbin/httpd -DFOREGROUND
             ├─1412 /usr/sbin/httpd -DFOREGROUND
             ├─1413 /usr/sbin/httpd -DFOREGROUND
             └─1414 /usr/sbin/httpd -DFOREGROUND

May 14 15:12:50 nextcloud.ossii.com.tw systemd[1]: Starting The Apache HTTP Server...
May 14 15:12:50 nextcloud.ossii.com.tw systemd[1]: Started The Apache HTTP Server.
May 14 15:12:50 nextcloud.ossii.com.tw httpd[1410]: Server configured, listening on: port 443, port 80
[ossii@nextcloud ~]$

利用瀏覽器測試一下 http 及 https 服務有沒有啟用。

image.png

image.png

這樣子就完成了 apache server (RockyLinux 9) 的初步安裝作業了~

安裝指令如下所示:

$ sudo apt -y install apache2 apache2-utils

接下來會出現一大堆訊息,包含安裝及啟用各式預設的模組功能,如下所示:

Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  apache2-bin apache2-data libapr1t64 libaprutil1-dbd-sqlite3 libaprutil1-ldap libaprutil1t64 liblua5.4-0 ssl-cert
Suggested packages:
  apache2-doc apache2-suexec-pristine | apache2-suexec-custom www-browser
The following NEW packages will be installed:
  apache2 apache2-bin apache2-data apache2-utils libapr1t64 libaprutil1-dbd-sqlite3 libaprutil1-ldap libaprutil1t64
  liblua5.4-0 ssl-cert
0 upgraded, 10 newly installed, 0 to remove and 1 not upgraded.
Need to get 2,084 kB of archives.
After this operation, 8,094 kB of additional disk space will be used.
Do you want to continue? [Y/n]

請輸入 Y 並按下 Enter 鍵進行安裝,安裝完成後,預設就會設定開機啟動 Apache 伺服器及手動啟用服務。

接下來先啟用 Apache 的 SSL 模組,特別先提醒一下,和 RedHat / CentOS 系列的 apahce 管理不大一樣,在 RedHat / CentOS 平台中要啟用特定的模組,只要安裝好對應的模組套件,再重新啟用 httpd 服務即可,但是在 Ubuntu Server 中,除了要安裝對應的模組套件外,要額外使用 a2emod 指令來指用模組,並重新啟用 apache 服務才可啟用,不然會發生明明就裝了模組但是一定沒有啟用對應功能的情況,這部份後續會再介紹其使用方式。

$ sudo a2enmod ssl
Considering dependency mime for ssl:
Module mime already enabled
Considering dependency socache_shmcb for ssl:
Enabling module socache_shmcb.
Enabling module ssl.
See /usr/share/doc/apache2/README.Debian.gz on how to configure SSL and create self-signed certificates.
To activate the new configuration, you need to run:
  systemctl restart apache2

要手動啟用 SSL 的網站:

$ sudo a2ensite default-ssl.conf

然後再手動重啟 Aapche 的服務。

$ sudo systemctl restart apache2

先利用 netstat 指令確認服務是否有啟動(有發現 80 及 443 port 都已運作中)。

$ sudo netstat -tlnp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 127.0.0.54:53           0.0.0.0:*               LISTEN      565/systemd-resolve
tcp        0      0 127.0.0.53:53           0.0.0.0:*               LISTEN      565/systemd-resolve
tcp        0      0 127.0.0.1:6010          0.0.0.0:*               LISTEN      1005/sshd: ossii@pt
tcp6       0      0 ::1:6010                :::*                    LISTEN      1005/sshd: ossii@pt
tcp6       0      0 :::443                  :::*                    LISTEN      1994/apache2
tcp6       0      0 :::22                   :::*                    LISTEN      1/init
tcp6       0      0 :::80                   :::*                    LISTEN      1994/apache2

利用 systemctl 指令查看一下相關服務的啟用情況。

$ sudo systemctl status apache2
● apache2.service - The Apache HTTP Server
     Loaded: loaded (/usr/lib/systemd/system/apache2.service; enabled; preset: enabled)
     Active: active (running) since Wed 2025-05-14 15:18:33 CST; 6min ago
       Docs: https://httpd.apache.org/docs/2.4/
   Main PID: 1669 (apache2)
      Tasks: 55 (limit: 2271)
     Memory: 5.2M (peak: 5.4M)
        CPU: 45ms
     CGroup: /system.slice/apache2.service
             ├─1669 /usr/sbin/apache2 -k start
             ├─1671 /usr/sbin/apache2 -k start
             └─1672 /usr/sbin/apache2 -k start

May 14 15:18:33 ubuntu-nextcloud systemd[1]: Starting apache2.service - The Apache HTTP Server...
May 14 15:18:33 ubuntu-nextcloud apachectl[1668]: AH00558: apache2: Could not reliably determine the server's fully qualified d>
May 14 15:18:33 ubuntu-nextcloud systemd[1]: Started apache2.service - The Apache HTTP Server.
lines 1-16/16 (END)

利用瀏覽器測試一下 http 及 https 服務有沒有啟用。

image.png

image.png

這樣子就完成了 apache server (Ubuntu Server 24.04) 的初步安裝作業了~

安裝 PHP 8.2 版

雖然 PHP 8.2 版已經在 RockyLinux 9 預設的套件庫中,但是建議採用第三方的套件庫,所支援的套件內容比較完整,請先使用以下指令安裝擴充的套件庫,指令如下所示:

$ sudo yum install epel-release
Last metadata expiration check: 0:54:14 ago on Wed May 14 16:16:33 2025.
Dependencies resolved.
================================================================================================================================
 Package                           Architecture                Version                        Repository                   Size
================================================================================================================================
Installing:
 epel-release                      noarch                      9-7.el9                        extras                       19 k

Transaction Summary
================================================================================================================================
Install  1 Package

Total download size: 19 k
Installed size: 26 k
Is this ok [y/N]:

輸入 y 並按下 Enter 鍵繼續下載安裝,安裝完成後再另外安裝第三方套件庫:

$ sudo yum install http://rpms.remirepo.net/enterprise/remi-release-9.rpm
Extra Packages for Enterprise Linux 9 - x86_64                                                  7.0 MB/s |  23 MB     00:03
Extra Packages for Enterprise Linux 9 openh264 (From Cisco) - x86_64                            1.0 kB/s | 2.5 kB     00:02
remi-release-9.rpm                                                                               47 kB/s |  32 kB     00:00
Dependencies resolved.
================================================================================================================================
 Package                        Architecture             Version                           Repository                      Size
================================================================================================================================
Installing:
 remi-release                   noarch                   9.5-2.el9.remi                    @commandline                    32 k

Transaction Summary
================================================================================================================================
Install  1 Package

Total size: 32 k
Installed size: 34 k
Is this ok [y/N]:

輸入 y 並按下 Enter 鍵繼續下載安裝,再更新一次 yum repo 資訊,指令如下:

$ sudo yum update
Last metadata expiration check: 0:00:01 ago on Wed May 14 17:17:25 2025.
Dependencies resolved.
================================================================================================================================
 Package                           Architecture                Version                          Repository                 Size
================================================================================================================================
Upgrading:
 epel-release                      noarch                      9-10.el9                         epel                       19 k

Transaction Summary
================================================================================================================================
Upgrade  1 Package

Total download size: 19 k
Is this ok [y/N]:

輸入 y 並按下 Enter 鍵繼續下載安裝,再次輸入 y 並按下 Enter 鍵完成安裝。

Downloading Packages:
epel-release-9-10.el9.noarch.rpm                                                                111 kB/s |  19 kB     00:00
--------------------------------------------------------------------------------------------------------------------------------
Total                                                                                            22 kB/s |  19 kB     00:00
Extra Packages for Enterprise Linux 9 - x86_64                                                  1.6 MB/s | 1.6 kB     00:00
Importing GPG key 0x3228467C:
 Userid     : "Fedora (epel9) <epel@fedoraproject.org>"
 Fingerprint: FF8A D134 4597 106E CE81 3B91 8A38 72BF 3228 467C
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-9
Is this ok [y/N]:

接下來請查詢 PHP 的 repo 來源版本清單,指令如下:

$ sudo yum module list php

結果如下,會發現有官方的和 Remi 的來源。

Last metadata expiration check: 0:03:12 ago on Wed May 14 17:17:25 2025.
Rocky Linux 9 - AppStream
Name                  Stream                   Profiles                                   Summary
php                   8.1                      common [d], devel, minimal                 PHP scripting language
php                   8.2                      common [d], devel, minimal                 PHP scripting language

Remi's Modular repository for Enterprise Linux 9 - x86_64
Name                  Stream                   Profiles                                   Summary
php                   remi-7.4                 common [d], devel, minimal                 PHP scripting language
php                   remi-8.0                 common [d], devel, minimal                 PHP scripting language
php                   remi-8.1                 common [d], devel, minimal                 PHP scripting language
php                   remi-8.2                 common [d], devel, minimal                 PHP scripting language
php                   remi-8.3                 common [d], devel, minimal                 PHP scripting language
php                   remi-8.4                 common [d], devel, minimal                 PHP scripting language

Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled

接下來直接重新將 PHP 關聯到 8.2 的模組來源,指令如下:

$ sudo yum module enable php:remi-8.2 -y
Last metadata expiration check: 0:04:46 ago on Wed May 14 17:17:25 2025.
Dependencies resolved.
================================================================================================================================
 Package                       Architecture                 Version                         Repository                     Size
================================================================================================================================
Enabling module streams:
 php                                                        remi-8.2

Transaction Summary
================================================================================================================================

Complete!

再查詢一次,就發現已經啟用 PHP 8.2 的官方來源了。

Last metadata expiration check: 0:05:16 ago on Wed May 14 17:17:25 2025.
Rocky Linux 9 - AppStream
Name                 Stream                      Profiles                                  Summary
php                  8.1                         common [d], devel, minimal                PHP scripting language
php                  8.2                         common [d], devel, minimal                PHP scripting language

Remi's Modular repository for Enterprise Linux 9 - x86_64
Name                 Stream                      Profiles                                  Summary
php                  remi-7.4                    common [d], devel, minimal                PHP scripting language
php                  remi-8.0                    common [d], devel, minimal                PHP scripting language
php                  remi-8.1                    common [d], devel, minimal                PHP scripting language
php                  remi-8.2 [e]                common [d], devel, minimal                PHP scripting language
php                  remi-8.3                    common [d], devel, minimal                PHP scripting language
php                  remi-8.4                    common [d], devel, minimal                PHP scripting language

Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled

最後安裝 PHP 8.2 的指令如下:

$ sudo yum install php-cli php-fpm php-curl php-mysqlnd php-gd php-opcache php-zip php-intl php-common php-bcmath php-imap php-imagick php-xmlrpc php-json php-readline php-memcached php-redis php-mbstring php-apcu php-xml php-dom php-redis php-memcached php-memcache php-process php-sodium php-bcmath php-gmp

輸入 y 並按下 Enter 鍵繼續下載安裝,完成安裝後請重新啟動 Apache 服務。

$ sudo systemctl restart httpd

即完成 PHP 8.2 (RockyLinux 9) 的安裝工作。

要安裝新版的 PHP 8 需要加入 Ondřej Surý (PHP 和 Debian 的首席開發人員,並維護 Ubuntu 和 Debian 套件) PHP PPA 的來源,指令如下:

$ sudo apt install software-properties-common
[sudo] password for ossii:

接下來新增 PHP 8 的 PPA 來源,指令如下:

$ sudo add-apt-repository ppa:ondrej/php

中間會出現這行訊息,請按下「Enter」鍵繼續跑。

Press [ENTER] to continue or Ctrl-c to cancel.
Hit:1 http://tw.archive.ubuntu.com/ubuntu noble InRelease
Get:2 http://tw.archive.ubuntu.com/ubuntu noble-updates InRelease [126 kB]
Get:3 http://tw.archive.ubuntu.com/ubuntu noble-backports InRelease [126 kB]
Get:4 http://tw.archive.ubuntu.com/ubuntu noble-updates/main amd64 Packages [1,090 kB]
Get:5 http://security.ubuntu.com/ubuntu noble-security InRelease [126 kB]
Get:6 http://tw.archive.ubuntu.com/ubuntu noble-updates/main Translation-en [232 kB]
Get:7 http://tw.archive.ubuntu.com/ubuntu noble-updates/main amd64 Components [161 kB]
Get:8 http://tw.archive.ubuntu.com/ubuntu noble-updates/restricted amd64 Packages [1,127 kB]
Get:9 http://tw.archive.ubuntu.com/ubuntu noble-updates/restricted Translation-en [234 kB]
Get:10 http://tw.archive.ubuntu.com/ubuntu noble-updates/restricted amd64 Components [212 B]
Get:11 http://tw.archive.ubuntu.com/ubuntu noble-updates/universe amd64 Packages [1,062 kB]
Get:12 http://tw.archive.ubuntu.com/ubuntu noble-updates/universe amd64 Components [376 kB]
Get:13 http://tw.archive.ubuntu.com/ubuntu noble-updates/multiverse amd64 Components [940 B]
Get:14 http://tw.archive.ubuntu.com/ubuntu noble-backports/main amd64 Packages [39.2 kB]
Get:15 http://tw.archive.ubuntu.com/ubuntu noble-backports/main amd64 Components [7,076 B]
Get:16 http://tw.archive.ubuntu.com/ubuntu noble-backports/restricted amd64 Components [216 B]
Get:17 http://tw.archive.ubuntu.com/ubuntu noble-backports/universe amd64 Packages [27.1 kB]
Get:18 http://tw.archive.ubuntu.com/ubuntu noble-backports/universe amd64 Components [16.4 kB]
Get:19 http://tw.archive.ubuntu.com/ubuntu noble-backports/multiverse amd64 Components [212 B]
Get:20 https://ppa.launchpadcontent.net/ondrej/php/ubuntu noble InRelease [24.3 kB]
Get:21 http://security.ubuntu.com/ubuntu noble-security/main amd64 Packages [838 kB]
Get:22 https://ppa.launchpadcontent.net/ondrej/php/ubuntu noble/main amd64 Packages [131 kB]
Get:23 https://ppa.launchpadcontent.net/ondrej/php/ubuntu noble/main Translation-en [40.6 kB]
Get:24 http://security.ubuntu.com/ubuntu noble-security/main Translation-en [154 kB]
Get:25 http://security.ubuntu.com/ubuntu noble-security/main amd64 Components [21.6 kB]
Get:26 http://security.ubuntu.com/ubuntu noble-security/restricted amd64 Packages [1,082 kB]
Get:27 http://security.ubuntu.com/ubuntu noble-security/restricted Translation-en [224 kB]
Get:28 http://security.ubuntu.com/ubuntu noble-security/restricted amd64 Components [212 B]
Get:29 http://security.ubuntu.com/ubuntu noble-security/universe amd64 Components [52.2 kB]
Get:30 http://security.ubuntu.com/ubuntu noble-security/multiverse amd64 Components [212 B]
Fetched 7,319 kB in 3s (2,184 kB/s)
Reading package lists... Done

執行 apt update 指令,也許會有需要更新的套件。

$ sudo apt update
$ sudo apt upgrade -y

PHP 的套件與模組很多,以下是一般常會用到的套件,安裝指令如下:

$ sudo apt install php8.2 libapache2-mod-php8.2 php8.2-gd php8.2-mysql php8.2-curl php8.2-mbstring php8.2-intl -y
$ sudo apt install php8.2-gmp php8.1-bcmath php8.2-imagick php8.2-xml php8.2-zip -y

如同前一章所述,Ubuntu 下的 Apache 模組需要先以 a2enmod 的指令啟用,指令如下:

$ sudo a2enmod php8.2
$ sudo systemctl restart apache2

即完成 PHP 8.2 (Ubuntu 24.04) 的安裝工作。

安裝 MariaDB 11.4 版

根據 MariaDB 官方資訊所示,目前 11.4 為 LTS(Long Term Support) 版本,社群版的部份會支援到 2029 年 6 月,所以建議佈署該版本,而在 Rocky Linux 9 預設使用的是 10 .11 版本,安裝 MariaDB 11.4 相當容易,安裝指令如下所示。

image.png

先新增官方針對 RPM 系列的 MariaDB 來源,指令如下:

$ sudo bash -c 'cat <<EOF > /etc/yum.repos.d/mariadb.repo
# MariaDB 11.4 RedHatEnterpriseLinux repository list
# https://mariadb.org/download/
[mariadb]
name = MariaDB
baseurl = https://rpm.mariadb.org/11.4/rhel/\$releasever/\$basearch
gpgkey = https://rpm.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck = 1
enabled = 1
EOF'

更新 YUM 的 Cache 資訊:

$ sudo yum clean all
$ sudo yum makecache

安裝 MariaDB Server。

$ sudo yum install mariadb mariadb-server -y

啟用 MariaDB 伺服器的服務。

$ sudo systemctl restart mariadb
$ sudo systemctl enable mariadb
Created symlink /etc/systemd/system/multi-user.target.wants/mariadb.service → /usr/lib/systemd/system/mariadb.service

接著請初始化 MariaDB 資料庫環境,在 MariaDB 11.4 後指令稍有變化,但內容一樣,指令如下:

$ sudo mariadb-secure-installation

接下來會一直問各種問題,如下所示,詢問目前 root 用戶的密碼,因為一開始沒有設定,請直接按 Enter 鍵繼續。

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
haven't set the root password yet, you should just press enter here.

Enter current password for root (enter for none):

接下來所有的問題,請都直接輸入 Y 後按下 Enter 鍵繼續,當問到設定密碼時,也是按下 Y,並設定您的 MariaDB root 密碼 2 次。

You already have your root account protected, so you can safely answer 'n'.

Change the root password? [Y/n] Y
New password:
Re-enter new password:

完成設定後請設定 MariaDB 的預設字元集(UTF8mb4),請在 /etc/my.conf.d/ 目錄中新增一個新的設定檔,指令如下:

$ sudo bash -c 'cat <<EOF > /etc/my.cnf.d/default-character.cnf
[client]
default-character-set = utf8mb4

[mysqld]
character-set-server = utf8mb4
character-set-collations = utf8mb4=uca1400_ai_ci
EOF'

重新啟動 MariaDB 服務,並確認 MariaDB 服務狀態。

$ sudo systemctl restart mariadb
$ sudo netstat -tlnp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:3306            0.0.0.0:*               LISTEN      3851/mariadbd
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      580/sshd: /usr/sbin
tcp6       0      0 :::3306                 :::*                    LISTEN      3851/mariadbd
tcp6       0      0 :::22                   :::*                    LISTEN      580/sshd: /usr/sbin
tcp6       0      0 :::80                   :::*                    LISTEN      575/httpd
tcp6       0      0 :::443                  :::*                    LISTEN      575/httpd

利用 systemctl 指令查看一下相關服務的啟用情況及版本資訊。

$ sudo systemctl status mariadb
● mariadb.service - MariaDB 11.4.5 database server
     Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; preset: disabled)
    Drop-In: /etc/systemd/system/mariadb.service.d
             └─migrated-from-my.cnf-settings.conf
     Active: active (running) since Fri 2025-05-16 18:30:42 CST; 59s ago
       Docs: man:mariadbd(8)
             https://mariadb.com/kb/en/library/systemd/
    Process: 3835 ExecStartPre=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/S>
    Process: 3837 ExecStartPre=/bin/sh -c [ ! -e /usr/bin/galera_recovery ] && VAR= ||   VAR=`/usr/bin/galera_recove>
    Process: 3863 ExecStartPost=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/>
   Main PID: 3851 (mariadbd)
     Status: "Taking your SQL requests now..."
      Tasks: 12 (limit: 13752)
     Memory: 246.1M
        CPU: 389ms
     CGroup: /system.slice/mariadb.service
             └─3851 /usr/sbin/mariadbd

May 16 18:30:42 nextcloud.ossii.com.tw mariadbd[3851]: 2025-05-16 18:30:42 0 [Note] InnoDB: Loading buffer pool(s) f>
May 16 18:30:42 nextcloud.ossii.com.tw mariadbd[3851]: 2025-05-16 18:30:42 0 [Note] Plugin 'FEEDBACK' is disabled.
May 16 18:30:42 nextcloud.ossii.com.tw mariadbd[3851]: 2025-05-16 18:30:42 0 [Note] Plugin 'wsrep-provider' is disab>
May 16 18:30:42 nextcloud.ossii.com.tw mariadbd[3851]: 2025-05-16 18:30:42 0 [Note] InnoDB: Buffer pool(s) load comp>
May 16 18:30:42 nextcloud.ossii.com.tw mariadbd[3851]: 2025-05-16 18:30:42 0 [Note] Server socket created on IP: '0.>
May 16 18:30:42 nextcloud.ossii.com.tw mariadbd[3851]: 2025-05-16 18:30:42 0 [Note] Server socket created on IP: '::>
May 16 18:30:42 nextcloud.ossii.com.tw mariadbd[3851]: 2025-05-16 18:30:42 0 [Note] mariadbd: Event Scheduler: Loade>
May 16 18:30:42 nextcloud.ossii.com.tw mariadbd[3851]: 2025-05-16 18:30:42 0 [Note] /usr/sbin/mariadbd: ready for co>
May 16 18:30:42 nextcloud.ossii.com.tw mariadbd[3851]: Version: '11.4.5-MariaDB'  socket: '/var/lib/mysql/mysql.sock>
May 16 18:30:42 nextcloud.ossii.com.tw systemd[1]: Started MariaDB 11.4.5 database server.

即完成 MariaDB 11.4 (Rocky Linux 9) 的安裝工作。

利用以下指令查詢目前系統預設所提供的 MariaDB 是否為你所需要的版本:

$ sudo apt-cache policy mariadb-server mariadb-client

Ubuntu Server 24.04 預設使用的是 10 .11 版本

mariadb-server:
  Installed: (none)
  Candidate: 1:10.11.11-0ubuntu0.24.04.2
  Version table:
     1:10.11.11-0ubuntu0.24.04.2 500
        500 http://tw.archive.ubuntu.com/ubuntu noble-updates/universe amd64 Packages
        500 http://security.ubuntu.com/ubuntu noble-security/universe amd64 Packages
     1:10.11.7-2ubuntu2 500
        500 http://tw.archive.ubuntu.com/ubuntu noble/universe amd64 Packages
mariadb-client:
  Installed: (none)
  Candidate: 1:10.11.11-0ubuntu0.24.04.2
  Version table:
     1:10.11.11-0ubuntu0.24.04.2 500
        500 http://tw.archive.ubuntu.com/ubuntu noble-updates/universe amd64 Packages
        500 http://security.ubuntu.com/ubuntu noble-security/universe amd64 Packages
     1:10.11.7-2ubuntu2 500
        500 http://tw.archive.ubuntu.com/ubuntu noble/universe amd64 Packages

安裝 MariaDB 11.4 相當容易,先新增官方針對 apt 系列的 MariaDB 來源,指令如下:

先安裝必要的 apt 相關套件:

$ sudo apt-get install apt-transport-https curl ca-certificates software-properties-common -y

匯入必要的憑證,並建立 MariaDB 11.4 APT 套件來源資訊,指令如下:

$ sudo curl -fsSL https://mirror.mariadb.org/PublicKey_v2 | sudo gpg --dearmor | sudo tee /usr/share/keyrings/mariadb.gpg > /dev/null
$ sudo echo "deb [arch=amd64,arm64,ppc64el signed-by=/usr/share/keyrings/mariadb.gpg] https://mirror.mariadb.org/repo/11.4/ubuntu/ $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/mariadb.list

接著再更新一下 apt 資訊,然後查詢一下目前可以安裝的版本為何:

$ sudo apt update -y
$ sudo apt-cache policy mariadb-server mariadb-client          
mariadb-server:
  Installed: (none)
  Candidate: 1:11.4.5+maria~ubu2404
  Version table:
     1:11.4.5+maria~ubu2404 500
        500 https://mirror.mariadb.org/repo/11.4/ubuntu noble/main amd64 Packages
     1:11.4.4+maria~ubu2404 500
        500 https://mirror.mariadb.org/repo/11.4/ubuntu noble/main amd64 Packages
     1:10.11.11-0ubuntu0.24.04.2 500
        500 http://tw.archive.ubuntu.com/ubuntu noble-updates/universe amd64 Packages
        500 http://security.ubuntu.com/ubuntu noble-security/universe amd64 Packages
     1:10.11.7-2ubuntu2 500
        500 http://tw.archive.ubuntu.com/ubuntu noble/universe amd64 Packages
mariadb-client:
  Installed: (none)
  Candidate: 1:11.4.5+maria~ubu2404
  Version table:
     1:11.4.5+maria~ubu2404 500
        500 https://mirror.mariadb.org/repo/11.4/ubuntu noble/main amd64 Packages
     1:11.4.4+maria~ubu2404 500
        500 https://mirror.mariadb.org/repo/11.4/ubuntu noble/main amd64 Packages
     1:10.11.11-0ubuntu0.24.04.2 500
        500 http://tw.archive.ubuntu.com/ubuntu noble-updates/universe amd64 Packages
        500 http://security.ubuntu.com/ubuntu noble-security/universe amd64 Packages
     1:10.11.7-2ubuntu2 500
        500 http://tw.archive.ubuntu.com/ubuntu noble/universe amd64 Packages

看到「Candidate」那部份設定的是 11.4 的版本就 OK 了,請使用以下指令進行安裝。

$ sudo apt-get install mariadb-server mariadb-client -y

安裝完成,確認一下目前的版本資訊是否正確。

$ sudo mariadb --version
mariadb from 11.4.5-MariaDB, client 15.2 for debian-linux-gnu (x86_64) using  EditLine wrapper

接下來設定初始化的方式,與上一段 Rocky Linux 9 一樣,使用以下指令:

$ sudo mariadb-secure-installation

重新啟動 MariaDB 服務,並確認 MariaDB 服務狀態。

$ sudo systemctl restart mariadb
$ sudo netstat -tlnp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 127.0.0.1:3306          0.0.0.0:*               LISTEN      32094/mariadbd
tcp        0      0 127.0.0.1:6010          0.0.0.0:*               LISTEN      1183/sshd: ossii@pt
tcp        0      0 127.0.0.54:53           0.0.0.0:*               LISTEN      537/systemd-resolve
tcp        0      0 127.0.0.53:53           0.0.0.0:*               LISTEN      537/systemd-resolve
tcp6       0      0 ::1:6010                :::*                    LISTEN      1183/sshd: ossii@pt
tcp6       0      0 :::22                   :::*                    LISTEN      1/init
tcp6       0      0 :::80                   :::*                    LISTEN      15062/apache2
tcp6       0      0 :::443                  :::*                    LISTEN      15062/apache2

利用 systemctl 指令查看一下相關服務的啟用情況及版本資訊。

$ sudo systemctl status mariadb
● mariadb.service - MariaDB 11.4.5 database server
     Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; preset: enabled)
    Drop-In: /etc/systemd/system/mariadb.service.d
             └─migrated-from-my.cnf-settings.conf
     Active: active (running) since Mon 2025-05-19 12:02:43 CST; 5s ago
       Docs: man:mariadbd(8)
             https://mariadb.com/kb/en/library/systemd/
    Process: 31936 ExecStartPre=/usr/bin/install -m 755 -o mysql -g root -d /var/run/mysqld (code=exited, status=0/SUCCESS)
    Process: 31940 ExecStartPre=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
    Process: 31942 ExecStartPre=/bin/sh -c [ ! -e /usr/bin/galera_recovery ] && VAR= ||   VAR=`/usr/bin/galera_recovery`; [ $? -eq 0 ]   && systemctl set-environment _WSREP_START_POSITION=$VAR || exit 1 (code=exited, statu>
    Process: 31992 ExecStartPost=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
    Process: 31994 ExecStartPost=/etc/mysql/debian-start (code=exited, status=0/SUCCESS)
   Main PID: 31978 (mariadbd)
     Status: "Taking your SQL requests now..."
      Tasks: 14 (limit: 14994)
     Memory: 166.7M (peak: 256.1M)
        CPU: 4.645s
     CGroup: /system.slice/mariadb.service
             └─31978 /usr/sbin/mariadbd

May 19 12:02:41 ubuntu-nextcloud mariadbd[31978]: 2025-05-19 12:02:41 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
May 19 12:02:41 ubuntu-nextcloud mariadbd[31978]: 2025-05-19 12:02:41 0 [Note] Plugin 'FEEDBACK' is disabled.
May 19 12:02:41 ubuntu-nextcloud mariadbd[31978]: 2025-05-19 12:02:41 0 [Note] Plugin 'wsrep-provider' is disabled.
May 19 12:02:41 ubuntu-nextcloud mariadbd[31978]: 2025-05-19 12:02:41 0 [Note] InnoDB: Buffer pool(s) load completed at 250519 12:02:41
May 19 12:02:42 ubuntu-nextcloud mariadbd[31978]: 2025-05-19 12:02:42 0 [Note] Server socket created on IP: '127.0.0.1'.
May 19 12:02:42 ubuntu-nextcloud mariadbd[31978]: 2025-05-19 12:02:42 0 [Note] mariadbd: Event Scheduler: Loaded 0 events
May 19 12:02:42 ubuntu-nextcloud mariadbd[31978]: 2025-05-19 12:02:42 0 [Note] /usr/sbin/mariadbd: ready for connections.
May 19 12:02:42 ubuntu-nextcloud mariadbd[31978]: Version: '11.4.5-MariaDB-ubu2404'  socket: '/run/mysqld/mysqld.sock'  port: 3306  mariadb.org binary distribution
May 19 12:02:43 ubuntu-nextcloud systemd[1]: Started mariadb.service - MariaDB 11.4.5 database server.
May 19 12:02:43 ubuntu-nextcloud /etc/mysql/debian-start[31997]: Upgrading MariaDB tables if necessary.

即完成 MariaDB 11.4 (Ubuntu Server 24.04) 的安裝工作。


Revision #10
Created 14 May 2025 06:59:34 by kevin
Updated 19 May 2025 04:04:45 by kevin