差異處

這裏顯示兩個版本的差異處。

連向這個比對檢視

兩邊的前次修訂版 前次修改
tech:wordpress [2019/06/17 19:27] – [設定與驗證 nginx+php-fpm / mariadb] jonathan_tsaitech:wordpress [2019/07/22 17:41] (目前版本) – [評估外掛與相關資源] jonathan_tsai
行 1: 行 1:
 +====== CentOS7 安裝 WordPress 5 程序 ======
 +  * CentOS 7.6.1810 (Core)
 +  * Nginx 1.12.2
 +  * MariaDB 10.3.12
 +  * PHP 7.3.1
  
 +===== 安裝 Nginx / MariaDB / PHP 7 =====
 +  * EPEL <code sh>
 +yum install -y epel-release yum-utils
 +</code>
 +  * Remi 關閉 5.4 啟用 7.3<code sh>
 +rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
 +yum-config-manager --disable remi-php54
 +yum-config-manager --enable remi-php73
 +</code>
 +  * nginx <code sh>
 +vi /etc/yum.repos.d/nginx.repo</code><file>
 +[nginx]
 +name=nginx repo
 +baseurl=http://nginx.org/packages/centos/7/$basearch/
 +gpgcheck=0
 +enabled=1</file><code sh>
 +yum install -y nginx
 +</code>
 +  * php-fpm <code sh>
 +yum install -y php-fpm php
 +</code>
 +  * mariadb-server <code sh>
 +vi /etc/yum.repos.d/MariaDB.repo</code><file>
 +# MariaDB 10.3 CentOS repository list - created 2019-01-25 13:04 UTC
 +# http://downloads.mariadb.org/mariadb/repositories/
 +[mariadb]
 +name = MariaDB
 +baseurl = http://yum.mariadb.org/10.3/centos7-amd64
 +gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
 +gpgcheck=1
 +</file><code sh>
 +yum install -y MariaDB-server 
 +</code>
 +
 +===== 設定與驗證 nginx+php-fpm / mariadb =====
 +  * Firewall 開啟 http / https <code sh>
 +firewall-cmd --permanent --zone=public --add-service=http
 +firewall-cmd --permanent --zone=public --add-service=https
 +firewall-cmd --reload
 +</code>
 +  * 設定 nginx 開機啟動 <code sh>
 +systemctl restart nginx
 +systemctl enable nginx 
 +</code>
 +  * 設定主網站頁目錄 <code sh>
 +vi /etc/nginx/conf.d/default.conf
 +</code><file>
 +server {
 +    listen       80;
 +    server_name  localhost;
 +
 +    gzip on;
 +    gzip_comp_level    5;
 +    gzip_min_length    256;
 +    gzip_proxied       any;
 +    gzip_vary          on;
 +
 +    gzip_types
 +    application/atom+xml
 +    application/javascript
 +    application/json
 +    application/ld+json
 +    application/manifest+json
 +    application/rss+xml
 +    application/vnd.geo+json
 +    application/vnd.ms-fontobject
 +    application/x-font-ttf
 +    application/x-web-app-manifest+json
 +    application/xhtml+xml
 +    application/xml
 +    font/opentype
 +    image/bmp
 +    image/svg+xml
 +    image/x-icon
 +    text/cache-manifest
 +    text/css
 +    text/plain
 +    text/vcard
 +    text/vnd.rim.location.xloc
 +    text/vtt
 +    text/x-component
 +    text/x-cross-domain-policy;
 +    # text/html is always compressed by gzip module
 +
 +    location ~*  \.(jpg|jpeg|png|gif|ico|css|js|pdf)$ {
 +        expires 7d;
 +    }
 +
 +
 +    charset utf-8;
 +    access_log  /var/log/nginx/access.log  main;
 +
 +    root   /var/www/html;
 +    index  index.php index.html index.htm; 
 +
 +    location / {
 +        try_files $uri $uri/ =404;
 +    }
 +
 +    error_page  404              /404.html;
 +
 +    # redirect server error pages to the static page /50x.html
 +    #
 +    error_page   500 502 503 504  /50x.html;
 +    location = /50x.html {
 +        root   /usr/share/nginx/html;
 +    }
 +
 +    location ~ \.php$ {
 +        try_files $uri =404;
 +        fastcgi_pass 127.0.0.1:9000;
 +        fastcgi_index index.php;
 +        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
 +        include fastcgi_params;
 +    }
 +}
 +</file><code sh>
 +chcon -R -t httpd_sys_rw_content_t /usr/share/nginx/html
 +systemctl reload nginx
 +</code>
 +  * 修改 php 設定<code sh>
 +vi /etc/php.ini
 +</code><file>
 +:
 +;cgi.fix_pathinfo=1
 +cgi.fix_pathinfo=0
 +:
 +[Date]
 +:
 +date.timezone = Asia/Taipei
 +:
 +</file>
 +  * 修改 php-fpm 設定<code sh>
 +vi /etc/php-fpm.d/www.conf
 +</code><file>
 +:
 +; RPM: apache user chosen to provide access to the same directories as httpd
 +;user = apache
 +user = nginx
 +; RPM: Keep a group allowed to write in log dir.
 +;group = apache
 +group = nginx
 +:
 +:
 +; Default Values: user and group are set as the running user
 +;                 mode is set to 0660
 +listen.owner = nobody
 +listen.group = nobody
 +;listen.mode = 0660
 +:
 +</file><code sh>
 +systemctl restart php-fpm
 +systemctl enable php-fpm 
 +</code>
 +  * 啟動 MariaDB 與驗證新密碼<code sh>
 +systemctl restart mariadb
 +systemctl enable mariadb 
 +mysql_secure_installation
 +mysql -u root -p
 +</code>
 +  * 安裝其他 php 套件 <code sh>
 +yum install php-mysqlnd php-mbstring php-xmlrpc php-soap php-gd php-xml php-intl php-zip php-curl php-cli
 +systemctl restart php-fpm
 +systemctl restart nginx
 +</code>
 +
 +===== 下載最新版 Wordpress =====
 +  * 下載網址 : http://wordpress.org/download/
 +<code>
 +yum install wget unzip
 +cd /var/www/html/
 +wget http://wordpress.org/latest.zip
 +unzip latest.zip
 +chown -R nginx:nginx wordpress
 +</code>
 +
 +===== 開始基本設定 =====
 +  * 建立 wordpress db <code sh>
 +mysql -u root -p
 +</code><file>
 +create database `wordpress`;
 +create user 'wpadmin'@'localhost' identified by '**Password**';
 +grant all on wordpress.* to 'wpadmin'@'localhost';
 +flush privileges;
 +quit
 +</file>
 +  * 透過網頁安裝設定 wordpress : http://xxx.xxx.xxx/wordpress <-- 依據只是經過三個步驟就可以安裝完成
 +  * 使用 admin 與預設密碼(0adf3e 這樣的密碼) 登入, 先將預設密碼改成你要的密碼
 +
 +===== 設定固定網址 =====
 +  * /etc/nginx/conf.d/default.conf <file>
 +:
 +    index  index.php index.html index.htm;
 +
 +    location / {
 +        try_files $uri $uri/ /index.php?$args;
 +    }
 +
 +    error_page  404              /404.html;
 +:
 +</file>
 +  * 檢查設定檔與重啟 nginx<code sh>
 +nginx -t
 +systemctl restart nginx
 +</code>
 +
 +===== 設定特定 IP 可存取 wp-admin =====
 +  * Exp. 開放 10.x.x.x 以及 172.16.x.x 可以進入 wp-admin 管理介面
 +  * 編輯 /etc/nginx/conf.d/default.conf <file>
 +:
 +    location / {
 +        try_files $uri $uri/ /index.php?$args;
 +    }
 +
 +    location /wp-admin/ {
 +        allow 10.0.0.0/8;
 +        allow 172.16.0.0/16;
 +        deny all;
 +     }
 +
 +    location /wp-admin/admin-ajax.php {
 +       allow all;
 +    }
 +
 +    error_page  404              /404.html;
 +:
 +</file>
 +  * 重新啟動 nginx 讓設定生效<code sh>
 +systemctl restart nginx
 +</code>
 +
 +===== 評估外掛與相關資源 =====
 +  * CDN 整合
 +      * [[https://free.com.tw/cloudflare-wordpress-plugin/|Cloudflare 免費 WordPress 外掛教學,一鍵為網站快速套用最佳化設定]]
 +  * 數據統計
 +    * https://wp2static.com/
 +    * https://wordpress.org/plugins/wp-slimstat/
 +  * 網站測速
 +    * http://www.webkaka.com/UrlCheck.aspx
 +  * 網站優化
 +    * https://wordpress.org/plugins/autoptimize/
 +
 +  * plugin 參考文章
 +    * https://transbiz.com.tw/wordpress-plugin-%E6%8E%A8%E8%96%A6/
 +
 +<note>
 +  * 如果要更改網址 -> 參考 **[[tech/wordpress_move]]**
 +  * 如果要更改已經上傳的媒體(圖片, 檔案)檔名 -> 參考 **[[https://webcusp.com/how-to-easily-rename-uploaded-media-files-in-wordpress/|How to Easily Rename uploaded Media Files in WordPress]]**
 +</note>
 +
 +====== 參考網址 ======
 +  * http://blog.itist.tw/2016/01/installing-lemp-stack-with-centos-7-nginx-mariadb-php-7.html
 +  * https://computingforgeeks.com/how-to-install-php-7-3-on-centos-7-fedora/
 +  * https://codex.wordpress.org/Installing_WordPress#Famous_5-Minute_Installation
 +  * http://benjr.tw/96885
 +  * https://www.digitalocean.com/community/tutorials/how-to-increase-pagespeed-score-by-changing-your-nginx-configuration-on-ubuntu-16-04
 +
 +
 +{{tag>wordpress blog 安裝}}
  • tech/wordpress.txt
  • 上一次變更: 2019/07/22 17:41
  • jonathan_tsai