[日期:2011-05-06] 來源:Linux社區 作者:fuying163
Centos5.5(32bit)
所需軟件包:
gd-2.0.35.tar.gz
libxml2-2.7.7.tar.gz
libmcrypt-2.5.8.tar.bz2
cronolog-1.6.2.tar.gz
httpd-2.2.8.tar.gz
mysql-5.1.44.tar.gz
php-5.2.14.tar.gz
xcache-1.3.0.tar.gz
ZendOptimizer-3.3.9-linux-glibc23-i386.tar.gz
修改系統參數,編寫腳本執行init.sh
cd /opt
vi init.sh
將下列內容拷貝至init.sh腳本中
#welcome
cat << EOF
+--------------------------------------------------------------+
| === Welcome to Centos System init === |
+--------------http://www.linuxtone.org------------------------+
+----------------------Author:NetSeek--------------------------+
EOF
#disable ipv6
cat << EOF
+--------------------------------------------------------------+
| === Welcome to Disable IPV6 === |
+--------------------------------------------------------------+
EOF
echo "alias net-pf-10 off" >> /etc/modprobe.conf
echo "alias ipv6 off" >> /etc/modprobe.conf
/sbin/chkconfig --level 35 ip6tables off
echo "ipv6 is disabled!"
#disable selinux
sed -i '/SELINUX/s/enforcing/disabled/' /etc/selinux/config
echo "selinux is disabled,you must reboot!"
#vim
sed -i "8 s/^/alias vi='vim'/" /root/.bashrc
echo 'syntax on' > /root/.vimrc
#zh_cn
sed -i -e 's/^LANG=.*/LANG="zh_CN.GB18030"/' /etc/sysconfig/i18n
#tunoff services
#--------------------------------------------------------------------------------
cat << EOF
+--------------------------------------------------------------+
| === Welcome to Tunoff services === |
+--------------------------------------------------------------+
EOF
#---------------------------------------------------------------------------------
for i in `ls /etc/rc3.d/S*`
do
CURSRV=`echo $i|cut -c 15-`
echo $CURSRV
case $CURSRV in
crond | irqbalance | microcode_ctl | network | random | sendmail | sshd | syslog | local | mysqld )
echo "Base services, Skip!"
;;
*)
echo "change $CURSRV to off"
chkconfig --level 235 $CURSRV off
service $CURSRV stop
;;
esac
done
執行腳本:
sh init.sh
重啓系統
reboot
二、編譯安裝基本環境
使用 yum 程序安裝所需開發包(以下爲標準的 RPM 包名稱)
rpm --import http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
yum -y install ntp vim-enhanced gcc gcc-c++ gcc-g77 flex bison autoconf automake bzip2-devel ncurses-devel zlib-devel libjpeg-devel libpng-devel libtiff-devel freetype-devel libXpm-devel gettext-devel pam-devel libtool libtool-ltdl openssl openssl-devel fontconfig-devel
解釋如下:
安裝基本的編譯工具 # yum install -y gcc gcc-c++ flex bison autoconf automake libtool bzip2-devel zlib-devel ncurses-devel pam-devel
安裝編譯 GD 需要的庫# yum install -y xorg-x11-server-Xorg fontconfig-devel libXpm-devel libjpeg-devel libpng-devel libtiff-devel freetype-devel
安裝mysql需要的庫# yum install -y libxml2-devel curl-devel
編譯安裝軟件包
1)GD2
tar -zxvf gd-2.0.35.tar.gz
cd gd-2.0.35
./configure --prefix=/usr/local/gd2
make && make install
2) LibXML2
tar -zxvf libxml2-2.7.7.tar.gz
cd libxml2-2.7.7
./configure --prefix=/usr/local/libxml2
make && make install
3) LibMcrypt
tar xvf libmcrypt-2.5.8.tar.bz2
cd libmcrypt-2.5.8
./configure --prefix=/usr/local/libmcrypt
make && make install
4) Apache日誌截斷程序
tar zxvf cronolog-1.6.2.tar.gz
cd cronolog-1.6.2
./configure --prefix=/usr/local/cronolog
make && make install
5)安裝mysql
tar -zxvf mysql-5.1.44.tar.gz
cd mysql-5.1.44
./configure --prefix=/usr/local/mysql --enable-assembler --with-extra-charsets=complex --enable-thread-safe-client --with-big-tables --with-readline --with-ssl --with-embedded-server --enable-local-infile
make && make install
創建MySQL數據庫,用默認的配置my.cnf
groupadd mysql
useradd -g mysql mysql
cp /usr/local/mysql/share/mysql/my-medium.cnf /etc/my.cnf
/usr/local/mysql/bin/mysql_install_db --user=mysql
chown -R mysql /usr/local/mysql/var
chgrp -R mysql /usr/local/mysql/.
添加Mysql啓動服務,並且設置root密碼
cp /usr/local/mysql/share/mysql/mysql.server /etc/init.d/mysql
chmod 755 /etc/init.d/mysql
chkconfig --level 345 mysql on
echo "/usr/local/mysql/lib/mysql" >> /etc/ld.so.conf
echo "/usr/local/lib" >>/etc/ld.so.conf
ldconfig
ln -s /usr/local/mysql/lib/mysql /usr/lib/mysql
ln -s /usr/local/mysql/include/mysql /usr/include/mysql
service mysql start
/usr/local/mysql/bin/mysqladmin -u root password root //root改爲你需要的密碼
service mysql restart
6)安裝apache
groupadd httpd
useradd -g httpd -s /sbin/nologin -M httpd
tar -zxvf httpd-2.2.8.tar.gz
cd httpd-2.2.8
./configure --prefix=/usr/local/apache2 --with-included-apr --enable-so --enable-deflate=shared --enable-expires=shared --enable-rewrite=shared --enable-static-support --disable-userdir --enable-dav --enable-maintainer-mode
紅色字體爲部署SVN服務器所用,否則編譯svn的時候會報錯
make
make install
7)安裝php
tar -zxvf php-5.2.14.tar.gz
cd php-5.2.14
mkdir -p /usr/local/php/etc
./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-libxml-dir=/usr/local/libxml2 --with-gd=/usr/local/gd2 --with-jpeg-dir --with-png-dir --with-bz2 --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-openssll --with-mcrypt=/usr/local/libmcrypt --enable-soap --enable-gd-native-ttf --enable-ftp --enable-mbstring --enable-exif --disable-ipv6 --disable-cgi --disable-cli
make
make install
cp php.ini-dist /usr/local/php/etc/php.ini
7)安裝Xcache
tar -zxvf xcache-1.3.0.tar.gz
cd xcache-1.3.0
/usr/local/php/bin/phpize ./configure --enable-xcache --enable-xcache-coverager --with-php-config=/usr/local/php/bin/php-config --enable-inline-optimization --disable-debug
vi /usr/local/php/etc/php.ini
在最後添加以下內容
[xcache-common]
zend_extension = /usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/xcache.so
[xcache.admin]
xcache.admin.user = "admin"
;create md5 password: echo -n "password"| md5sum
xcache.admin.pass = "f3dfd37a03b1356d6380b41e524f903b" #password is hx10.com
[xcache]
; Change xcache.size to tune the size of the opcode cache
xcache.size = 24M
xcache.shm_scheme = "mmap"
xcache.count = 4
xcache.slots = 8K
xcache.ttl = 0
xcache.gc_interval = 0
; Change xcache.var_size to adjust the size of variable cache
xcache.var_size = 8M
xcache.var_count = 1
xcache.var_slots = 8K
xcache.var_ttl = 0
xcache.var_maxttl = 0
xcache.var_gc_interval = 300
xcache.test = Off
xcache.readonly_protection = On
xcache.mmap_path = "/tmp/xcache"
xcache.coredump_directory = ""
xcache.cacher = On
xcache.stat = On
xcache.optimizer = Off
[xcache.coverager]
xcache.coverager = On
xcache.coveragedump_directory = ""
8)安裝Zend Optimizer 系統如果是64位的,請安裝64位的ZendOptimizer-3.3.9-linux-glibc23文件;
tar -zxvf ZendOptimizer-3.3.9-linux-glibc23-i386.tar.gz
mv ZendOptimizer-3.3.9-linux-glibc23-i386 /usr/local/Zend
cp /usr/local/Zend/data/5_2_x_comp/ZendOptimizer.so /usr/local/Zend/
vi /usr/local/php/etc/php.ini
最後一行加入以下內容
zend_optimizer.optimization_level=15
zend_extension=/usr/local/Zend/ZendOptimizer.so
9)整合Apache與PHP及系統初化配置
vi /usr/local/apache2/conf/httpd.conf
查找AddType application/x-gzip .gz .tgz,在該行下面添加
AddType application/x-httpd-php .php
查找DirectoryIndex index.html 把該行修改成
DirectoryIndex index.html index.htm index.php
找到
#Include conf/extra/httpd-mpm.conf
#Include conf/extra/httpd-info.conf
#Include conf/extra/httpd-vhosts.conf
#Include conf/extra/httpd-default.conf
去掉這4行前面的#
注意:以上 4 個擴展配置文件中的設置請按照相關原則進行合理配置!
vi /usr/local/apache2/conf/extra/httpd-vhosts.conf
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot "/www/wwwroot/"
ServerName www.test.com
ServerAlias www.test.com
ErrorLog "logs/www.test.com-error_log"
CustomLog "logs/www.test.com-access_log" common
</VirtualHost>
新建一個虛擬主機,刪除原有的虛擬主機配置;
mkdir -p /www/wwwroot/
然後PHP探針放到這個目錄
vi /usr/local/apache2/conf/httpd.conf
找到
<Directory />
Options FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all //把這裏的Deny改成Allow
</Directory>
找到
#ServerName www.example.com:80 在這一行後面加入下面一行
ServerName 127.0.0.1:80
找到
User httpd
Group httpd
把原來的daemon修改成httpd
Apache 運行賬戶 httpd:httpd
chown -R httpd:httpd /www/wwwroot
重啓apache
# /usr/local/apache2/bin/apachectl restart
輸入探針的地址訪問
http://ip/php.php
安裝apache服務
cd httpd-2.2.8
cp support/apachectl /etc/init.d/httpd
vi /etc/init.d/httpd
加入以下的代碼,使apache可以用chkconfig方式啓動(保留#):
# Startup script for the Apache Web Server
# chkconfig: 2345 10 90
# description: Apache is a World Wide Web server.
# processname: httpd
# pidfile: /usr/local/apache2/log/httpd.pid
# config: /usr/local/apache2/conf/httpd.conf
安裝服務並開機啓動
chmod 755 /etc/init.d/httpd
chkconfig --add httpd
chkconfig --level 345 httpd on
service httpd start
10)安全和性能優化
vi /usr/local/php/etc/php.ini
查找disable_functions =
等號後面加入以下參數,注意不能換行
phpinfo,passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_alter,ini_restore,dl,pfsockopen,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,get_cfg_var
查找以下2項,把on改成off
expose_php = Off
display_errors = Off
vi /usr/local/apache2/conf/extra/httpd-default.conf 修改後的內容如下
Timeout 15
KeepAlive Off
MaxKeepAliveRequests 50
KeepAliveTimeout 5
UseCanonicalName Off
AccessFileName .htaccess
ServerTokens Prod
ServerSignature Off
HostnameLookups Off
vi /usr/local/apache2/conf/extra/httpd-mpm.conf 修改一個模塊後的內容如下
原來的配置如下:
<IfModule mpm_prefork_module>
ServerLimit 256
StartServers 5
MinSpareServers 5
MaxSpareServers 10
MaxClients 256
MaxRequestsPerChild 0
</IfModule>
修改後配置如下
<IfModule mpm_prefork_module>
ServerLimit 2000
StartServers 2000
MinSpareServers 10
MaxSpareServers 10
MaxClients 2000
MaxRequestsPerChild 10000
</IfModule>
查看是什麼模式
/usr/local/apache2/bin/apachectl -l
如果出現prefork.c那就說明是prefork模式
本篇文章來源於 Linux公社網站(www.linuxidc.com) 原文鏈接:http://www.linuxidc.com/Linux/2011-05/35628.htm
[url=http://www.idouye.com/]http://www.idouye.com 愛豆葉資料分享[/url]
CentOS 5.5+Apache+PHP+MySQL 5部署筆記(更新)
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章
Apache HTTP Server詳解
顺其自然~
2020-03-08 12:51:19
Xdebug 配置 php 調試器
changyang208
2020-02-24 08:31:01
apache http的語句,允許被訪問
攀峰者
2020-02-22 13:11:50
新_CentOS 6下搭建Apache+MySQL+PHP+SSL
sealbird
2018-11-20 02:47:16
CentOS 6 架設 apache + php + mysql
sealbird
2018-11-20 02:47:16
CentOS 下管理自定義 PHP 計劃任務代碼的守護進程腳本
sealbird
2018-11-20 02:47:15
apache 防盜鏈,限帶寬和連接數
sealbird
2018-11-08 03:25:01
apache防盜鏈(mod_perl試用二)
sealbird
2018-11-08 03:25:01
Apache 防盜鏈(Apache Anti-Leech)技術的簡單實現
sealbird
2018-11-08 03:25:01
apachemod_proxy 集羣
sealbird
2018-11-04 02:51:46
Apache RewriteRule的標誌一覽
sealbird
2018-11-04 02:51:46
apache2.2 tomcat6.0 負載均衡集羣整理配置
sealbird
2018-11-04 02:51:46
Apache Http(反向代理)Tomcat模式下訪問報錯:Proxy Error
爪洼实习生
2018-08-29 08:36:27
給Tomcat,Apache配置gzip壓縮(HTTP壓縮)功能
wangxuefeng_yctc
2018-08-25 02:33:36