2016年5月18日 星期三

第8章WordPress

8WordPress




8-1 簡介
8-2 安裝
8-3 新增別名、資料庫
8-3-1新增別名
8-3-2新增資料庫
8-4 網頁登入
8-4-1網頁安裝步驟
8-4-2首次登入
8-4-3LDAP登入設定
8-5 LDAP用戶登入
8-6參考文獻


8-1 簡介

  WordPress 是一套 PHP 開發的個人部落格 (Blog) 的系統,它強調網頁標準,美觀及可用性,使用者可以很方便的在管理平台上撰寫文章,並快速變更部落格的佈置主題、語言及其他設定。

  部落格作者可以建立密碼來保護文章,因此該文章只讓擁有密碼的讀者閱讀。除此之外還有很多的外掛模組來增強 WordPress 的功能,讓作者在寫作部落格時更加方便。

8-2 安裝

方式一:(使用ports
# cd /usr/ports/www/wordpress
# make config ; make install clean

方式二:(使用 pkg
# pkg install WordPress

‧略‧
New packages to be INSTALLED:
        wordpress: 4.5.2,1
        php56-curl: 5.6.21
        curl: 7.48.0_1
        php56-ftp: 5.6.21
‧略‧
Proceed with this action? [y/N]: y
‧略‧
Before the first use of WordPress, copy wp-config-sample.php to wp-config.php
in /usr/local/www/wordpress and modify it to fit your MySQL.
Maybe you need 'mysqladmin create wordpress' first.
If you are upgrading from 1.x or 2.x or 3.x to 4.x, please run
http://your.site/wordpress/wp-admin/upgrade.php to upgrade to WordPress 4.x
#

方式三:(下載 .zip 或 .tar.gz)至 /tmp 資料夾
root@f40:/tmp # unzip wordpress-4.5.2-zh_TW.zip

# mv wordpress /usr/local/www/

8-3 組態設定、調整、新增資料庫

8-3-1 新增別名
# ee /usr/local/etc/apache24/Includes/wordpress.conf

Alias /wordpress/ "/usr/local/www/wordpress/"
 <Directory "/usr/local/www/wordpress/">
    Options none
    AllowOverride none

    Require all granted
 </Directory>

# /usr/local/etc/rc.d/apache24 restart

8-3-2 新增資料庫
# mysql -u root -p
mysql> create database wordpress;
mysql> grant all on wordpress.* to wordpress@localhost identified by '********';
mysql> quit

8-4 網頁登入(中文化調整、LDAP登入設定)

8-4-1網頁安裝步驟

登入:
https://f40.testbsd.com/wordpress/

首次登入,尚無設定檔,會自動轉至下列網址:
https://f40.testbsd.com/wordpress/wp-admin/setup-config.php


【圖8-4-1-1

輸入資料庫等相關資訊
【圖8-4-1-2
完成的系統組態檔案,須手動新增wordpress/wp-config.php並貼上設定黨內容
【圖8-4-1-3

# ee /usr/local/www/wordpress/wp-config.php

<?php
/**
 * WordPress 基本設定檔。
 *
 * 本檔案包含以下設定選項: MySQL 設定、資料表前綴、
 * 私密金鑰、WordPress 語言設定以及 ABSPATH。如需更多資訊,請
 * 前往 {@link http://codex.wordpress.org/Editing_wp-config.php 編輯
 * wp-config.php} Codex 頁面。或者向您的空間提供商諮詢關於 MySQL 設定資訊。
 *
 * 這個檔案用於安裝程式自動生成 wp-config.php 設定檔。
 * 您不需要將它用於您的網站,可以手動複製這個檔案,
 * 並重新命名為 "wp-config.php",然後輸入相關訊息。
 *
‧略‧

【圖8-4-1-4

完成設定
【圖8-4-1-5
8-4-2首次登入
使用admin登入
【圖8-4-2-1

【圖8-4-2-2
8-4-3LDAP登入設定

由於WordPress內建,並沒有LDAP認證模組,所以需要另外下載

下載網址一:
https://wordpress.org/plugins/wpdirauth/other_notes/

下載網址二:
http://w2.testbsd.com:8080/WordPressLdap/wpdirauth.1.7.15.zip

將下載的wpdirauth.1.7.15.zip複製到本機 /tmp
搬移並解壓縮到 /usr/local/www/wordpress/wp-content/plugins/
# mv /tmp/wpdirauth.1.7.15.zip /usr/local/www/wordpress/wp-content/plugins/
# cd /usr/local/www/wordpress/wp-content/plugins/
# unzip wpdirauth.1.7.15.zip
# ls /usr/local/www/wordpress/wp-content/plugins/
akismet         hello.php       index.php       wpdirauth

再次登入網頁,點選外掛模組
【圖8-4-3-1
發現多了LDAP 認證選項,請勾選,並執行
【圖8-4-3-2
再次回到帳號管理,發現多了認證選項
【圖8-4-3-3

【圖8-4-3-4


【圖8-4-3-5


【圖8-4-3-6

8-5 LDAP用戶登入
【圖8-5-1
【圖8-5-2

【圖8-5-3

登入成功,自動帶出160601這個帳號在OpenLdap內的資訊,供使用者確認。

【圖8-5-4

如下圖,再次由admin登入,選擇[全部帳號],可以看到目前已經加入的用戶。
【圖8-5-5

8-6 參考文獻
http://wordpress.org/
https://tw.wordpress.org/
https://zh-tw.wordpress.com/create/


2016年5月11日 星期三

安裝phpLdapAdmin

3-3 安裝phpLdapAdmin

# pkg install phpldapadmin

安裝結果
.略.
New packages to be INSTALLED:
        phpldapadmin: 1.2.3_7,1
        php56-gettext: 5.6.21
.略.
phpldapadmin-1.2.3_7,1 has been installed into:       // 顯示安裝路徑
    /usr/local/www/phpldapadmin
Please edit config.php to suit your needs.
To make phpLDAPadmin available through your web site, I suggest that
you add something like the following to httpd.conf:      // 提示新增別名

    Alias /phpldapadmin/ "/usr/local/www/phpldapadmin/htdocs/"
    <Directory "/usr/local/www/phpldapadmin/htdocs">
        Options none
        AllowOverride none

        Order Deny,Allow
        Deny from all
        Allow from 127.0.0.1 .example.com
    </Directory>

新增別名,別名的用意是可以使用 http:
# ee /usr/local/etc/apache24/Includes/phpldapadmin.conf

基於安全考量,筆者不建議phpLdapAdmin的網頁,開放給外部,所以設定如下
Alias /phpldapadmin/ "/usr/local/www/phpldapadmin/htdocs/"
<Directory "/usr/local/www/phpldapadmin/htdocs/">
        Options None
        AllowOverride None

        Require host a6j a6j.testbsd.com
</Directory>

重新啟動Apache,會重新載入/usr/local/etc/apache24/Includes/*.conf
# service apache24 restart

確認執行無誤
Performing sanity check on apache24 configuration:
Syntax OK
Stopping apache24.
Waiting for PIDS: 8781.
Performing sanity check on apache24 configuration:
Syntax OK
Starting apache24.



登入網頁,已經能透過Unbound解析域名,是不是感覺很好呢?

【圖3-3-1

安裝OpenLdap

3-2 安裝OpenLdap

  SSO的建置,可以讓使用者,使用單一帳號登入許多的網頁。

3-2-1 安裝openldap-server
# pkg install openldap-server

安裝過程,會顯示版本號、檔案大小、應調整的組態設定、開機啟動設定等資訊。
Updating FreeBSD repository catalogue...
Fetching meta.txz: 100%    940 B   0.9kB/s    00:01
Fetching packagesite.txz: 100%    5 MiB   2.8MB/s    00:02
Processing entries: 100%
FreeBSD repository update completed. 25130 packages processed.
The following 1 package(s) will be affected (of 0 checked):

New packages to be INSTALLED:
        openldap-server: 2.4.44
.略.
************************************************************
The OpenLDAP server package has been successfully installed.

In order to run the LDAP server, you need to edit
  /usr/local/etc/openldap/slapd.conf
to suit your needs and add the following lines to /etc/rc.conf:
  slapd_enable="YES"
  slapd_flags='-h "ldapi://%2fvar%2frun%2fopenldap%2fldapi/ ldap://0.0.0.0/"'
  slapd_sockets="/var/run/openldap/ldapi"

Then start the server with
  /usr/local/etc/rc.d/slapd start
or reboot.

Try `man slapd' and the online manual at
  http://www.OpenLDAP.org/doc/
for more information.

slapd runs under a non-privileged user id (by default `ldap'),
see /usr/local/etc/rc.d/slapd for more information.

新增開機時自動啟動slapd服務
# echo 'slapd_enable="YES"' >> /etc/rc.conf

回想:目前為止,已經有三種方式,可以寫入/etc/rc.conf

3-2-2 設定slapd.conf

  前置作業,先產生加密的rootpw密碼,rootpw OpenLDAP 管理員密碼,預設密碼是secret很不安全,建議修改,執行slappasswd指令可產生一組加密後的密碼,讀者可以將產生加密後的結果,貼到slapd.conf裡面。
# lappasswd

New password: ********
Re-enter new password: ********
{SSHA}b2CEwIudAjt6jsjz8yPxLyL1ToHMu6dI

修改設定檔 slapd.conf
# ee /usr/local/etc/openldap/slapd.conf

新增/修改:
(~5)
include         /usr/local/etc/openldap/schema/core.schema
include         /usr/local/etc/openldap/schema/cosine.schema
include         /usr/local/etc/openldap/schema/nis.schema
include         /usr/local/etc/openldap/schema/inetorgperson.schema
include         /usr/local/etc/openldap/schema/collective.schema
include         /usr/local/etc/openldap/schema/corba.schema
include         /usr/local/etc/openldap/schema/duaconf.schema
include         /usr/local/etc/openldap/schema/dyngroup.schema
include         /usr/local/etc/openldap/schema/java.schema
include         /usr/local/etc/openldap/schema/misc.schema
include         /usr/local/etc/openldap/schema/openldap.schema
include         /usr/local/etc/openldap/schema/pmi.schema
include         /usr/local/etc/openldap/schema/ppolicy.schema
(~16)
moduleload    back_mdb
(~47)
access to attrs=userPassword
        by self write
        by anonymous auth
        by * none

access to *
        by self write
        by users read
        by peername.ip=127.0.0.1 read
        by anonymous auth
(~54)
suffix           "dc=testbsd,dc=com"
rootdn          "cn=Manager,dc=testbsd,dc=com"
(~59)
rootdn          {SSHA}b2CEwIudAjt6jsjz8yPxLyL1ToHMu6dI

設定 openldap-client 的部份
# ee /usr/local/etc/openldap/ldap.conf

修改內容
(~11)
BASE dc=testbsd,dc=com
URI ldap://127.0.0.1

啟動:# service slapd start (或者下列指令也可以)
# /usr/local/etc/rc.d/slapd start

結果
Starting slapd.

3-2-3 設定第一個Domain

# mkdir /usr/local/etc/openldap/data
# cd /usr/local/etc/openldap/data

新增一個檔domainmgr.ldif
# ee domainmgr.ldif

內容如下,讀者可依照自己的網域名稱輸入
# Create Domain entry
dn: dc=testbsd,dc=com
objectclass: dcObject
objectclass: organization
o: testbsd.com
dc: testbsd

# Create Manager entry
dn: cn=Manager,dc=testbsd,dc=com
objectclass: organizationalRole
cn: Manager

執行ldapadd新增網域至ldapdb
# ldapadd -x -D "cn=Manager,dc=testbsd,dc=com" -W -f domainmgr.ldif -c

執行ldapadd會詢問rootpw的密碼,也就是Manager的密碼。
Enter LDAP Password: ********
adding new entry "dc=testbsd,dc=com"
adding new entry "cn=Manager,dc=testbsd,dc=com"


  此時,已經完成了在OpenLdap內新增一個網域:testbsd.com,接著如何用最輕鬆的方式,建立公司內部的組織、群組?讓我們繼續看下去~