CentOS 5 安裝 LAMP (AMP) 環境

名稱定義:

LAMP= Linux + Apache + MySQL + PHP

AMP= Apache + MySQL + PHP

Apache 部分:

安裝:

yum -y install httpd mod_ssl

改設定:

cp /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf.bak

vi /etc/httpd/conf/httpd.conf

250行 ServerAdmin root@localhost

390行 DirectoryIndex index.html index.html.var 修改成--> DirectoryIndex index.html index.htm index.php index.html.var

730行 LanguagePriority zh-TW en ca cs da de el eo es et fr he hr it ja ko ltz nl nn no pl pt pt-BR ru sv zh-CN

Listen 80

#Listen ip.version.4.ip:80

#Listen [ip::v6]:80

加入一行:

ServerName localhost

開啟 httpd 服務:

/etc/rc.d/init.d/httpd start

chkconfig httpd on

若出現 bash: service: command not found 或 bash: chkconfig: command not found :

先下指令

su - root //回覆密碼後,再下相關指令。

參考:

PHP 部分:

安裝:

yum -y install php mysql mysql-server php-mysql php-gd php-mbstring

改設定:

cp /etc/php.ini /etc/php.ini.bak

vi /etc/php.ini

312行 max_execution_time = 300

313行 max_input_time = 600

314行 memory_limit = 160M

477行 post_max_size = 80M

582行 upload_max_filesize = 20M

[Date]

date.timezone = "Asia/Taipei"

short_open_tag = On

#short_open_tag = On 設此項是為了解決 php 檔在網上執行後出現空白的現象,原因是因為 short_open_tag 設定為 Off 導致無法解譯 <? 及結尾的 ?> 這兩個 tag。

#上面設定值,請視自己需求修改

重啟 httpd:

service httpd restart

測試 php 是否正常:

<?

phpinfo();

?>

MySQL 部分:

啟動 MySQL:

/etc/rc.d/init.d/mysqld start

chkconfig mysqld on

如何重新安裝 MySQL?

service mysqld stop

yum -y remove mysql

rm -rf /var/lib/mysql

yum -y install php mysql mysql-server php-mysql php-gd

service mysqld start

不使用 phpmyadmin 功能,直接用命令列來設定密碼:

mysqladmin -u root password '密碼'

安裝 phpMyAdmin 部分:

修改 config.inc.php (先 cp /phpmyadmin/config.sample.inc.php /phpmyadmin/config.inc.php)

/* Authentication type */

$cfg['Servers'][$i]['auth_type'] = 'http';

/* Server parameters */

$cfg['Servers'][$i]['host'] = 'localhost';

/* Added by James */

$cfg['PmaAbsoluteUri'] = 'http://yourip/phpmyadmin/';

/* Added by James */

$cfg['Servers'][$i]['connect_type'] = 'tcp';

$cfg['Servers'][$i]['compress'] = false;

/* Select mysqli if your server has it */

$cfg['Servers'][$i]['extension'] = 'mysql';

$cfg['Servers'][$i]['AllowNoPassword'] = false;

查看 SELinux 狀態:

sestatus  //看狀態

getsebool -a  //看開啟監視的服務有哪些

setenforce 0 //暫時關閉 SELinux

setenforce 1 //打開 SELinux

/var/log/messages 最底下會有最新的 SELinux log 資訊,可用 tail 指令來檢視此檔案。

在 /var/www/html/  下面下指令: ls -Z 來看 phpmyadmin 目錄是否為 httpd_sys_content_t ,不是的話 phpmyadmin 網頁就會被阻檔而產生 403 錯誤。

chcon -R -u -t httpd_sys_content_t /var/www/html/phpmyadmin

============================

完全關閉 SELinux 功能:

vi /etc/sysconfig/selinux

內容:

SELINUX=enforcing 改成--> SELINUX=disabled

重新開機。

出現 403 問題解法(引用自《Apache under SELinux - 讓Apache跑得順起來! 》:

phpmyadmin在非默認/var/www/html目錄下無法運轉 通常類似的情況都是在配置了虛擬主機時,訪問/phpmyadmin等提示403訪問拒絕,日誌裡也提示Permission denied,這是因為phpmyadmin防止的目錄及文件本身屬性不符合context要求。  假設phpmyadmin放在/web目錄下,那麼執行:  chcon -R -t httpd_user_content_t /web  則會令/web及其下所有子目錄/文件,包括phpmyadmin文件都獲得了httpd_user_content_t的屬性,如果其傳統的Unix屬性對httpd來說是可讀的話,再重新訪問一下就應該可以了。

我的解法:

chcon -R -t httpd_sys_content_t /var/www/html/phpmyadmin

//SELinux 指令 chcon -R (recursive)

//SELinux 指令 chcon -R -u username -r role -t type filename (其中 username, role, type 自訂,一般而言,用 ls -Z 這個指令就可以看到檔案的 SELinux 的角色設定值,排列為 username:role:type filename)

解決 phpmyadmin 3.4.1 不能在 PHP 5.1.6 版本上運行的問題(升級 PHP 5.1.6 為 5.2.10 版本):

 參考 HowTos     PHP 5.1 To 5.2

# touch /etc/yum.repos.d/CentOS-Testing.repo

# vi /etc/yum.repos.d/CentOS-Testing.repo

寫這檔案 /etc/yum.repos.d/CentOS-Testing.repo 的內容為:

[c5-testing] name=CentOS-5 Testing baseurl=http://dev.centos.org/centos/$releasever/testing/$basearch/ enabled=1 gpgcheck=1 gpgkey=http://dev.centos.org/centos/RPM-GPG-KEY-CentOS-testing includepkgs=php*

存檔後執行:

# rpm -qa |grep php

# yum update

//然後按 y 就可以開始升級 php 相關的套件。

# service httpd restart

# php -v //查看 php 版本是否升級成功。

參考:

PHP 5.2.10 版本升級為 5.3.6 (參考:Linux CentOS 5 Server: YUM Repository to Install Zend Optimizer ):

//其實原本是想安裝 Zend Optimizer 但 php 5.2 版本不給裝,後來執行以下步驟套件管理員就自行把 php 升級為 5.3 版本了。

# cd /root/

# wget -q -O - http://www.atomicorp.com/installers/atomic.sh | sh

//上面會自行下載 atomic.sh 並且執行,在 /etc/yum.repos.d/ 多了一個檔案 atomic.repo。

# yum install php-zend-optimizer

//執行完會出現錯誤訊息。回到桌面圖形環境就可以看到有 php 套件更新的訊息 8 則了,按全部安裝,安裝完以下面命令看安裝新版本是否成功。

# php -v

PHP 5.3.6 (cli) (built : Apr 19 2011 12:28:40)

Copyright (c) 1997-2011 The PHP Group

Zend Engine v.2.3.0 Copyright (c) 1998-2011 Zend Technologies

# yum install php-zend-optimizer

//PHP 升級為 5.3.6 後再安裝一次 Zend Optimizer。此時還是發生套件不相容的錯誤。

//搞半天,原來 Zend Optimizer 只支援到 php 5.2 以前的版本,php 5.3以後要改用 php-zend-gard-loader 這個套件。

# yum install php-zend-guard-loader

//按 y 確認安裝後,就可安裝成功。

# php -v

# php -m

//以上兩個指令若都能看到 Zend Guard Loader 字樣代表安裝成功。

#cd /root

#rpm -ivh http://repo.webtatic.com/yum/centos/5/`uname  -i`/webtatic-release-5-0.noarch.rpm

 

安裝PHP

#yum --enablerepo=webtatic install php

升級PHP

#yum --enablerepo=webtatic update php

 

如果不能安裝或升級時,請改用下列指令

#yum --disablerepo=* --enablerepo=webtatic update php

 

下列指令也是安裝php,但指定不要5.3.x版的 

#yum --disablerepo=* --enablerepo=webtatic --exclude=php*5.3* install php  

PHP 5.1.6 版本升級為 5.4.21 , mysql 升級為 5.5.34

注意不要裝來源不明的 repo。不要裝 devel 的版本。

http://linux.vbird.org/linux_server/0360apache.php#user_group_httpd.conf

# 安裝必要的 LAMP 軟體: php-devel 可以先忽略。

[root@www ~]# yum install httpd mysql mysql-server php php-mysql

http://blog.faq-book.com/?p=6777

rpm -Uvh http://dl.fedoraproject.org/pub/epel/5/x86_64/epel-release-5-4.noarch.rpm

rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-5.rpm

把 remi.repo 內的 enabled=0 改為enabled=1

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

[root@localhost ~]# vim /etc/yum.repos.d/remi.repo

[remi]

name=Les RPM de remi pour Enterprise Linux $releasever - $basearch

#baseurl=http://rpms.famillecollet.com/enterprise/$releasever/remi/$basearch/

mirrorlist=http://rpms.famillecollet.com/enterprise/$releasever/remi/mirror

enabled=1

gpgcheck=1

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi

failovermethod=priority

 

[remi-test]

name=Les RPM de remi en test pour Enterprise Linux $releasever - $basearch

#baseurl=http://rpms.famillecollet.com/enterprise/$releasever/test/$basearch/

mirrorlist=http://rpms.famillecollet.com/enterprise/$releasever/test/mirror

enabled=1

gpgcheck=1

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi

把 epel.repo 內的 enabled=0 改為enabled=1

接下來:

yum clean all

yum update

yum remove mysql

yum remove php

yum install httpd

yum install mysql

yum install php

yum install mysql-server

yum install php-mysql

rpm -qa |grep php

rpm -qa | grep mysql

亦可參考:

http://disp.cc/b/11-6BcZ

如果要裝新版的 PHP 5.4 的話,要裝 remi repo

先安裝 EPEL repo

$ rpm -ivh http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

再裝 Remi repo

$ rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm

升級 php ,其他相關的php模組與 mysql 也會跟著升級

$ yum --enablerepo=remi install php 

====================================================================================================================

 Package                        Arch                   Version                           Repository            Size

====================================================================================================================

Updating:

 php                            x86_64                 5.4.20-1.el6.remi                 remi                 2.7 M

Installing for dependencies:

 compat-mysql51                 x86_64                 5.1.54-1.el6.remi                 remi                 1.4 M

Updating for dependencies:

 mysql                          x86_64                 5.5.34-1.el6.remi                 remi                 5.8 M

 mysql-libs                     x86_64                 5.5.34-1.el6.remi                 remi                 775 k

 mysql-server                   x86_64                 5.5.34-1.el6.remi                 remi                  10 M

 php-cli                        x86_64                 5.4.20-1.el6.remi                 remi                 2.6 M

 php-common                     x86_64                 5.4.20-1.el6.remi                 remi                 925 k

 php-devel                      x86_64                 5.4.20-1.el6.remi                 remi                 2.5 M

 php-fpm                        x86_64                 5.4.20-1.el6.remi                 remi                 1.3 M

 php-gd                         x86_64                 5.4.20-1.el6.remi                 remi                 142 k

 php-mbstring                   x86_64                 5.4.20-1.el6.remi                 remi                 943 k

 php-mcrypt                     x86_64                 5.4.20-1.el6.remi                 remi                  49 k

 php-mysql                      x86_64                 5.4.20-1.el6.remi                 remi                 134 k

 php-pdo                        x86_64                 5.4.20-1.el6.remi                 remi                 118 k

 php-xml                        x86_64                 5.4.20-1.el6.remi                 remi                 169 k

至於其他使用編譯安裝的套件要重新編譯安裝一次

例如:  eAccelerator, memcache, mailparse

不然會出現PHP API版本號碼不合的訊息:

Unable to initialize module

Module compiled with module API=20090626

PHP    compiled with module API=20100525

These options need to match

http://wbkuo.pixnet.net/blog/post/43709814-yum-update-%E6%99%82%E7%99%BC%E7%94%9F-transaction-check-error-%E9%8C%AF%E8%AA%A4

[問題]

今天在幫客戶更新 php 時發生以下錯誤

ransaction Check Error:

  file /etc/my.cnf from install of mysql-5.1.58-jason.1.x86_64 conflicts with file from package mysql-5.0.95-1.el5_7.1.i386

  .....

[解法]

1. 先使用 # yum clean all 再進行更新

2. 先移除再重裝

    移除

    # yum remove php

    # yum remove php-common

    # yum remove mysql

    重裝

    # yum install mysql

    # yum install php

3. 檢查 /boot 目錄,如果剩餘空間很小,請清出一些空間

4. 檢查 /etc/yum.repos.d 底下的來源,一個一個把 enable=1 改成 enable=0,看看哪裡發生衝突

** 因為客戶的主機沒有資料,所以我是試到第二個解法就成功了 **

參考:

phpSysInfo 安裝:

# sudo

# cd /var/www/html/

# wget phpsysinfo.xx.gz

# tar phpsysinfo.xx.gz

# yum install php-dom

# service httpd restart

# cp /var/www/html/phpsysinfo/config.php.new /var/www/html/phpsysinfo/config.php

# vi /var/www/html/phpsysinfo/config.php

config.php 的內容改下面第一行為兩行:

//define('PSI_PLUGINS', false);

define('PSI_PLUGINS', 'MDStatus,PS,PSStatus,Quotas,SMART,BAT,ipmi');

# setenforce 0 //用這個指令來看完整的頁面資料(如網路流量)。

use your browser to visit http://your.ip/phpsysinfo/

關閉某些功能:

# setenforce 1 //這個指令比較安全,但只能看到一半的頁面資料。

CentOS 5.6 IPV6 網站設定:

以支援 ipv6 的電腦及網路,用 browser 開 http://[ipv6]/   服務正常,但檢測網站 (台中市 ipv6 檢測網站ipv6 檢測網)說都不通過。這時已經在 dns 上面設好 A 及 AAAA 記錄了,ptr 反解記錄也有,ping 及 ping6 也沒有問題。結果是網卡設定有問題,IPV6 的 gateway 沒設定好,補上、重啟網卡就可以了。以下文字引用自《張老師的 CentOS 5.6 IPV6 設定》:

二、網路設定的部分

# service ip6tables stop

# vi /etc/sysconfig/network

NETWORKING_IPV6=yes

# vi /etc/sysconfig/network-scripts/ifcfg-eth0

IPV6INIT=yes

IPV6ADDR=<IPv6-IP-Address>

IPV6_DEFAULTGW=<IPv6-IP-Gateway-Address>

( IPV6_DEFAULTGW 可直接打網址 ::ffe不加 mask /64)

重新啟動網路設定

# service network restart

三、測試(ping6 , traceroute6 , route)

$ ping6 ipv6.google.com

$ traceroute6 ipv6.google.com

$ route -n -A inet6

/etc/sysconfig/network 如下:

NETWORKING=yes

NETWORKING_IPV6=yes

HOSTNAME=web.nnjh.tn.edu.tw

GATEWAY=111.111.111.254

/etc/sysconfig/network-scripts/ifcfg-eth0 如下:

# Intel Corporation 82574L Gigabit Network Connection

DEVICE=eth0

BOOTPROTO=static

BROADCAST=111.111.111.255

HWADDR=your:mac:address

IPADDR=111.111.111.yourip

IPV6ADDR=2222:222:222::yourip/64

IPV6INIT=yes

IPV6_AUTOCONF=no

IPV6_DEFAULTGW=200X:28X:7XXX::fffe

NETMASK=255.255.255.0

NETWORK=163.xxx.xxx.0

ONBOOT=yes

當初就是沒加這行,浪費很多時間: IPV6_DEFAULTGW=200X:28X:7XXX::fffe

/etc/httpd/conf/httpd.conf 部分內容如下:

Listen 80

# Listen 111.111.111.111:80

# Listen [222:222:222::222]:80

/etc/sysconfig/ip6tables 如下:

# Firewall configuration written by system-config-securitylevel

# Manual customization of this file is not recommended.

*filter

:INPUT ACCEPT [0:0]

:FORWARD ACCEPT [0:0]

:OUTPUT ACCEPT [0:0]

:RH-Firewall-1-INPUT - [0:0]

-A INPUT -j RH-Firewall-1-INPUT

-A FORWARD -j RH-Firewall-1-INPUT

-A RH-Firewall-1-INPUT -i lo -j ACCEPT

-A RH-Firewall-1-INPUT -p icmpv6 -j ACCEPT

-A RH-Firewall-1-INPUT -p 50 -j ACCEPT

-A RH-Firewall-1-INPUT -p 51 -j ACCEPT

-A RH-Firewall-1-INPUT -p udp --dport 5353 -d ff02::fb -j ACCEPT

-A RH-Firewall-1-INPUT -p udp -m udp --dport 631 -j ACCEPT

-A RH-Firewall-1-INPUT -p tcp -m tcp --dport 631 -j ACCEPT

-A RH-Firewall-1-INPUT -p udp -m udp --dport 32768:61000 -j ACCEPT

-A RH-Firewall-1-INPUT -p tcp -m tcp --dport 32768:61000 ! --syn -j ACCEPT

-A RH-Firewall-1-INPUT -m tcp -p tcp --dport 21 -j ACCEPT

-A RH-Firewall-1-INPUT -m tcp -p tcp --dport 22 -j ACCEPT

-A RH-Firewall-1-INPUT -m tcp -p tcp --dport 80 -j ACCEPT

-A RH-Firewall-1-INPUT -m tcp -p tcp --dport 443 -j ACCEPT

-A RH-Firewall-1-INPUT -m tcp -p tcp --dport 3052 -j ACCEPT

-A RH-Firewall-1-INPUT -m udp -p udp --dport 3052 -j ACCEPT

-A RH-Firewall-1-INPUT -m tcp -p tcp --dport 6547 -j ACCEPT

-A RH-Firewall-1-INPUT -m udp -p udp --dport 6547 -j ACCEPT

-A RH-Firewall-1-INPUT -j REJECT --reject-with icmp6-adm-prohibited

COMMIT

/etc/resolv.conf 如下:

search domain.name.edu.tw

nameserver 111.111.111.1

nameserver 8.8.8.8

參考:

為資安故,將 port 3052 限制在內網連結,其他不可連:

/etc/sysconfig/iptables 更新:

-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp -s 163.xx.xx.0/24 --dport 3052 -j ACCEPT

-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p udp -s 163.xx.xx.0/24 --dport 3052 -j ACCEPT

存檔完後執行 service iptables restart

etc/sysconfig/ip6tables 更新:

-A RH-Firewall-1-INPUT -m tcp -p tcp -s 2001:xxx:xxxx::/64 --dport 3052 -j ACCEPT

-A RH-Firewall-1-INPUT -m udp -p udp -s 2001:xxx:xxxx::/64 --dport 3052 -j ACCEPT

存檔完後執行 service ip6tables restart

Requirements for Joomla 1.5.x

 

*Do not use PHP 4.3.9, 4.4.2 or 5.0.4. These releases have known bugs that will interfere with installation. Zend Optimizer 2.5.10 for PHP 4.4.x also has serious bugs and you should ask your host to upgrade to a newer version. Joomla! versions 1.5.15 + are compatible with PHP 5.3. Note that the OpenID library is not yet compatible with PHP 5.3.

**Joomla is not yet compatible with MySQL 6.x.

***In order to use SEO URLs, you will need to have the Apache mod_rewrite extension installed.

****For Microsoft IIS (depending on your setup) you may need the following:

For further assistance using Microsoft IIS, visit the Joomla IIS forum.

Joomla 1.6 will require PHP 5.2+ and MySQL 5.0.4+.

2011-05-26 的版本是:

Joomla 調校:

LoadModule rewrite_module modules/mod_rewrite.so

<Directory "/var/www/html">

# AllowOverride controls what directives may be placed in .htaccess files.

# It can be "All", "None", or any combination of the keywords:

#   Options FileInfo AuthConfig Limit

#

    AllowOverride All

Firefox 無法下載檔案解法,或改用 Google Chrome:

查詢 cpu 、 ram 、及 disk 硬體規格的指令:

有兩種方式,以 root 身份執行:

方式一:在/proc之下執行

$ cat cpuinfo

$ cat meminfo

方式二:執行指令

$ dmidecode -t processor

$ dmidecode -t memory

方式三:

$ grep -A 3 "model name" /proc/cpuinfo |egrep -v '(stepping|cache|--)'|awk -F: '{print $2}'

$ dmesg | grep "Memory:"

$ fdisk -l 2> /dev/null|grep '^Disk'

$ cat /proc/scsi/scsi

查 memory usage 的 script:

ps -ylC httpd | awk '{x += $8;y += 1} END {print "Apache Memory Usage (MB): "x/1024; print "Average Proccess Size (MB): "x/((y-1)*1024)}'

上面的 httpd 可改為 mysqld 以查詢 mysqld 的 memory 使用量。

調校 apache 設定檔