FreeNAS 上安裝 AMP 環境


(Photo by traaf)

所謂 AMP 環境就是有 Apache, Mysql, PHP 等常用的架網站的環境,照下面的作法,就可以在 FreeNAS 上架構一個網站。

作業系統版本:

FreeNAS 0.7.2 Sabanda (revision 5543)
核心 FreeBSD 7.3-RELEASE-p3
已預裝 lighthttpd
Joomla 1.5.22
php5-zlib 5.2.12 版本不符,改用 php5-zlib-5.3.5


安裝 PHP 5 環境 (quote: from here)

setenv PACKAGESITE ftp://ftp.freebsd.org/pub/FreeBSD/ports/i386/packages-7.2/ (ftp 網址有可能更動,可匿名登入 ftp 站查看新的目錄網址)

# pkg_add -r php5
# pkg_add -r php5-extensions
# pkg_add -r php5-xmlrpc
# pkg_add -r php5-gettext
# pkg_add -r php5-mcrypt
# pkg_add -r php5-mysql
# pkg_add -r php5-mbstring

以上為本機的 shell 介面安裝,但這些 packages (套件)也可以經由 freenas 的新增「套件」介面,將在 freebsd 官網上的套件下載到普通電腦再上傳至 freenas 的新增「套件」介面。可以先以匿名帳號登入:

ftp://ftp.freebsd.org/pub/FreeBSD/ports/i386/packages-7-stable/Latest/

抓取要安裝的套件再上傳至 freenas 的 web 介面安裝。

以上安裝完就可支援 phpMyAdmin 了。接下來不能進入 FreeNAS web 控制介面,就要利用下面指令修正:

# mv /usr/local/bin/php /usr/local/bin/php-cli
# cp /usr/local/bin/php-cgi /usr/local/bin/php

修正完成。

上傳 phpinfo.php 到 user 目錄,然後在本機上的 shell 介面

再修正時區的問題:

在 /usr/local/etc/php.ini 這個檔案中加入以下字。

[Date]
date.timezone = “Asia/Taipei"

這些字可以經由 sftp 下載 php.ini ,編輯後再上傳,利用 shell 功能在本機上下指令:

# cp /mnt/mounted-disk/users/username/php.ini /usr/local/etc/php.ini

我裝好的套件一覽:

gettext-0.18.1.1 GNU gettext package
libiconv-1.13.1_1 A character set conversion library
libltdl-2.2.10 System independent dlopen wrapper
libmcrypt-2.5.8 Multi-cipher cryptographic library (used in PHP)
libxml2-2.7.8_1 XML parser library for GNOME
mysql-client-5.0.90 Multithreaded SQL database (client)
mysql-server-5.0.90 Multithreaded SQL database (server)
oniguruma-4.7.1 A BSDL Regular Expressions library compatible with POSIX/GN
pcre-8.12 Perl Compatible Regular Expressions library
php5-5.3.5 PHP Scripting Language
php5-ctype-5.3.5 The ctype shared extension for php
php5-dom-5.3.5 The dom shared extension for php
php5-extensions-1.4 A “meta-port" to install PHP extensions
php5-filter-5.3.5 The filter shared extension for php
php5-gettext-5.3.5 The gettext shared extension for php
php5-hash-5.3.5 The hash shared extension for php
php5-iconv-5.3.5 The iconv shared extension for php
php5-json-5.3.5 The json shared extension for php
php5-mbstring-5.3.5 The mbstring shared extension for php
php5-mcrypt-5.3.5 The mcrypt shared extension for php
php5-mysql-5.3.5 The mysql shared extension for php
php5-pdo-5.3.5 The pdo shared extension for php
php5-pdo_sqlite-5.3.5 The pdo_sqlite shared extension for php
php5-posix-5.3.5 The posix shared extension for php
php5-session-5.3.5 The session shared extension for php
php5-simplexml-5.3.5 The simplexml shared extension for php
php5-sqlite-5.3.5 The sqlite shared extension for php
php5-tokenizer-5.3.5 The tokenizer shared extension for php
php5-xml-5.3.5 The xml shared extension for php
php5-xmlreader-5.3.5 The xmlreader shared extension for php
php5-xmlrpc-5.3.5 The xmlrpc shared extension for php
php5-xmlwriter-5.3.5 The xmlwriter shared extension for php
php5-zlib-5.3.5 The zlib shared extension for php
pkg-config-0.25_1 A utility to retrieve information about installed libraries
sqlite3-3.7.4 An SQL database engine in a C library

可加裝額外的套件,不裝亦可:

gettext-0.17_1 GNU gettext package
libiconv-1.11_1 A character set conversion library
libltdl-1.5.26 System independent dlopen wrapper
libmcrypt-2.5.8 Multi-cipher cryptographic library (used in PHP)
libxml2-2.7.3 XML parser library for GNOME
mysql-client-5.0.77_1 Multithreaded SQL database (client)
mysql-server-5.0.77_1 Multithreaded SQL database (server)
pcre-7.9 Perl Compatible Regular Expressions library
php5-5.2.9 PHP Scripting Language
php5-ctype-5.2.9 The ctype shared extension for php
php5-dom-5.2.9 The dom shared extension for php
php5-extensions-1.3 A “meta-port" to install PHP extensions
php5-filter-5.2.9 The filter shared extension for php
php5-gettext-5.2.9 The gettext shared extension for php
php5-hash-5.2.9 The hash shared extension for php
php5-iconv-5.2.9 The iconv shared extension for php
php5-json-5.2.9 The json shared extension for php
php5-mbstring-5.2.9 The mbstring shared extension for php
php5-mcrypt-5.2.9 The mcrypt shared extension for php
php5-mysql-5.2.9 The mysql shared extension for php
php5-pcre-5.2.9 The pcre shared extension for php
php5-pdo-5.2.9 The pdo shared extension for php
php5-pdo_sqlite-5.2.9 The pdo_sqlite shared extension for php
php5-posix-5.2.9 The posix shared extension for php
php5-session-5.2.9 The session shared extension for php
php5-simplexml-5.2.9 The simplexml shared extension for php
php5-spl-5.2.9 The spl shared extension for php
php5-sqlite-5.2.9 The sqlite shared extension for php
php5-tokenizer-5.2.9 The tokenizer shared extension for php
php5-xml-5.2.9 The xml shared extension for php
php5-xmlreader-5.2.9 The xmlreader shared extension for php
php5-xmlrpc-5.2.9 The xmlrpc shared extension for php
php5-xmlwriter-5.2.9 The xmlwriter shared extension for php
pkg-config-0.23_1 A utility to retrieve information about installed libraries

=====================
安裝 MySQL

* 在網頁管理介面上新增一 個 group 名稱為 mysql 。然後新增一 user 為 mysql 。

* 用 ssh 連到機器上,並作個檔案匣:

# mkdir /mnt/mounted-disk/db/mysql

FreeNAS 預設存放處為 /var/db/mysql ,但還沒有生成,建個連結:

# ln -s /mnt/mounted-disk/db/mysql /var/db/mysql

給所有權限給 user mysql 以及 group mysql 存取檔案匣 /mnt/mounted-disk/db/mysql 的權利:

# chown -R mysql:mysql /mnt/mounted-disk/db/mysql/

接下來:

# chmod 777 /tmp
# chmod 777 /var/tmp
# chmod 777 /ftmp

開始安裝 MySQL server:

# pkg_add -r mysql50-server

建立 db:

# /usr/local/bin/mysql_install_db(安装mysql)

接下來大概會看到這些字:

Installing MySQL system tables…
090819 11:18:58 [Warning] option ‘max_join_size’: unsigned value 18446744073709551615 adjusted to 4294967295
090819 11:18:58 [Warning] option ‘max_join_size’: unsigned value 18446744073709551615 adjusted to 4294967295
OK
Filling help tables…
090819 11:18:58 [Warning] option ‘max_join_size’: unsigned value 18446744073709551615 adjusted to 4294967295
090819 11:18:58 [Warning] option ‘max_join_size’: unsigned value 18446744073709551615 adjusted to 4294967295
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
/usr/local/bin/mysqladmin -u root password ‘new-password’
/usr/local/bin/mysqladmin -u root -h freenas.local password ‘new-password’

