Banana Pi 測試 – Gentoo Linux 安裝 LAMP Server

參考網頁:
Installing LAMP (Linux, Apache, MySQL, PHP and PhpMyAdmin) in Gentoo Linux
Installing Apache, MySQL, PHP in Gentoo Server | S V N Labs Softwares
LAMP Server on Gentoo – Linode Guides & Tutorials

同步套件庫
# emerge –sync

更新整個系統
# emerge –update world

安裝 Apache Web Server
# emerge apache[@more@]預設網頁根目錄 /var/www/localhost/htdocs/
底下更改成 /var/www/html
# cp /etc/apache2/vhosts.d/default_vhost.include /etc/apache2/vhosts.d/default_vhost.include.$(date +%F)
# sed -i ‘s|/var/www/localhost/htdocs|/var/www/html|’ /etc/apache2/vhosts.d/default_vhost.include
# mv /var/www/localhost/htdocs /var/www/html

cgi 目錄由 /var/www/localhost/cgi-bin 改成 /var/www/cgi-bin
# sed -i ‘s|/var/www/localhost/cgi-bin|/var/www/cgi-bin|’ /etc/apache2/vhosts.d/default_vhost.include
# sed -i ‘s|/var/www/localhost/cgi-bin|/var/www/cgi-bin|’ /etc/apache2/vhosts.d/00_default_ssl_vhost.conf

取消 Indexes 目錄顯示
# sed -i ‘s/Options Indexes/Options -Indexes/’ /etc/apache2/vhosts.d/default_vhost.include

將使用者網頁目錄由 public_html 改成 www
# sed -i ‘s/public_html/www/’ /etc/apache2/modules.d/00_mod_userdir.conf

增加網頁目錄中的 index 設定
# sed -i ‘s/DirectoryIndex index.html index.html.var/DirectoryIndex index.php index.html index.htm index.html.var/’ /etc/apache2/modules.d/00_default_settings.conf

取消 Deny from all 設定
# vim /etc/apache2/modules.d/00_default_settings.conf
<Directory />
Options FollowSymLinks
AllowOverride None
Order deny,allow
# Deny from all
</Directory>

ServerSignature On 改成 ServerSignature Off
# sed -i ‘s/ServerSignature On/ServerSignature Off/’ /etc/apache2/modules.d/00_default_settings.conf

啟動 Apache Web Server,如果出現下面的訊息
# /etc/init.d/apache2 start
* Starting apache2 …
apache2: apr_sockaddr_info_get() failed for lemaker
* start-stop-daemon: failed to start `/usr/sbin/apache2′ [ !! ]
* ERROR: apache2 failed to start

請在 /etc/hosts 加入一行
# vim /etc/hosts
127.0.0.1 lemaker

設定開機時啟動 Apache Web Servr
# rc-update add apache2 default

安裝 MySQL Server
# emerge dev-db/mysql

啟動 MySQL Server
# /etc/init.d/mysql start
  * Checking mysqld configuration for mysql …                                                               [ ok ]
 * Starting mysql …
 * You don’t appear to have the mysql database installed yet.
 * Please run `emerge –config =dev-db/mysql-5.5.40` to have this done…
 * ERROR: mysql failed to start

如果出上面的錯誤訊息
# emerge –config =dev-db/mysql-5.5.40

Configuring pkg…

 * Please provide a password for the mysql ‘root’ user now, in the
 * MYSQL_ROOT_PASSWORD env var or through the /root/.my.cnf file.
 * Avoid [“‘_%] characters in the password
    >(輸入您要設定的 MySQL Server 密碼)
 * Retype the password
    >(再次輸入您要設定的 MySQL Server 密碼)
 * Creating the mysql database and setting proper
 * permissions on it …
 * Command: ‘/usr/share/mysql/scripts/mysql_install_db’ ‘–basedir=/usr’  –loose-skip-grant-tables –loose-skip-host-cache –loose-skip-name-resolve –loose-skip-networking –loose-skip-slave-start –loose-skip-ssl –loose-skip-log-bin –loose-skip-relay-log –loose-skip-slow-query-log –loose-skip-external-locking –loose-skip-log-slave-updates –user=mysql –loose-skip-innodb ‘–datadir=///var/lib/mysql’ ‘–tmpdir=///tmp/’
 * Starting mysqld …
 * Command //usr/sbin/mysqld             –loose-skip-grant-tables –loose-skip-host-cache –loose-skip-name-resolve –loose-skip-networking –loose-skip-slave-start –loose-skip-ssl –loose-skip-log-bin –loose-skip-relay-log –loose-skip-slow-query-log –loose-skip-external-locking –loose-skip-log-slave-updates –user=mysql –loose-skip-innodb             –user=mysql            –log-warnings=0                –basedir=//usr                 –datadir=///var/lib/mysql                 –max_allowed_packet=8M                 –net_buffer_length=16K                 –default-storage-engine=MyISAM            –socket=//var/run/mysqld/mysqld16101.sock              –pid-file=//var/run/mysqld/mysqld20041.pid
 *              –tmpdir=///tmp/                                                                             [ ok ]
 * Setting root password …                                                                                [ ok ]
 * Loading “zoneinfo”, this step may require a few seconds … …                                          [ ok ]
 * Stopping the server …
 * Done

MySQL Server 的一些安全性設定
# /usr/bin/mysql_secure_installation

設定開機時啟動 MySQL Server
# rc-update add mysql default

MySQL Server 設定檔
/etc/mysql/my.cnf

安裝 PHP
# USE=”apache2 mysql mysqli php cli cgi pam ssl xml xml2 berkdb innodb jpeg png pcre session unicode” emerge ‘dev-lang/php’

# vim /etc/conf.d/apache2
APACHE2_OPTS=”-D DEFAULT_VHOST -D INFO -D SSL -D SSL_DEFAULT_VHOST -D LANGUAGE -D PHP5″

PHP 設定檔
/etc/php/apache2-php5.5/php.ini

PHP 一些設定
# sed -i ‘s/allow_url_fopen = On/allow_url_fopen = Off/’ /etc/php/apache2-php5.5/php.ini
# sed -i ‘s/expose_php = On/expose_php = Off/’ /etc/php/apache2-php5.5/php.ini
# sed -i ‘s/upload_max_filesize = 2M/upload_max_filesize = 500M/’ /etc/php/apache2-php5.5/php.ini
# sed -i ‘s/post_max_size = 8M/post_max_size = 500M/’ /etc/php/apache2-php5.5/php.ini
# sed -i ‘s/session.cookie_httponly =/session.cookie_httponly = 1/’ /etc/php/apache2-php5.5/php.ini
# sed -i ‘s/;date.timezone =/date.timezone = Asia/Taipei/’ /etc/php/apache2-php5.5/php.ini
# sed -i ‘s/max_execution_time = 30/max_execution_time = 300/’ /etc/php/apache2-php5.5/php.ini
# sed -i ‘s/max_input_time = 60/max_input_time = 600/’ /etc/php/apache2-php5.5/php.ini

重新啟動 apache Web Server
# /etc/init.d/apache2 restart