来一发构建高功能Web情况(linux/nginx/mysql/php-fastcgi)
小知识:Linux同时具有字符界面和图形界面。在字符界面用户可以通过键盘输入相应的指令来进行操作。本文次要是撰写Linux体系中PHPWeb情况的设置,先容在CentOS体系下安装:Nginx、MySQL、php-FastCGI,文顶用的软件都是停止2011/6/22最新不乱版。收集上关于这类设置良多,设置历程相差不年夜,可是参数有所分歧。入手下手之前先先容一下nginx:
Nginx(enginex)是一款轻量级的Web办事器/反向代办署理办事器及电子邮件(IMAP/POP3)代办署理办事器,并在一个BSD-like协定下刊行。由俄罗斯的步伐计划师IgorSysoev所开辟,最后供***年夜型的出口网站及征采引擎Rambler(俄文:Рамблер)利用。其特性是占据内存少,并发才能强,现实上nginx的并发才能的确在同范例的网页伺服器中体现较好.今朝中国年夜陆利用nginx网站用户有:新浪、网易、腾讯,别的出名的微网志Plurk也利用nginx。
上面入手下手叙说具体设置历程:
1、Centos体系安装终了以后,封闭不必要的办事优化体系,安装体系更新和所需软件撑持。
封闭不必要的办事
chkconfig--level3acpidoffchkconfig--level3anacronoffchkconfig--level3apmdoffchkconfig--level3mdmonitoroffchkconfig--level3xinetdoffchkconfig--level3sendmailoffchkconfig--level3rpcgssdoffchkconfig--level3rawdevicesoffchkconfig--level3messagebusoffchkconfig--level3atdoffchkconfig--level3gpmoffchkconfig--level3autofsoffchkconfig--level3cpuspeedoffchkconfig--level3haldaemonoffchkconfig--level3nfslockoffchkconfig--level3portmapoffchkconfig--level3xfsoffchkconfig--level3netfsoffchkconfig--level3smartdoffchkconfig--level3ip6tablesoffchkconfig--level3isdnoffchkconfig--level3rpcidmapdoffchkconfig--level3microcode_ctloffserviceacpidstopserviceanacronstopserviceapmdstopservicemdmonitorstopservicexinetdstopservicesendmailstopservicerpcgssdstopservicerawdevicesstopservicemessagebusstopserviceatdstopservicegpmstopserviceautofsstopservicecpuspeedstopservicehaldaemonstopservicenfslockstopserviceportmapstopservicexfsstopservicenetfsstopservicesmartdstopserviceip6tablesstopserviceisdnstopservicerpcidmapdstopservicemicrocode_ctlstop安装体系更新和所需软件撑持
yum-yupdateyum-yinstallgccgcc-c++autoconflibjpeglibjpeg-devellibpnglibpng-develfreetypefreetype-devellibxml2libxml2-develzlibzlib-develglibcglibc-develglib2glib2-develbzip2bzip2-develncursesncurses-develcurlcurl-devele2fsprogse2fsprogs-develkrb5krb5-devellibidnlibidn-developensslopenssl-developenldapopenldap-develnss_ldapopenldap-clientsopenldap-serversntprar下载必要用到的软件包(以下地点都是官方下载、也能够本人查找)
【下载PHP必要的库】wgethttp://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.13.1.tar.gzwgethttp://ncu.dl.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gzwgethttp://ncu.dl.sourceforge.net/project/mhash/mhash/0.9.9.9/mhash-0.9.9.9.tar.gzwgethttp://ncu.dl.sourceforge.net/project/mcrypt/MCrypt/2.6.8/mcrypt-2.6.8.tar.gz【下载mysql、php、nginx】wgethttp://mysql.mirrors.hoobly.com/Downloads/MySQL-5.1/mysql-5.1.57.tar.gzwgethttp://us.php.net/distributions/php-5.2.17.tar.gzwgethttp://php-fpm.org/downloads/php-5.2.17-fpm-0.5.14.diff.gzwgethttp://www.nginx.org/download/nginx-1.0.2.tar.gzwgetftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.12.tar.gz【下载php扩大】wgethttp://pecl.php.net/get/memcache-2.2.6.tgzwgethttp://pecl.php.net/get/PDO_MYSQL-1.0.2.tgzwgethttp://bart.eaccelerator.net/source/0.9.6.1/eaccelerator-0.9.6.1.tar.bz2wgetftp://ftp.imagemagick.org/pub/ImageMagick/ImageMagick-6.7.0-8.tar.gzwgethttp://pecl.php.net/get/imagick-3.0.0.tgz2、安装PHP必要的库步伐
tarzxvflibiconv-1.13.1.tar.gzcdlibiconv-1.13.1/&&./configure--prefix=/usr/localmake&&makeinstall&&cd..tarzxvflibmcrypt-2.5.8.tar.gzcdlibmcrypt-2.5.8/&&./configuremake&&makeinstall/sbin/ldconfig&&cdlibltdl/&&./configure--enable-ltdl-installmake&&makeinstall&&cd../..tarzxvfmhash-0.9.9.9.tar.gzcdmhash-0.9.9.9/&&./configuremake&&makeinstall&&cd..ln-s/usr/local/lib/libmcrypt.la/usr/lib/libmcrypt.laln-s/usr/local/lib/libmcrypt.so/usr/lib/libmcrypt.soln-s/usr/local/lib/libmcrypt.so.4/usr/lib/libmcrypt.so.4ln-s/usr/local/lib/libmcrypt.so.4.4.8/usr/lib/libmcrypt.so.4.4.8ln-s/usr/local/lib/libmhash.a/usr/lib/libmhash.aln-s/usr/local/lib/libmhash.la/usr/lib/libmhash.laln-s/usr/local/lib/libmhash.so/usr/lib/libmhash.soln-s/usr/local/lib/libmhash.so.2/usr/lib/libmhash.so.2ln-s/usr/local/lib/libmhash.so.2.0.1/usr/lib/libmhash.so.2.0.1ln-s/usr/local/bin/libmcrypt-config/usr/bin/libmcrypt-configtarzxvfmcrypt-2.6.8.tar.gz
cdmcrypt-2.6.8/&&/sbin/ldconfig
./configure&&make&&makeinstall&&cd..
3、编译安装MySQL
tarzxvfmysql-5.1.57.tar.gz&&cdmysql-5.1.57./configure--prefix=/usr/local/webserver/mysql/--enable-assembler--with-extra-charsets=complex--enable-thread-safe-client--with-big-tables--with-readline--with-ssl--with-embedded-server--enable-local-infilemake&&makeinstall&&cd..创立mysql用户组,创立数据库、日记等存储目次并付与权限
mkdir-p/data/mysqldatamkdir-p/data/mysqldata/databasemkdir-p/data/mysqldata/logmkdir-p/data/mysqldata/pidgroupaddmysqluseradd-gmysql-d/data/mysqldata/database-s/sbin/nologinmysqlchgrp-Rmysql/usr/local/webserver/mysql/.chown-Rroot:mysql/usr/local/webserver/mysql/*chown-Rmysql:mysql/data/mysqldata/*修正my.cnf文件参数(参数合用于年夜于2G内存办事器)
port=3306socket=/tmp/mysql.sockuser=mysqlport=3306socket=/tmp/mysql.sockbasedir=/usr/local/webserver/mysqldatadir=/data/mysqldata/databaselog-error=/data/mysqldata/log/mysql_error.logpid-file=/data/mysqldata/pid/mysql.pidskip-external-lockingskip-name-resolveback_log=500key_buffer_size=256Mmax_allowed_packet=32Mthread_stack=192Ktable_cache=256sort_buffer_size=4Mread_buffer_size=4Mjoin_buffer_size=4Mread_rnd_buffer_size=8Mmyisam_sort_buffer_size=64Mthread_cache=128thread_cache_size=10query_cache_size=32Mtmp_table_size=128Mmax_connections=5000wait_timeout=60max_connect_errors=6000expire_logs_days=30server-id=1quickmax_allowed_packet=32Mno-auto-rehash初始化MySQL办事
/usr/local/webserver/mysql/bin/mysql_install_db--basedir=/usr/local/webserver/mysql--datadir=/data/mysqldata/database--user=mysql启动MySQL办事
serviceacpidstopserviceanacronstopserviceapmdstopservicemdmonitorstopservicexinetdstopservicesendmailstopservicerpcgssdstopservicerawdevicesstopservicemessagebusstopserviceatdstopservicegpmstopserviceautofsstopservicecpuspeedstopservicehaldaemonstopservicenfslockstopserviceportmapstopservicexfsstopservicenetfsstopservicesmartdstopserviceip6tablesstopserviceisdnstopservicerpcidmapdstopservicemicrocode_ctlstop0修正root暗码
serviceacpidstopserviceanacronstopserviceapmdstopservicemdmonitorstopservicexinetdstopservicesendmailstopservicerpcgssdstopservicerawdevicesstopservicemessagebusstopserviceatdstopservicegpmstopserviceautofsstopservicecpuspeedstopservicehaldaemonstopservicenfslockstopserviceportmapstopservicexfsstopservicenetfsstopservicesmartdstopserviceip6tablesstopserviceisdnstopservicerpcidmapdstopservicemicrocode_ctlstop14、编译安装PHP(FastCGI形式)
serviceacpidstopserviceanacronstopserviceapmdstopservicemdmonitorstopservicexinetdstopservicesendmailstopservicerpcgssdstopservicerawdevicesstopservicemessagebusstopserviceatdstopservicegpmstopserviceautofsstopservicecpuspeedstopservicehaldaemonstopservicenfslockstopserviceportmapstopservicexfsstopservicenetfsstopservicesmartdstopserviceip6tablesstopserviceisdnstopservicerpcidmapdstopservicemicrocode_ctlstop25、安装PHP扩大模块
serviceacpidstopserviceanacronstopserviceapmdstopservicemdmonitorstopservicexinetdstopservicesendmailstopservicerpcgssdstopservicerawdevicesstopservicemessagebusstopserviceatdstopservicegpmstopserviceautofsstopservicecpuspeedstopservicehaldaemonstopservicenfslockstopserviceportmapstopservicexfsstopservicenetfsstopservicesmartdstopserviceip6tablesstopserviceisdnstopservicerpcidmapdstopservicemicrocode_ctlstop3修正php.ini文件
serviceacpidstopserviceanacronstopserviceapmdstopservicemdmonitorstopservicexinetdstopservicesendmailstopservicerpcgssdstopservicerawdevicesstopservicemessagebusstopserviceatdstopservicegpmstopserviceautofsstopservicecpuspeedstopservicehaldaemonstopservicenfslockstopserviceportmapstopservicexfsstopservicenetfsstopservicesmartdstopserviceip6tablesstopserviceisdnstopservicerpcidmapdstopservicemicrocode_ctlstop4查找:
serviceacpidstopserviceanacronstopserviceapmdstopservicemdmonitorstopservicexinetdstopservicesendmailstopservicerpcgssdstopservicerawdevicesstopservicemessagebusstopserviceatdstopservicegpmstopserviceautofsstopservicecpuspeedstopservicehaldaemonstopservicenfslockstopserviceportmapstopservicexfsstopservicenetfsstopservicesmartdstopserviceip6tablesstopserviceisdnstopservicerpcidmapdstopservicemicrocode_ctlstop5修正为:
serviceacpidstopserviceanacronstopserviceapmdstopservicemdmonitorstopservicexinetdstopservicesendmailstopservicerpcgssdstopservicerawdevicesstopservicemessagebusstopserviceatdstopservicegpmstopserviceautofsstopservicecpuspeedstopservicehaldaemonstopservicenfslockstopserviceportmapstopservicexfsstopservicenetfsstopservicesmartdstopserviceip6tablesstopserviceisdnstopservicerpcidmapdstopservicemicrocode_ctlstop6并在此行后增添以下几行,然后保留:
serviceacpidstopserviceanacronstopserviceapmdstopservicemdmonitorstopservicexinetdstopservicesendmailstopservicerpcgssdstopservicerawdevicesstopservicemessagebusstopserviceatdstopservicegpmstopserviceautofsstopservicecpuspeedstopservicehaldaemonstopservicenfslockstopserviceportmapstopservicexfsstopservicenetfsstopservicesmartdstopserviceip6tablesstopserviceisdnstopservicerpcidmapdstopservicemicrocode_ctlstop7再查找:
serviceacpidstopserviceanacronstopserviceapmdstopservicemdmonitorstopservicexinetdstopservicesendmailstopservicerpcgssdstopservicerawdevicesstopservicemessagebusstopserviceatdstopservicegpmstopserviceautofsstopservicecpuspeedstopservicehaldaemonstopservicenfslockstopserviceportmapstopservicexfsstopservicenetfsstopservicesmartdstopserviceip6tablesstopserviceisdnstopservicerpcidmapdstopservicemicrocode_ctlstop8修正为:
serviceacpidstopserviceanacronstopserviceapmdstopservicemdmonitorstopservicexinetdstopservicesendmailstopservicerpcgssdstopservicerawdevicesstopservicemessagebusstopserviceatdstopservicegpmstopserviceautofsstopservicecpuspeedstopservicehaldaemonstopservicenfslockstopserviceportmapstopservicexfsstopservicenetfsstopservicesmartdstopserviceip6tablesstopserviceisdnstopservicerpcidmapdstopservicemicrocode_ctlstop9创立缓存目次,设置eAccelerator减速PHP:
0将以下参数增加到php.ini文件开端
1修正php-fpm.conf设置文件
2假如安装Nginx+PHP用于步伐调试,请将以下的
3改成
4以便显现PHP毛病信息,不然,Nginx会报形态为500的空缺毛病页
启动php-cgi历程,监听127.0.0.1的9000端口,历程数为128(假如办事器内存小于3GB,能够只开启64个历程),用户为:www
Ulimit-SHn65535
/usr/local/webserver/php/sbin/php-fpmstart//在www用户创立以后在开启。
注:/usr/local/webserver/php/sbin/php-fpm另有其他参数,包含:start|stop|quit|restart|reload|logrotate,修正php.ini后不重启php-cgi,从头加载设置文件利用reload。
6、编译安装nginx
创立www用户和组,和网站目次,日记目次
5创立或修正nginx设置文件
catnginx.conf
6catvhosts.conf
7catenable_fcgi.conf
8启动nginx办事
9
小知识:CentOS完全遵守上游供应商的再发行政策,并且以百分之百的软件兼容性为目标。 眼看这个学期的Linux课程已经告一段落了,我觉得有必要写一遍心得体会来总结一下这学期对着门课程的学习。 把这个问题放在其他Linux社区请求帮助也是一种选择。如果Linux得不到答案,请不要以为我们觉得无法帮助你。有时只是看到你问题的人不知道答案罢了。这时换一个社区是不错的选择。 和私有操作系统不同,各个Linux的发行版本的技术支持时间都较短,这对于Linux初学者是往往不够的。 熟悉系统的基本操作,Linux的图形界面直观,操作简便,多加上机练习就可熟悉操作,在Linux下学习办公软件等常用软件。 对Linux命令熟悉后,你可以开始搭建一个小的Linux网络,这是最好的实践方法。Linux是网络的代名词,Linux网络服务功能非常强大,不论是邮件服务器、Web服务器、DNS服务器等都非常完善。 Windows?是图形界面的,Linux类似以前的?DOS,是文本界面的,如果你运行了图形界面程序X-WINDOWS后,Linux?也能显示图形界面,也有开始菜单、桌面、图标等。 其实老师让写心得我也没怎么找资料应付,自己想到什么就写些什么,所以不免有些凌乱;很少提到编程,因为那些在实验报告里已经说了,这里再写就多余了。 其中不乏很多IT精英的心血。我们学透以后更可以做成自己的OS!? 其实老师让写心得我也没怎么找资料应付,自己想到什么就写些什么,所以不免有些凌乱;很少提到编程,因为那些在实验报告里已经说了,这里再写就多余了。
页:
[1]