Alternatively you can run:
/usr/local/bin/mysql_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:
cd /usr/local ; /usr/local/bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl
cd mysql-test ; perl mysql-test-run.pl

Please report any problems with the /usr/local/bin/mysqlbug script!

The latest information about MySQL is available on the web at
http://www.mysql.com
Support MySQL by buying support/licenses at http://shop.mysql.com

接下來:

# chown -R mysql /var/db/mysql
# /usr/local/bin/mysqld_safe & (啟動 MYSQL)
# /usr/local/bin/mysqladmin -u root password 123456 (更改密碼123456為自己的密碼。)

為了要使 mysql 自動開機就啟用,要設定: mysql_enable="YES" 到 rc.conf 這個檔案, 使用網頁控制介面來作:選 System -> Advance -> rc.conf。

接下來按紅色「加」號,變數填 mysql_enable ,值 (value) 填 YES

接下來就「重新開機」。完成安裝 mysql 。

=====================
安裝 phpMyAdmin

# mkdir /mnt/mounted-disk/www
# cd /mnt/mounted-disk/www

接下來在 web 介面設定 /mnt/mounted-disk/www 為 www的預設檔案匣。

再去 phpmyadmin 網站下載最新的 phpMyAdmin 程式,利用 ftp 傳到 freenas 機器中,再用本機的 shell ,把 user 上傳的 phpmyadmin 檔案拷貝到 /mnt/mounted-disk/www 下)

解壓、並建立 symbolic links:

# tar -zxvf phpMyAdmin-3.2.1-english.tar.gz
(gz檔名不一定是這個名稱,要看你使用什麼語言,什麼版本。)
# ln -s /mnt/mounted-disk/www/phpMyAdmin-3.2.1-english/ /mnt/mounted-disk/www/phpMyAdmin
(檔案匣不一定是這個名稱,要看你使用什麼語言,什麼版本。)

安裝完成,接下來打 http://你的ip/phpMyAdmin/ 來作管理。

限制 phpMyAdmin 的存取範圍:

=====================
修正 「Notice: Undefined index: QUERY_STRING in ../libraries/joomla/environment/uri.php on line 161 」錯誤
在 joomla 程式 /environment/uri.php around line 161 改下面的字:

/*
* Since we do not have REQUEST_URI to work with, we will assume we
are
* running on IIS and will therefore need to work some magic with
the SCRIPT_NAME and
* QUERY_STRING environment variables.
*/

if (strlen($_SERVER['QUERY_STRING']) &&
strpos($_SERVER['REQUEST_URI'], $_SERVER['QUERY_STRING']) === false) {
$theURI .= '?'.$_SERVER['QUERY_STRING'];
}

}

改成:

/*
* Since we do not have REQUEST_URI to work with, we will assume we
are
* running on IIS and will therefore need to work some magic with
the SCRIPT_NAME and
* QUERY_STRING environment variables.
*/

if (isset($_SERVER['QUERY_STRING']) &&
strpos($_SERVER['REQUEST_URI'], $_SERVER['QUERY_STRING']) === false) {
$theURI .= '?'.$_SERVER['QUERY_STRING'];
}
}

就改 strlen 為 isset 即可 (參考)。

=====================
建立資料庫:

校對選 utf8_unicode_ci

=====================
修改 lighthttpd.conf

# cd /var/etc/lighthttpd.conf

加入 mod_rewrite 字串如:

server.modules = (
“mod_rewrite",

重啟 lighthttpd

# cd /etc/rc.d/
# ./lighthttpd restart

Advertisements

發表迴響

在下方填入你的資料或按右方圖示以社群網站登入:

WordPress.com Logo

您的留言將使用 WordPress.com 帳號。 登出 / 變更 )

Twitter picture

您的留言將使用 Twitter 帳號。 登出 / 變更 )

Facebook照片

您的留言將使用 Facebook 帳號。 登出 / 變更 )

Google+ photo

您的留言將使用 Google+ 帳號。 登出 / 變更 )

連結到 %s