安裝環境:
Linode 的 CentOS 6.2 64bit Profile (Latest 3.4 (3.4.2-x86_64-linode25))
◎ 安裝 Apache, PHP, MySQL
# yum install httpd php mysql-server php-devel php-mysql php-mbstring php-gd
設定 Apache 服務隨系統一起啟動
# chkconfig httpd on
確認 Apache 自動啟動有打開
# chkconfig --list httpd httpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
確認2--5要為on
啟動 httpd
# service httpd start
利用 phpinfo() 檢查看看 httpd 與 php 是否正常
# vim /var/www/html/test_httpd.php
建立一個php網頁檔,內容輸入:
<?php phpinfo(); ?>
打開瀏覽器,網址輸入 http://(server的ip位址)/test_httpd.php
可以看到 PHP 版本為 5.3.3、Apache 版本為 2.2.15
◎ 修改apache設定檔
# vim /etc/httpd/conf/httpd.conf
Timeout 120
# 不論接收或傳送,當持續連線等待超過 120 秒則該次連線就中斷。
# 一般來說,此數值在 300 秒左右即可
# 設定保持持續連線
KeepAlive Off #改為 On
MaxKeepAliveRequests 100 #設為0即無限制
# prefork預設值
<IfModule prefork.c> StartServers 8 MinSpareServers 5 MaxSpareServers 20 ServerLimit 256 MaxClients 256 MaxRequestsPerChild 4000 </IfModule>
# 依server的等級調整數字,我是修改為
<IfModule prefork.c> ServerLimit 1000 StartServers 8 MinSpareServers 10 MaxSpareServers 64 MaxClients 1000 MaxRequestsPerChild 10000 </IfModule>
# ServerLimit要放在第一項才有用 http://www.lslnet.com/linux/f/docs1/i44/big5305295.htm
# apache程序的使用者與群組
User apache
Group apache
#ServerName www.example.com:80 改為 server的IP位址:80
ServerName xxx.xxx.xxx.xxx:80
#網頁根目錄預設存放的地方
DocumentRoot "/var/www/html"
DirectoryIndex #要再加上 index.htm 至於 index.php 在 conf.d/php.conf 裡會加
# 下面這些沒在用 cgi 可以註解掉
# ScriptAlias /cgi-bin/ "/var/www/cgi-bin/" #<Directory "/var/www/cgi-bin"> # AllowOverride None # Options None # Order allow,deny # Allow from all #</Directory>
# AddLanguage 留英文與繁體中文就好
AddLanguage en .en AddLanguage zh-TW .zh-tw LanguagePriority en zh-TW
#下面這些沒在用可以註解掉
#AddHandler type-map var #AddType text/html .shtml #AddOutputFilter INCLUDES .shtml #BrowserMatch "Mozilla/2" nokeepalive #BrowserMatch "MSIE 4\.0b2;" nokeepalive downgrade-1.0 force-response-1.0 #BrowserMatch "RealPlayer 4\.0" force-response-1.0 #BrowserMatch "Java/1\.0" force-response-1.0 #BrowserMatch "JDK/1\.0" force-response-1.0 #BrowserMatch "Microsoft Data Access Internet Publishing Provider" redirect-carefully #BrowserMatch "MS FrontPage" redirect-carefully #BrowserMatch "^WebDrive" redirect-carefully #BrowserMatch "^WebDAVFS/1.[0123]" redirect-carefully #BrowserMatch "^gnome-vfs/1.0" redirect-carefully #BrowserMatch "^XML Spy" redirect-carefully #BrowserMatch "^Dreamweaver-WebDAV-SCM1" redirect-carefully
重新啟動 apache
# service httpd restart
◎ 修改 /etc/php.ini
# vim /etc/php.ini
;是否要使用像這種 <?=$foo?> 的簡寫符號
short_open_tag = Off
;這個可以調大點,設成40960
output_buffering = 4096
;記憶體用量限制
memory_limit = 128M
;不顯示error,而是記錄在 /var/log/httpd/error_log
display_errors = Off
log_errors = On
ignore_repeated_errors = On
ignore_repeated_source = On
;設定時區
date.timezone = Asia/Taipei
; cookie存活時間(秒),設為0的話瀏覽器關掉即到期
session.cookie_lifetime = 3600
; session存活時間
session.gc_maxlifetime = 3600
◎ 設定 MySQL
初次啟動
# service mysqld start
修改root密碼
# mysqladmin -u root password 'your.password'
登入看看
#mysql -u root -p
離開
mysql> exit
設定 MySQL 服務隨系統一起啟動
# chkconfig mysqld on
確認 MySQL 自動啟動有打開
# chkconfig --list mysqld mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off
2-5要為on
● 安裝 phpMyAdmin
到 http://www.phpmyadmin.net/ 下載新版的 phpMyAdmin
解壓縮到 /var/www/html/phpMyAdmin 之下
# cd /var/www/html # wget http://downloads.sourceforge.net/project/phpmyadmin/phpMyAdmin/x.x.x/phpMyAdmin-x.x.x-all-languages.tar.gz?use_mirror=ncu # tar -xzvf phpMyAdmin_x.x.x-all-languages.tar.gz # mv phpMyAdmin_x.x.x-all-languages phpMyAdmin # cd /var/www/html/phpMyAdmin # cp config.sample.inc.php config.inc.php # vim config.inc.php
將 $cfg['Servers'][$i]['auth_type'] = 'cookie';
改為 $cfg['Servers'][$i]['auth_type'] = 'http';
打開瀏覽器,輸入網址
http://(ip位址)/phpMyAdmin
帳號密碼輸入 MySQL 的 root/密碼
出現:缺少 mcrypt 外掛。請檢查 PHP 設定
安裝 EPEL (Extra Packages for Enterprise Linux) 套件庫
先到 http://download.fedoraproject.org/pub/epel/6/x86_64/
尋找新的 epel-release-x-x.noarch.rpm 複製連結
# rpm -ivh http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-x-x.noarch.rpm
更新套件庫
# yum update
接著就可以安裝 php-mcrypt 了
# yum install php-mcrypt