2018年6月23日 星期六

Ubuntu Server 16.x 上安裝 LAMP


sudo apt install apache2 mariadb-server php7.0-mysql php7.0-curl php7.0-json php7.0-cgi
php7.0 libapache2-mod-php7.0


設定mariadb server
sudo mysql_secure_installation


建立測試網頁
cd  /var/www/html/
vi samplepage.php
加入以下參數
<?php
  phpinfo():
php?>


啟動與重開機啟動服務

sudo systemctl start  apache2.service
sudo systemctl enable apache2.service


sudo systemctl start  mysql
sudo systemctl enable mysql



Ubuntu入門 系統更新指令(apt-get)一些常用指令
指令一:sudo apt-get update
說明:用來取得遠端更新伺服器的套件檔案清單。

指令二:sudo apt-get -y dist-upgrade
說明:更新套件。

指令三:sudo apt-get clean
說明:清除更新時所下載回來的更新(安裝)檔案。
PS:前提是您的Linux要連上網際網路,以及取得root權限,以下sudo指令就是用來取得root權限的!
查詢所有已安裝套件的清單
dpkg --get-selections


查詢是否安裝某套件
dpkg --get-selections | grep apache


將所安裝套件列出List表
dpkg --get-selections > installed_packages.txt
只會產生二欄資料,一欄是套件名稱,一欄是狀態,適合用來給用程式做後續處理用
dpkg -l  > installed_packages.txt
適合拿來製表使用哩


sudo apt-get update
# 同步系統套件庫清單


sudo apt-get upgrade
# 更新沒有套件相依性問題的套件


sudo apt-get dist-upgrade
# 依照套件相依性更新所有套件


sudo apt-get install
# 自動安裝指定的套件


sudo apt-get remove
# 自動移除套件,並留下設定檔


sudo apt-get --purge remove
# 自動移除套件,不保留設定檔


sudo apt-get clean
# 移除所有的套件暫存檔案 /var/cache/apt/archives


sudo apt-get autoclean
# 移除所有舊版的套件暫存檔案,最新版本保留


可用參數:


-y 自動回答 yes
-s 安全模式,測試安裝 / 移除
-f 強制模式,強制安裝或修正錯誤
-d 只下載 deb 套件並存放在 /var/cache/apt/archives
--reinstall 重新安裝套件


sudo dpkg --configure -a
# 重新設定之前因中斷等因素還沒裝好的套件


sudo synaptic
# 用圖形化界面管理 APT 套件庫


Ubuntu iptables 設定
1.#請在家目錄內建立backup資料夾
mkdir /home/user/backup

2.建立一檔案名為 iptables.sh,內容如下:
#!/bin/bash
iptables -P INPUT DROP
iptables -A INPUT -i lo -j ACCEPT
# 127.0.0.1 本地端回應全接受
iptables -A INPUT -i eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT
#針對 eth0 這張網卡,設定我主動發出去的回應都予放行
#iptables -A INPUT -i eth0 -s 192.168.0.0/24 -j ACCEPT
# 192.168.0.1~255 這個網段全放行

# 設定主機上提供的服務可讓外部網路存取
iptables -A INPUT -i eth0 -p tcp --dport 22 -j ACCEPT # ssh
iptables -A INPUT -i eth0 -p tcp --dport 80 -j ACCEPT # http
iptables -A INPUT -i eth0 -p tcp --dport 3306 -j ACCEPT # mariadb

iptables -A INPUT -i eth0 -p tcp -s x.x.x.x -d x.x.x.x --dport 80 -j ACCEPT # http
## -s x.x.x.x <--來源IP    -d x.x.x.x <--目的IP

2.建立捷徑,請下指令
sudo ln -s /home/user/backup/iptables.sh /etc/init.d/iptables.sh

設定成可執行的權限
chmod 755 /home/user/backup/iptables.sh

註:/home/user 這個地方的"user"請更改成你的登入帳號名稱

3.加入啟動項目,請下指令
sudo update-rc.d -f iptables.sh defaults

4.重開機後,請用指令檢查
sudo iptables -L -n

往後你若想要修改防火牆的設定時,只要去修改此檔即可 /home/user/backup/iptables.sh
修改完再重開機就行了


Ubuntu 14.04 主機的終端機中文顯示

在Ubuntu 12.04 及Ubuntu 14.04 我們利用Terminal登入主機 卻不能顯示中文
 一定要顯示中文時 請如下修改:
1.編修 /var/lib/locales/supported.d/local 檔案
zh_TW BIG5
en_US.UTF-8 UTF-8
加入 zh_TW.UTF-8 UTF-8


zh_TW BIG5
en_US.UTF-8 UTF-8
zh_TW.UTF-8 UTF-8

2.重新製作local sudo  locale-gen

3. 修改預設的顯示語系 /etc/default/locale
sudo vim /etc/default/locale
全改為zh_TW.UTF-8
如下所示
LANG="zh_TW.UTF-8"
LANGUAGE="zh_TW.UTF-8"
LC_NUMERIC="zh_TW.UTF-8"
LC_TIME="zh_TW.UTF-8"
LC_MONETARY="zh_TW.UTF-8"
LC_PAPER="zh_TW.UTF-8"
LC_NAME="zh_TW.UTF-8"
LC_ADDRESS="zh_TW.UTF-8"
LC_TELEPHONE="zh_TW.UTF-8"
LC_MEASUREMENT="zh_TW.UTF-8"
LC_IDENTIFICATION="zh_TW.UTF-8"

這樣登出再登入就可以看到中文了

沒有留言:

張貼留言