內容選單標籤

2026年4月26日 星期日

Ubuntu26.04

----------------------------------------------------------------- 安裝ubuntu26.04約30分

 


 
 







##每次上串照片只能2張,否則順序相反!





-----------------------------------------------------------------  檢查分割區掛載

 $ ls /
bin   cdrom  etc   lib    lost+found  mnt  proc  run   snap  swap.img  tmp  var
boot  dev    home  lib64  media       opt  root  sbin  srv   sys       usr
$ ls /mnt
backup
 

$ df /dev/sda* -h
檔案系統        容量  已用  可用 已用% 掛載點
devtmpfs        3.4G     0  3.4G    0% /dev
/dev/sda1       1.1G  6.4M  1.1G    1% /boot/efi
/dev/sda2        94G   12G   77G   14% /
/dev/sda3       139G   11G  122G    8% /mnt/backup

$ lsblk
NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTS
...
sda      8:0    0 238.5G  0 disk 
├─sda1   8:1    0     1G  0 part /boot/efi
├─sda2   8:2    0  95.4G  0 part /
└─sda3   8:3    0 142.1G  0 part /mnt/backup

$ sudo blkid /dev/sda3
[sudo: authenticate] 密碼:         
/dev/sda3: UUID="399a1d65-031b-4c29-a197-15fd5acd4393" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="6d0ae669-f55c-4b70-87c8-a3982a2decf8"

 $ sudo nano /etc/fstab
  GNU nano 8.7.1                                        /etc/fstab                                                 
# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
# / was on /dev/sda2 during curtin installation
/dev/disk/by-uuid/92dc97bf-1df4-4463-8fd2-55489431de2d / ext4 defaults 0 1
# /mnt/backup was on /dev/sda3 during curtin installation
/dev/disk/by-uuid/399a1d65-031b-4c29-a197-15fd5acd4393 /mnt/backup ext4 defaults 0 1
# /boot/efi was on /dev/sda1 during curtin installation
/dev/disk/by-uuid/43B4-268A /boot/efi vfat defaults 0 1
/swap.img       none    swap    sw      0       0

-----------------------------------------------------------------安裝timeshift 

$ sudo apt update && sudo apt upgrade -y 

$ sudo apt install timeshift -y

 

-----------------------------------------------------------------  版本

uname -a
Linux ubuntu2604 7.0.0-14-generic #14-Ubuntu SMP PREEMPT_DYNAMIC Mon Apr 13 11:09:53 UTC 2026 x86_64 GNU/Linux 

lsb_release -a
No LSB modules are available.
Distributor ID:    Ubuntu
Description:    Ubuntu 26.04 LTS
Release:    26.04
Codename:    resolute

cat /etc/os-release
PRETTY_NAME="Ubuntu 26.04 LTS"
NAME="Ubuntu"
VERSION_ID="26.04"
VERSION="26.04 (Resolute Raccoon)"
VERSION_CODENAME=resolute
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=resolute
LOGO=ubuntu-logo
 

-----------------------------------------------------------------更新 

sudo apt update && sudo apt upgrade -y 

-----------------------------------------------------------------網路校時 

#設定時區
 sudo timedatectl set-timezone Asia/Taipei

#啟用自動校時
sudo timedatectl set-ntp on

timedatectl
               Local time: 二 2026-04-28 12:44:55 CST
           Universal time: 二 2026-04-28 04:44:55 UTC
                 RTC time: 二 2026-04-28 04:44:55
                Time zone: Asia/Taipei (CST, +0800)
System clock synchronized: yes
              NTP service: active
          RTC in local TZ: no
 

----------------------------------------------------------------- 安裝chrome


wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb

ls -l

sudo apt install ./google-chrome-stable_current_amd64.deb

-----------------------------------------------------------------

-----------------------------------------------------------------

-----------------------------------------------------------------

-----------------------------------------------------------------

-----------------------------------------------------------------

-----------------------------------------------------------------

----------------------------------------------------------------- 

 



2026年4月24日 星期五

Ubuntu24.04 練習

--------------------------------------------------------------------時區 

  date
Fri Apr 24 08:13:46 AM UTC 2026

sudo timedatectl set-timezone Asia/Taipei

 date
Fri Apr 24 04:16:53 PM CST 2026

--------------------------------------------------------------------cpu、memory、disk

 lscpu

 free -h

 df -h   #"Disk Free",-h 代表 "Human-readable",會以 GB 或 MB 顯示

 du -h   #"Disk Usage"

 sudo du -sh /var/log

 

lsblk -p /dev/sda   #list block devices 查看樹狀分區結構

sudo fdisk -l /dev/sda   #manipulate disk partition table 查看分區表詳細規格

--------------------------------------------------------------------定輸出年、月的月曆

 cal 04 2026

--------------------------------------------------------------------

 

--------------------------------------------------------------------

--------------------------------------------------------------------

--------------------------------------------------------------------

--------------------------------------------------------------------

--------------------------------------------------------------------

-------------------------------------------------------------------- 


Ubuntu24.04 for Apache2+php+MariaDB

 Windows11 + VMware +Ubuntu24.04 Server(192.168.209.131/24)

-------------------------------------------------------------------

#系統安裝後,更新
sudo apt update
sudo apt upgrade

#安裝ssh
sudo systemctl status ssh
apt list --installed | grep ssh
sudo apt install openssh-server
sudo systemctl status ssh
sudo systemctl start ssh
sudo systemctl enable ssh
ss -tunlp

#防火牆放行ssh
sudo ufw status
sudo ufw enable
sudo ufw allow ssh
sudo ufw status

