在Cubieboard 上安裝LAMP server

在Cubieboard 上安裝LAMP server (Linux, Apache, MySQL, PHP)

安裝MySQL

首先先更新一下套件資訊

server# aptitude update && aptitude upgrade

安裝MySQL套件, 在安裝過程中, 會要求你建立MySQL root 的密碼.

server# apt-get install mysql-server mysql-client

若沒有建立MySQL root 密碼, 也可以事後用下列指令來建立:

server# /usr/bin/mysqladmin -u root password 'enter-your-good-new-password-here'

安裝Apache2

安裝Apache套件

server# apt-get install apache2 apache2-doc

安裝PHP

安裝PHP套件

server# apt-get install php5 php5-mysql libapache2-mod-php5

乾脆順便安裝apache 的perl, python 套件好了

server# apt-get install perl libapache2-mod-perl2
server# apt-get install python libapache2-mod-python

讓使用者也可以在自己的Home Directory 建立網頁

啟用apach2 的 userdir 模組

server# a2enmod userdir

修改/etc/apache2/mods-enabled/userdir.conf 檔案如下, 請視自己需求而修改.

<IfModule mod_userdir.c>
        UserDir public_html
        UserDir disabled root

        <Directory /home/*/public_html>
                AllowOverride FileInfo AuthConfig Limit Indexes
                Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
                <Limit GET POST OPTIONS>
                        Order allow,deny
                        Allow from all
                </Limit>
                <LimitExcept GET POST OPTIONS>
                        Order deny,allow
                        Deny from all
                </LimitExcept>
        </Directory>
</IfModule>

然後在User的Home Directory 下建立publi_html 目錄(不需是root)

server$ mkdir /home/$USER/public_html

修改此目錄的group 為www-data (需要是root 才能做)

server# chgrp www-data /home/<username>/public_html

並且確定使用者的Home directory 權限必須是755, 不然apache 無法存取的public_html 目錄

server# chmod 755 /home/<username>

若要讓使用者也可以用php, 則修改/etc/apache2/mods-available/php5.conf, 把下列幾行給註解起來

#<IfModule mod_userdir.c>
#    <Directory /home/*/public_html>
#        php_admin_value engine Off
#    </Directory>
#</IfModule>

然後重新啟動apache即可

server# /etc/init.d/apache2 restart

安裝phpMyAdmin

server# apt-get install phpmyadmin

安裝期間, 他會問你目前使用http server的程式是Apache or 其他, 選Apache 就對了.

接下來他會問你MySql 的root 密碼.

再接下來他會問你要進入phpMyAdmin的密碼 (注意: 帳號名稱為phpmyadmin).

然後使用Browser 連線 http://your_ip/phpmyadmin 即可.

連進去後, 你可以使用MySQL 的root 帳密登入, 或者是phpmyadmin 的帳密登入.
MySql root 的帳號擁有全部權限, 但是phpmyadmin 帳號的權限有限制.

Apache, PHP, MySQL, phpMyAdmin 的設定檔

設定檔如下, 裡面有詳細說明, 請視情況修改其內容.

/etc/apache2/apache2.conf
/etc/php5/apache2/php.ini
/etc/mysql/my.cnf
/etc/phpmyadmin/apache.conf   (這個檔會被link到/etc/apache2/conf.d/phpmyadmin.conf)

在PHP 中使用MySQL

嗯…好像php default 就會使用mysql 了, 不需再額外設定

Apache Virtual Host 設定

在/etc/apache2/sites-available 目錄下建立virtual host 設定檔. 建議檔跟domain name 一樣. 比較好管理.
假設你的virtual host 的domain name 是www.myblog.idv.tw. 那麼設定檔名就是www.myblog.idv.tw
其內容如下:

<VirtualHost *:80>
        ServerAdmin  your-email@mail_addr.com     ### Your email address

        DocumentRoot /www/myblog/html             #### 存放網頁的目錄
        ServerName www.myblog.idv.tw              ### 你的virtual host 的domain name
        AddDefaultCharset UTF-8
        <Directory />
                Options FollowSymLinks
                AllowOverride All
        </Directory>
        <Directory /var/www/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                Order allow,deny
                allow from all
        </Directory>

        ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
        <Directory "/usr/lib/cgi-bin">
                AllowOverride None
                Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
                Order allow,deny
                Allow from all
        </Directory>

        ErrorLog /www/log/error.log                  ### Error 的記錄案

        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn

        CustomLog /www/log/access.log combined    ### Access 的記錄檔
</VirtualHost>

然後在/etc/apache2/sites-enable 目錄下建立上述檔案的link

server# cd /etc/apache2/sites-enable
server# ln -s ../www.myblog.idv.tw 100-www.myblog.idv.tw

這個link 的前3為數字好像沒啥作用, 我只是照著此目錄的習慣來做而已, 純粹好看.

啟用Apache額外的module

將要啟用的module 在/etc/apache2/modes-enable 建立link即可

例如我想啟用/etc/apapche2/rewrite.load 這個module, 只要如下設定並重新啟動apache

server# cd /etc/apache2/mods-enable
server# ln -s ../mods-available/rewrite.load rewrite.load
server# /etc/init.d/apache2 restart

參考資料

  1. LAMP, Linux Apache MySQL PHP
  2. VirtualHost Examples
This entry was posted in embedded system, 架站 and tagged , . Bookmark the permalink.

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *