$sudo apt udate
$sudo apt upgrade
安裝web server,使用nginx
$sudo apt install nginx
開機時自動啟動nginx
$sudo systemctl enable nginx
啟動nginx
$sudo systemctl start nginx
檢查nginx 狀態
$sudo systemctl status nginx
確認nginx設定檔是否正確
$nginx -t
這邊已經安裝好了,可以使用瀏覽器輸入IP連上看看。
注意防火牆應該預設是使用ufw
如果要多個網站放在同一台,也就是虛擬主機,他的設定檔放在 /etc/nginx/sites-available/
我開一個MYDOMAIN.com 的檔案,下面是內容範本
server { listen 80; listen [::]:80; server_name MYDOMAIN.com; root /usr/share/nginx/html/; index index.php index.html ; location / { try_files $uri $uri/ /index.php; } # php7.4-fpm location ~ \.php$ { fastcgi_pass unix:/run/php/php7.4-fpm.sock; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; include snippets/fastcgi-php.conf; } # speed up repeat visits to your page, cached 360 days location ~*\.(jpg|jpeg|gif|png|webp|svg|ttf|css|js|ico|xml)$ { access_log off; log_not_found off; expires 360d; } # disable access to hidden files location ~ /\.ht { access_log off; log_not_found off; deny all; } }
完成後要ln 到sites-enabled內
#ln -s /etc/nginx/sites-available/mydomain.com /etc/nginx/sites-enabled/
檢查nginx設定是否正確。若有錯要需要排查一下
$nginx -t
沒問題就重啟nginx
$sudo systemctl restart nginx.service
安裝數據資料庫MariaDB
$apt install mariadb-server mariadb-client
檢查狀態
$systemctl status mariadb
啟動mariadb
$sudo systemctl start mariadb
開機自動啟動設定
$sudo systemctl enable mariadb
初始化安裝安全設定
$sudo mysql_secure_installation
進入資料庫
$sudo mariadb -u root
登出指令 exit ;
確認版本
$ mariadb –version
預設只會開啟本機localhost連線,若要對外直接打開PORT讓外部連線
# vi /etc/mysql/mariadb.conf.d/50-server.cnf
將內容的 bind-address = 127.0.0.1 前面加上註解# 即可,
變成 #bind-address = 127.0.0.1
安裝PHP,這邊使用PHP7.4
$ sudo apt install php7.4 php7.4-fpm php7.4-mysql php-common php7.4-cli php7.4-common php7.4-json php7.4-opcache php7.4-readline php7.4-mbstring php7.4-xml php7.4-gd php7.4-curl
啟動PHP
$sudo systemctl start php7.4-fpm
開機時自動啟動
$sudo systemctl enable php7.4-fpm
檢查狀態
$systemctl status php7.4-fpm