#PuTTY安裝設定
左上圖示  Change Setting  Window  Apperance  Font Setting  Change  大小:18
選取視窗中文字,滑鼠左鍵一下,即將內容複製到剪貼簿中

#安裝Apache
sudo apt install apache2
apt list --installed | grep apache2
systemctl status apache2
sudo ufw allow "Apache Full"   &&HTTP + HTTPS
sudo ufw status
ss -tunpl
http://192.168.209.131/

#安裝php
sudo apt install php libapache2-mod-php php-mysql php-curl php-gd php-mbstring php-xml -y
apt list --installed | grep php
php -v
sudo systemctl restart apache2
#測試php環境
echo "<?php phpinfo();?>" | sudo tee /var/www/html/info.php
cat /var/www/html/info.php
http://192.168.209.131/info.php

#安裝MariaDB
sudo apt install mariadb-server -y
sudo systemctl status mariadb
#執行安全安裝腳本
sudo mysql_secure_installation

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

#建立資料庫與使用者
sudo mariadb
MariaDB [(none)]> create database Dbkk;
MariaDB [(none)]> create user "kk"@"localhost" identified by "db123456";
MariaDB [Dbkk]> grant all privileges on Dbkk.* to "kk"@"localhost";
MariaDB [(none)]> flush privileges;
MariaDB [(none)]> exit
#建立資料表
sudo mariadb -u kk -p
Enter password:db123456
MariaDB [(none)]> show databases;
MariaDB [(none)]> use Dbkk;
MariaDB [Dbkk]> create table TabCla(Idno int auto_increment primary key,Na varchar(100),Acnt varchar(100));
MariaDB [Dbkk]> show tables;
MariaDB [Dbkk]> describe TabCla;
#新增一筆資料
MariaDB [Dbkk]> insert into TabCla(Na,Acnt) values("測試員01","test01");
MariaDB [Dbkk]> select * from TabCla;
#使用者家目錄建立web資料夾,軟連結到Apache目錄
mkdir -p  /home/kk/web
sudo ln -s /home/kk/web /var/www/html/web
ls -al /home/kk

drwxrwxr-x 2 kk   kk   4096 Apr 24 06:11 web

ls -al /var/www/html

lrwxrwxrwx 1 root root    12 Apr 24 06:12 web -> /home/kk/web

#確保Apache有權限讀取家目錄
chmod 755 /home/kk
chmod 755 /home/kk/web

ls -al /home/kk

drwxr-xr-x 2 kk   kk   4096 Apr 24 06:11 web

ls -al /var/www/html

lrwxrwxrwx 1 root root    12 Apr 24 06:12 web -> /home/kk/web

#測試
nano web/01.html
<H1>TEST!</H1>
http://192.168.209.131/web/01.html

#建立PHP

#連線資料庫
nano web/db.php
<?php
$host = 'localhost';
$dbname = 'Dbkk';
$user = 'kk'; // 建議使用您之前建立的特定帳號
$pass = 'db123456';

try {
    $pdo = new PDO("mysql:host=$host;dbname=$dbname;charset=utf8", $user, $pass);
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
    die("連線失敗: " . $e->getMessage());
}
?>


#瀏覽所有資料
nano web/ListCla.php
<?php
include 'db.php';
$stmt = $pdo->query("SELECT * FROM TabCla");
echo "<h1>資料列表</h1><table border='1'><tr><th>ID</th><th>姓名</th><th>帳號</th><th>操作</th></tr>";
while ($row = $stmt->fetch()) {
    echo "<tr>
            <td>{$row['Idno']}</td>
            <td>{$row['Na']}</td>
            <td>{$row['Acnt']}</td>
            <td>
                <a href='ModiCla.php?id={$row['Idno']}'>修改</a> |
                <a href='delCla.php?id={$row['Idno']}'>刪除</a>
            </td>
          </tr>";
}
echo "</table><br><a href='addCla.php'>新增資料</a>";
?>

 

#新增功能
nano web/addCla.php
<?php
include 'db.php';
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $stmt = $pdo->prepare("INSERT INTO TabCla (Na, Acnt) VALUES (?, ?)");
    $stmt->execute([$_POST['Na'], $_POST['Acnt']]);
    header("Location: ListCla.php");
}
?>
<form method="post">
    姓名: <input type="text" name="Na" required><br>
    帳號: <input type="text" name="Acnt" required><br>
    <button type="submit">送出新增</button>
</form>

  

#刪除功能
nano web/delCla.php
<?php
include 'db.php';
if (isset($_GET['id'])) {
    $stmt = $pdo->prepare("DELETE FROM TabCla WHERE Idno = ?");
    $stmt->execute([$_GET['id']]);
}
header("Location: ListCla.php");
?>

  

#查詢與修改功能 
nano web/ModiCla.php
<?php
include 'db.php';
$id = $_GET['id'];
$stmt = $pdo->prepare("SELECT * FROM TabCla WHERE Idno = ?");
$stmt->execute([$id]);
$row = $stmt->fetch();

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $upd = $pdo->prepare("UPDATE TabCla SET Na = ?, Acnt = ? WHERE Idno = ?");
    $upd->execute([$_POST['Na'], $_POST['Acnt'], $id]);
    header("Location: ListCla.php");
}
?>
<form method="post">
    姓名: <input type="text" name="Na" value="<?=$row['Na']?>"><br>
    帳號: <input type="text" name="Acnt" value="<?=$row['Acnt']?>"><br>
    <button type="submit">確認修改</button>
</form>


http://192.168.209.131/web/ListCla.php