Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Install WordPress on Linode

chph
April 07, 2017

Install WordPress on Linode

chph

April 07, 2017
Tweet

More Decks by chph

Other Decks in Technology

Transcript

  1. 延續上回遭遇問題 • PHP 7.0 安裝完成後,撰寫 hello.php 放到 / var/www/html ⽬目錄

    • 瀏覽 http://{Linode 機器IP}/hello.php • PHP 程式碼原封不動印出 !?
  2. 安裝後資訊 • Creating config file /etc/php/7.0/apache2/php.ini with new version •

    Module mpm_event disabled. • Enabling module mpm_prefork. • apache2_switch_mpm Switch to prefork • apache2_invoke: Enable module php7.0 • Setting up php7.0 (7.0.15-0ubuntu0.16.04.4) ... • Setting up libapache2-mod-php (1:7.0+35ubuntu6) ...
  3. 多出的 Apache 模組設定 • afu@f2e-demo:/etc/apache2/mods-enabled$ ls -l | grep php

    • lrwxrwxrwx 1 root root 29 Apr 7 02:33 php7.0.conf -> ../mods-available/ php7.0.conf • lrwxrwxrwx 1 root root 29 Apr 7 02:33 php7.0.load -> ../mods-available/ php7.0.load
  4. php7.0.load 檔案內容 • afu@f2e-demo:/etc/apache2/mods-enabled$ cat php7.0.load • LoadModule php7_module /usr/lib/apache2/

    modules/libphp7.0.so • LoadModule 是 Apache 指令,表⽰示啟⽤用某個模組 • libphp7.0.so 是給 Apache ⽤用的 PHP 模組檔
  5. php7.0.conf 檔案內容 • <FilesMatch ".+\.ph(p[3457]?|t|tml)$"> • SetHandler application/x-httpd-php • </FilesMatch>

    • <FilesMatch ".+\.phps$"> • SetHandler application/x-httpd-php-source • # Deny access to raw php sources by default • # To re-enable it's recommended to enable access to the files • # only in specific virtual host or directory • Require all denied • </FilesMatch> • # Deny access to files without filename (e.g. '.php') • <FilesMatch "^\.ph(p[3457]?|t|tml|ps)$">
  6. 會裝這些套件 (~160 MB) The following NEW packages will be installed:

    libaio1 libcgi-fast-perl libcgi-pm-perl libencode-locale-perl libevent-core-2.0-5 libfcgi-perl libhtml-parser-perl libhtml-tagset-perl libhtml-template-perl libhttp-date-perl libhttp-message-perl libio-html-perl liblwp-mediatypes-perl libtimedate-perl liburi-perl mysql-client-5.7 mysql-client-core-5.7 mysql-common mysql-server mysql-server-5.7 mysql-server-core-5.7 0 upgraded, 21 newly installed, 0 to remove and 25 not upgraded. Need to get 19.0 MB of archives. After this operation, 162 MB of additional disk space will be used. Do you want to continue? [Y/n] y
  7. 透過互動式問答作更更安全的設定 sudo mysql_secure_installation 如果是正式營運的 DB server,應都回答 Y,或是另外⾃自⼰己操作亦可 * 更更改 root

    密碼 * 移除 MySQL 匿名使⽤用者 * 不允許 root 帳號透過遠端登入 (只能從 localhost 登入) * 移除測試資料庫 …
  8. MySQL Server status ? afu@f2e-demo:~$ sudo service mysql status •

    mysql.service - MySQL Community Server Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled) Active: active (running) since Fri 2017-04-07 02:56:26 CST; 5min ago Main PID: 12327 (mysqld) CGroup: /system.slice/mysql.service └─12327 /usr/sbin/mysqld
  9. 重開治百病 (?) afu@f2e-demo:~$ sudo service mysql restart * 重開會有 down

    time,以及 warm up 問題 甚⾄至可能開不起來來,謹慎操作!
  10. mysql client 參參數說明 mysql -h localhost -u root -p *

    沒給 -h 表⽰示連 localhost * 沒給 -u 表⽰示登入⽬目前的作業系統使⽤用者 (afu) * 如果不要換⾏行行等待⼈人⼯工輸入密碼,可以串串接在 -p 後⽅方 例例如 -p1234
  11. 抓 WordPress 原始碼 (正體中⽂文) • cd ~ • wget https://tw.wordpress.org/

    wordpress-4.7.3-zh_TW.zip • unzip wordpress-4.7.3-zh_TW.zip # 解壓縮 • 也可以⽤用瀏覽器下載,解壓縮後以慣⽤用⽅方式丟 到虛擬主機
  12. 複製⼀一份新的網站設定檔 • afu@f2e-demo:/etc/apache2/sites-enabled$ ls -l • lrwxrwxrwx 1 root root

    35 Feb 24 15:08 000- default.conf -> ../sites-available/000-default.conf • sudo cp 000-default.conf f2edemo.localhost.conf
  13. 讓筆電能識別測試網域 •因為世界上沒有 f2edemo.localhost 這個網 域 •透過修改筆電的 /etc/hosts,把 f2edemo.localhost 指向 Linode

    主機 IP, 使瀏覽器開此網域會導向 Linode IP •如果⾃自⼰己有購買網域,就無需此⾴頁步驟
  14. 從 Apache error log 找問題 • afu@f2e-demo:~$ sudo tail -f

    /var/log/apache2/error.log • [Fri Apr 07 03:37:23.157237 2017] [authz_core:error] [pid 14665] [client 36.224.197.156:56604] AH01630: client denied by server configuration: /home/afu/wordpress/ • [Fri Apr 07 03:37:24.007958 2017] [authz_core:error] [pid 14665] [client 36.224.197.156:56604] AH01630: client denied by server configuration: /home/afu/wordpress/favicon.ico, referer: http:// f2edemo.localhost/ • [Fri Apr 07 03:37:24.997800 2017] [authz_core:error] [pid 14665] [client 36.224.197.156:56604] AH01630: client denied by server configuration: /home/afu/wordpress/
  15. 編輯網站設定檔 
 f2edemo.localhost.conf <VirtualHost *:80> ServerName f2edemo.localhost DocumentRoot /home/afu/wordpress #

    <Directory> 順序不拘,只要包在 VirtualHost 裡⾯面即可 <Directory /home/afu/wordpress> Options FollowSymLinks # 允許捷徑⽬目錄 (例例如 afu/wordpress/share 在 /var/share) AllowOverride All # 允許⽤用 .htaccess 覆寫 Apache 設定 Require all granted # 允許存取 </Directory> </VirtualHost>
  16. 檢查缺漏 PHP 模組並補裝 • php -m | grep mysql #

    預期應有 mysql • sudo apt-get install php7.0-mysql # 安裝 php 連結 MySQL 的 extension • sudo apachectl restart # 重開 Apache
  17. 建立專⽤用資料庫與使⽤用者 mysql -u root -p CREATE DATABASE wordpress; CREATE USER

    'wpuser' IDENTIFIED BY 'wpuserpass'; GRANT ALL PRIVILEGES ON wordpress.* TO 'wpuser';