1) VirtualBox (我的主機是Win11)
VirtualBox 7.0.8 Windows hosts ISO: https://www.virtualbox.org/wiki/Downloads
1.1) install VirtualBox 7.0.8 Oracle VM VirtualBox Extension Pack
1.2) install guest addition in ubuntu client:
check guest addition is installed ok:
$ lsmod | grep vboxguest
vboxguest 434176 7 vboxsf
Win11 用 ipconfig check wifi IP - 192.168.x.xxx (e.g. change to 192.168.x.x as static IP), set up wifi as bridge adapter (網路設定成橋接介面卡)
2) VirtualBox 建立新的 Ubuntu Server 教學:
https://ubuntu.com/download/server (now is 22.04.2 LTS)
手動設定固定 IP:
sudo netplan generate
sudo pico /etc/netplan/00-installer-config.yaml (更改成 fix ip)
network:
version: 2
renderer: networkd
ethernets:
enp0s3:
dhcp4: no
gateway4: 192.168.0.1
addresses: [192.168.x.x/24]
nameservers:
addresses: [8.8.8.8,8.8.4.4]
Windows 11 固定IP設定方式
家中Router 設定 DDNS (我由約 2000年已使用 noip.com ...)
2.1) after ubuntu server setup:
sudo apt update && sudo apt upgrade -y
timedatectl set-timezone Asia/Taipei
hostnamectl set-hostname xxx.no-ip.com
sudo apt install cockpit
sudo systemctl enable --now cockpit.socket
sudo systemctl status cockpit.socket
Access cockpit thru:
https://192.168.x.x:9090/
ping -c 5 www.google.com
ifconfig
ip a
sudo service ssh status
2.2) 安裝LAMP Server and phpmyadmin
sudo apt purge phpmyadmin
sudo apt install phpmyadmin
sudo service apache2 restart
2.3) install ubuntu desktop on ubuntu server
sudo apt install ubuntu-desktop
sudo apt install lightdm
Install google browser
sudo dpkg -i google-chrome-stable_current_amd64.deb
3) 建立wordpress
wp-config.php 設置 : https://developer.wordpress.org/apis/wp-config-php/
Google Blogger部落格文章搬家到WordPress:
Manual upgrade for WordPress:
tar -zxvf wordpress-6.2.2-zh_TW.tar.gz
rm -r wp-content (delete this folder) in the .gz file
sudo cp -r wordpress /var/www/
3.1) 部落格搬家麻煩的事, 搬 blog 總有大大小小怪問題,例如不是全部相片下載到 server,那麼如果用作備份還可,相片的連結仍是 blogger 可見。
登入: mysql -u root -p
mysql>use wordpress;
mysql>select * from wp_options limit 2;
option_name option_value
siteurl http://192.168.x.x
home http://xxx.no-ip.com
mysql>exit
修改配置文件 replace local url by 域名 url :
mysql>UPDATE wp_options SET option_value = replace(option_value, 'http://192.168.x.x', 'http://xxx.no-ip.com') WHERE option_name = 'home';
WordPress內外網同時訪問問題解決方法:
amend /var/www/wordpress/wp-includes/option.php:
家中 Router 需要 port forward 80/443至 ubuntu server ip.
3.2) 想起廿多年前用Linux Fedora 架站後,試過 lifetype (官方已結束維護),工貿署2013年為中小企推廣 Joomla! 建網站,在網上找到:
我好像 2005年剛出已用過功能全面的 Joomla 建設網誌。所以,又嘗試它。
建立Joomla 4.3.1:
4) enable SSL (http to https)
e.g. self-signed certificate
openssl req -x509 -newkey rsa:4096 -sha256 -days 3650 -nodes \
-keyout example.key -out example.crt
sudo openssl req -x509 -nodes -days 3650 -newkey rsa:2048 -keyout /etc/ssl/private/xxx.no-ip.com.key -out /etc/ssl/certs/xxx.no-ip.com.crt
create 000-default.conf for <VirtualHost *:80> and xxx.no-ip.com-ssl.conf for <VirtualHost *:443> (refer step 6):
cat /etc/apache2/sites-available/xxx.no-ip.com-ssl.conf
sudo a2enmod ssl
sudo a2ensite xxx.no-ip.com-ssl.conf
Enable/Disable your site config using sudo a2ensite {name} or sudo a2dissite {name}.
sudo systemctl restart apache2
sudo apache2ctl -S to check if :80 :443 is enabled
OR (Let's Encrypt, this is work in browser)
Install SNAP and Let's Encrypt using CERTBOT
5) share folder in VirtualBox
mkdir temp
/home/<admin>/temp
sudo mount -t vboxsf 分享資料夾名稱 掛載路徑
sudo mount -t vboxsf [sourcedir] /home/[admin]/[destdir]
Auto mount at startup example:
As root (i.e. sudo) Go to home folder and create a cron file:
sudo pico cronjobs; Add the following and save file
@reboot sleep 15; mount -t vboxsf temp /home/ubuntuadmin/temp
To enable your cron as root (for above filename)
crontab cronjobs
Make sure cron is active:
crontab -l
6) share folder using webdav ; setup davfs to allow webDAV, and WebDAV with user authentication
matthew is the user id to login webdav:
sudo htpasswd -c /etc/apache2/webdav.passwords matthew
sudo pico /etc/apache2/sites-available/xxx-no-ip.com-ssl.conf:
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerAdmin webmaster@localhost
ServerName xxx.no-ip.com
DocumentRoot /var/www/wordpress
Alias /webdav /var/www/webdav
<Location /webdav>
Options Indexes
DAV On
AuthType Basic
AuthName "webdav"
AuthUserFile /etc/apache2/webdav.password
Require valid-user
</Location>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
SSLEngine on
SSLCertificateFile /etc/ssl/certs/xxx.no-ip.com.crt
SSLCertificateKeyFile /etc/ssl/certs/xxx.no-ip.com.key
</VirtualHost>
</IfModule>
sudo pico /etc/apache2/sites-available/000-default.conf
<IfModule mod_ssl.c>
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/wordpress
Alias /webdav /var/www/webdav
<Location /webdav>
Options Indexes
DAV On
AuthType Basic
AuthName "webdav"
AuthUserFile /etc/apache2/webdav.password
Require valid-user
</Location>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
</IfModule>
/etc/davfs2/davfs2.conf
sudo pico /etc/davfs2/secrets
7)在 ubuntu server 設定 防火牆 ufw firewall
sudo apt install ufw
sudo ufw default deny incoming
sudo ufw default allow outgoing
根據自己需要,例如: Web server可開啓 port 80 等。
sudo ufw allow 80
設定好可以指令令其生效。
sudo ufw enable
檢視現有設定可用這:
sudo ufw status numbered
sudo ufw status verbose
sudo ufw reset (if need delete)
8) NextCloud install
mysql -u root -p
CREATE USER 'nextcloud'@'localhost' IDENTIFIED BY 'passw@rd';
CREATE DATABASE IF NOT EXISTS nextcloud CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
GRANT ALL PRIVILEGES ON nextcloud.* TO 'nextcloud'@'localhost';
FLUSH PRIVILEGES;
quit;
cd /var/www/
sudo wget https://download.nextcloud.com/server/releases/latest.zip
sudo unzip latest.zip
sudo rm -rf latest.zip
sudo chown -R www-data:www-data /var/www/nextcloud/
sudo -u www-data php occ maintenance:install --database \
"mysql" --database-name "nextcloud" --database-user "nextcloud" --database-pass \
"passw@rd" --admin-user "admin" --admin-pass "admin123"
wait and after completed, Nextcloud was successfully installed
add domain and set pretty and shorter URLs remove the "index.php” part in all Nextcloud URLs.
sudo pico /var/www/nextcloud/config/config.php
'trusted_domains' =>
array (
0 => 'localhost',
1 => 'yyy.no-ip.com',
),
'htaccess.RewriteBase' => '/',
config ssl like step 4 and 6:
sudo pico /etc/apache2/sites-available/yyy.no-ip.com-ssl.conf
HTTP Strict Transport Security, which instructs browsers not allow any connection to the Nextcloud instance using HTTP, it prevents man-in-the-middle attack.
<VirtualHost *:443>
ServerName yyy.no-ip.com
<IfModule mod_headers.c>
Header always set Strict-Transport-Security "max-age=15552000; includeSubDomains"
</IfModule>
</VirtualHost>
9) antivirus - ClamAV / Clamtk
After install, get latest signatures of virus:
sudo freshclam
sudo mkdir temp/archive (for moving infected file to a specified location)
To scan the whole system (need a while):
clamscan -r --infected --move=temp/archive --exclude-dir="^/sys" /
Clamtk (GUI) - https://www.imaginelinux.com/clamtk-for-ubuntu/
10) 遙遠登入 virtualbox client
用另一台電腦登入 我的Win11 主機(192.168.x.x),利用微軟的 (remote desktop, port default 3389) 便可。
而在 Virtualbox client display 頁設定 3390-4000 任何一個port(例:我用 3390),剔選enable server。
在Win11 主機的 firewall 新增此 port 的 inbound traffic。
那麼, 用另一台電腦 RDP
192.168.x.x:3390
便見到我 Ubuntu client 的登入画面了。
後記:
如果起 Server, 自動 down, up vm 會是關鍵動作,因我用 win11, 那使用 task scheduler 便能達成。
我將 action 放在 .bat 再令 scheduler在 boot 機時運行它。
另外,我每週設定定時一次 reboot 可用
shutdown -r (會在一分鐘內重開機)。
参考這篇,而不要使用 login 後的 startup folder。
另外,網上見到香港朋友 Toby Chiu 的大作AroZos, 只需用 URL 便可控制聽歌看片分享檔案,功能強大,稍後作另文介紹安裝方法。
-------END-------
沒有留言:
張貼留言