係Ubuntu 18.04 上 安裝 NextCloud With LEMP Stack!(上)——安裝LEMP Stack,b,

Posted on Mon, Jul 9, 2018 科技趣聞 Unix/Linux

下文:

我接受唔到啊.jpg

本身對conoha嘅垃圾網絡同莫名其妙嘅潛規則感到唔多滿意,早已有出走嘅念頭。所以收到時候瞬間已經決更換VPS。(幸好Blog晨早搬咗做Hexo,不幸中嘅大幸)。

VPS

首先當然要有個VPS先啦。做咗一輪嘅search,發覺linode評價唔差,而且價錢實惠穩定,重要係咩啊?唔會有無限bandwidth啊!打開 Linode VPS 嘅網站,註冊。btw,而家輸入 promo code atp2018 仲有20蚊credit。

註冊好之後,新建新嘅VPS,之後選擇Ubuntu 18.04 init,完成之後可以經ssh登入啦。

準備

之後可以經ssh登入VPS:ssh [email protected]<your vps ip>

首先更新packages確保係最新嘅:apt update && apt upgrade

安裝 nginx

之後安裝nginx:apt install nginx

enable nginx嘅 service:systemctl enable nginx

啓動nginx嘅service:systemctl start nginx

查看nginx service 嘅狀態:systemctl status nginx

output sample:

● nginx.service - A high performance web server and a reverse proxy server
   Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
   Active: active (running) since Thu 2018-05-17 02:20:05 UTC; 2min 56s ago
     Docs: man:nginx(8)
 Main PID: 19851 (nginx)
    Tasks: 2 (limit: 2059)
   CGroup: /system.slice/nginx.service
           ├─19851 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
           └─19853 nginx: worker process

檢查nginx嘅版本:nginx -v

output sample:nginx version: nginx/1.14.0 (Ubuntu)

之後係browser 鍵入你嘅ip應該可以見到welcome page:

之後記得給予 nginx user對web server root嘅擁有權:sudo chown www-data:www-data /var/www/html -R

安裝 MariaDB

之後安裝MariaDB:apt install mariadb-server mariadb-client

查看 maridaDB嘅service嘅狀態:systemctl status mariadb

output sample:

● mariadb.service - MariaDB database server
   Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset: enabled)
   Active: active (running) since Thu 2018-05-17 02:39:57 UTC; 49s ago
 Main PID: 21595 (mysqld)
   Status: "Taking your SQL requests now..."
    Tasks: 27 (limit: 2059)
   CGroup: /system.slice/mariadb.service
           └─21595 /usr/sbin/mysqld

如果沒有開啓嘅話記得開啓:systemctl start mariadb

仲有enable埋:systemctl enable mariadb

之後執行installation script:mysql_secure_installation

基本上除咗Y/n就係enter,跟住指示做就得。

之後可以試下登入mariaDB:mariadb -u root

離開:exit;

檢查mariaDB嘅版本:mariadb --version

outut sample:mariadb Ver 15.1 Distrib 10.1.29-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2

記得開啓php7.7-fpm:systemctl start php7.2-fpm

開埋:systemctl enable php7.2-fpm

檢查狀態:systemctl status php7.2-fpm

output sample:

● php7.2-fpm.service - The PHP 7.2 FastCGI Process Manager
   Loaded: loaded (/lib/systemd/system/php7.2-fpm.service; enabled; vendor prese
   Active: active (running) since Thu 2018-05-17 03:04:46 UTC; 2min 43s ago
     Docs: man:php-fpm7.2(8)
 Main PID: 31922 (php-fpm7.2)
   Status: "Processes active: 0, idle: 2, Requests: 0, slow: 0, Traffic: 0req/se
    Tasks: 3 (limit: 2059)
   CGroup: /system.slice/php7.2-fpm.service
           ├─31922 php-fpm: master process (/etc/php/7.2/fpm/php-fpm.conf)
           ├─31939 php-fpm: pool www
           └─31940 php-fpm: pool www

創建 nginx block

事實上,除咗就咁成個 path當web server外,nginx當然亦可以建立類似virtual host咁,按訪問嘅port/domain唔同射去唔同嘅path嚟處理個request,而nginx會讀取 /etc/nginx/conf.d/ 下嘅所有config file。所以可以一個file for一個application都無問題。

首先移除原有嘅設定文件:rm /etc/nginx/sites-enabled/default

新建設定文件:nano /etc/nginx/conf.d/default.conf

填入,記得修改servername:```server {listen 80;listen [::]:80;server_name ; #改成你嘅dmain nameroot /var/www/html/;index index.php index.html index.htm index.nginx-debian.html;

location / {try_files $uri $uri/ /index.php;}

location ~ .php$ {fastcgi_pass unix:/run/php/php7.2-fpm.sock;fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;include fastcgi_params;include snippets/fastcgi-php.conf;}

location ~ /.ht {deny all;}}


儲存,離開。

測試設定冇問題:
`nginx -t`

output sample:

nginx: the configuration file /etc/nginx/nginx.conf syntax is oknginx: configuration file /etc/nginx/nginx.conf test is successful```

重開nginx:systemctl reload nginx

之後測試PHP,創建測試文件:nano /var/www/html/info.php

填入:<?php phpinfo(); ?>

儲存離開,並訪問該文件:<your domain / ip>/info.php

會出現類似嘅頁面:

冇問題之後記得順手移除就ok啦:rm /var/www/html/info.php

完。

參考: