多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
[返回目录](index.html)#### [安装](anzhuang_index.html "test") —— [CentOS5下Nginx 环境推荐教程](anzhuang_nginx.html "test") ##### 一、系统约定 软件源代码包存放位置 /usr/local/src 源码包编译安装位置(prefix) /usr/local/software\_name 脚本以及维护程序存放位置 /usr/local/sbin MySQL 数据库位置 /var/lib/mysql(可按情况设置) 网站根目录 /home/www/wwwroot(可按情况设置) 虚拟主机日志根目录 /home/www/logs(可按情况设置) 运行账户 www:www ##### 二、系统环境部署及调整 ###### 1、检查系统是否正常 ``` <pre class="brush:xml"> # more /var/log/messages (检查有无系统级错误信息) # dmesg (检查硬件设备是否有错误信息) # ifconfig(检查网卡设置是否正确) # ping www.163.com (检查网络是否正常) # cat /proc/cpuinfo (检查CPU频率是否正常) # top (按1检测CPU核数是否正常,内存大小是否正常) ``` ###### 2、关闭不需要的服务 ``` <pre class="brush:xml"># ntsysv ``` 以下仅列出需要启动的服务,未列出的服务一律推荐关闭: ``` <pre class="brush:xml"> atd crond irqbalance microcode_ctl network sendmail sshd syslog ``` 关闭SElinux:修改/etc/selinux/config文件中的SELINUX= 为 disabled ###### 3、更换yum国内源 ``` <pre class="brush:xml"> # cd /etc/yum.repos.d # mv CentOS-Base.repo CentOS-Base.repo.save # 网易YUM源地址:http://mirrors.163.com/.help/centos.html ,你可根据服务器版本指定源文件进行下载(此行不做为命令运行 ) # wget http://mirrors.163.com/.help/CentOS5-Base-163.repo # mv CentOS5-Base-163.repo CentOS-Base.repo # yum clean all ``` ###### 4、服务器时间检查和设置 ``` <pre class="brush:xml"> #data (检查时间是否正确,是否是中国时间CST) #cp -f /usr/share/zoneinfo/Asia/Shanghai /etc/localtime (如果时区不对,则执行,时间正常的跳过) #yum -y install ntp (安装ntp对时工具) #chkconfig ntpd on (让对时服务开机启动) ``` ###### 5、使用 yum 对系统进行更新并且安装必要软件包 ``` <pre class="brush:xml"> #yum update –y #yum -y install make openssl openssl-devel pcre pcre-devel libpng libpng-devel libjpeg-6b libjpeg-devel-6b freetype freetype-devel gd gd-devel zlib zlib-devel gcc gcc-c++ libXpm libXpm-devel ncurses ncurses-devel libmcrypt libmcrypt-devel libxml2 libxml2-devel imake autoconf automake screen sysstat compat-libstdc++-33 curl curl-devel ``` ###### 6. 重新启动系统 ``` <pre class="brush:xml"># init 6 ``` ##### 三、编译安装L.A.M.P环境 ###### 1、下载软件(截止到11年10月的最新版本) ``` <pre class="brush:xml"> # cd /usr/local/src #wget http://sysoev.ru/nginx/nginx-0.7.63.tar.gz #wget http://download.scientificlinux.net/nginx #wget http://download.scientificlinux.net/php-fpm.conf #wget http://download.scientificlinux.net/nginx.conf #wget http://download.scientificlinux.net/fcgi.conf #wget http://download.scientificlinux.net/php-5.2.10.tar.gz #wget http://download.scientificlinux.net/php-5.2.10-fpm-0.5.13.diff.gz #wget http://download.scientificlinux.net/ZendOptimizer-3.3.3-linux-glibc23-i386.tar.gz (32位系统) #wget http://download.scientificlinux.net/ZendOptimizer-3.3.3-linux-glibc23-x86_64.tar.gz (64位系统) #wget http://download.scientificlinux.net/mysql-5.1.39-linux-i686-glibc23.tar.gz (32位系统) #wget http://download.scientificlinux.net/mysql-5.1.39-linux-x86_64-glibc23.tar.gz (64位系统) ``` ###### 2、安装MySQL ``` <pre class="brush:xml"> cd /usr/local/src tar zxvf mysql-5.1.39-linux-i686-glibc23.tar.gz mv mysql-5.1.39-linux-i686-glibc23 /usr/local/ ln -s /usr/local/mysql-5.1.39-linux-i686-glibc23/ /usr/local/mysql groupadd mysql useradd -g mysql mysql chown -R mysql:mysql /usr/local/mysql chown -R mysql:mysql /usr/local/mysql-5.1.39-linux-i686-glibc23/ cd /usr/local/mysql ./scripts/mysql_install_db --user=mysql cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld chmod 755 /etc/rc.d/init.d/mysqld chkconfig --add mysqld chkconfig --level 3 mysqld on cp ./support-files/my-huge.cnf /etc/my.cnf mv /usr/local/mysql/data /var/lib/mysql chown -R mysql:mysql /var/lib/mysql ``` 编辑/etc/my.cnf 在 \[mysqld\] 段增加 ``` <pre class="brush:xml"> datadir = /var/lib/mysql skip-innodb wait-timeout = 10 max_connections = 512 max_connect_errors = 10000000 ``` 在 \[mysqld\] 段修改 ``` <pre class="brush:xml"> max_allowed_packet = 16M thread_cache_size = CPU个数*2 ``` 将 log-bin 注释 ``` <pre class="brush:xml"> service mysqld start bin/mysqladmin -u root password 'password_for_root' ``` 其中引号内的password\_for\_root是要设置的root密码 ###### 3、安装Nginx ``` <pre class="brush:xml"> cd /usr/local/src/ tar zxvf nginx-0.7.63.tar.gz cd nginx-0.7.63 ./configure --prefix=/usr/local/nginx --conf-path=/usr/local/nginx/conf/nginx.conf --with-http_realip_module --with-http_addition_module --with-http_gzip_static_module --with-http_random_index_module --with-http_stub_status_module --with-http_sub_module --with-http_dav_module make make install cp /usr/local/src/nginx /etc/init.d/nginx chmod 755 /etc/init.d/nginx chkconfig --add nginx chkconfig nginx on ``` ###### 4、安装PHP和Zend ``` <pre class="brush:xml"> cd /usr/local/src tar zxvf php-5.2.10.tar.gz gzip -cd php-5.2.10-fpm-0.5.13.diff.gz | patch -d php-5.2.10 -p1 cd php-5.2.10 ./configure --prefix=/usr/local/php5 --with-config-file-path=/usr/local/etc/cgi --enable-mbstring --enable-ftp --with-gd --with-jpeg-dir=/usr --with-png-dir=/usr --enable-magic-quotes --with-mysql=/usr/local/mysql --with-pear --enable-sockets --with-ttf --with-freetype-dir=/usr --enable-gd-native-ttf --with-zlib --enable-sysvsem --enable-sysvshm --with-libxml-dir=/usr --enable-force-cgi-redirect --enable-fastcgi --with-xmlrpc --enable-zip --enable-fpm make make install mkdir -p /usr/local/etc/cgi/ cp php.ini-dist /usr/local/etc/cgi/php.ini mv -f /usr/local/src/php-fpm.conf /usr/local/php5/etc/php-fpm.conf groupadd www useradd -g www www echo 'ulimit -SHn 65535' >> /etc/rc.local echo '/usr/local/php5/sbin/php-fpm start' >> /etc/rc.local cd /usr/local/src tar zxvf ZendOptimizer-3.3.3-linux-glibc23-i386.tar.gz cd ZendOptimizer-3.3.3-linux-glibc23-i386 ./install ``` 注意:第一个要填的路径是Zend安装路径,第二个是php.ini所在的路径,即/usr/local/etc/cgi 不要选重启apache ###### 5、启动Nginx和php ``` <pre class="brush:xml"> mv -f /usr/local/src/fcgi.conf /usr/local/nginx/conf/ cp -f /usr/local/src/nginx.conf /usr/local/nginx/conf/nginx.conf mkdir -p /home/www/wwwroot ulimit -SHn 65535 /usr/local/php5/sbin/php-fpm start service nginx start ``` 在/home/www/wwwroot放入一个index.php,内容为 打开浏览器访问,即可看到phpinfo页面 [返回目录](index.html) 上海盛大网络发展有限公司 c 2006 - 2011 B2-20040053. 问题和建议请反馈至:http://bbs.phpcms.cn