订阅邮件
快捷导航

Linux环境搭建web教程

  [复制链接]
查看: 3537|回复: 9
发表于 2012-9-1 21:12:04 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转合天下互动社区。

您需要 登录 才可以下载或查看,没有帐号?中文注册

x
目前常用的有两种系统供大家选择,一种是Linux环境下运行,另一种是windows系统环境下运行,我们建议大家采用 Linux 的环境下运行,当然如果只是测试用或者只是运行一些小站点的话可以使用windows系统。

一、系统约定
软件源代码包存放位置:/usr/local/src
源码包编译安装位置(prefix):/usr/local/software_name
脚本以及维护程序存放位置:/usr/local/sbin
MySQL 数据库位置:/var/lib/MySQL(可按情况设置)
Apache 网站根目录:/home/www/wwwroot(可按情况设置)
Apache 虚拟主机日志根目录:/home/www/logs(可按情况设置)
Apache 运行账户:www:www

二、系统环境部署及调整
1、检查系统是否正常
# more /var/log/messages(检查有无系统级错误信息)
# dmesg(检查硬件设备是否有错误信息)
#cat /proc/cpuinfo (检查CPU频率是否正常)
#top (按1检测CPU核数是否正常,内存大小是否正常)
# ifconfig(检查网卡设置是否正确)
# ping www.163.com(检查网络是否正常)
2、关闭不需要的服务
# ntsysv
以下仅列出需要启动的服务,未列出的服务一律推荐关闭:
atd
crond
irqbalance
microcode_ctl
network
sendmail
sshd
syslog
关闭SElinux:修改/etc/selinux/config文件中的SELINUX= 为 disabled
3、更换快速源
# cd /etc/yum.repos.d/
# mv CentOS-Base.repo CentOS-Base.repo.old
# wget http://centos.ustc.edu.cn/CentOS-Base.repo.5
# mv CentOS-Base.repo.5 CentOS-Base.repo
# yum update
4、使用 yum 程序安装所需开发包(以下为标准的 RPM 包名称)
# yum -y install ntp 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-deve
5、定时校正服务器时钟,定时与中国国家授时中心授时服务器同步
# crontab -e
加入一行:
*/30 * * * * ntpdate 210.72.145.44 > /dev/null 2>&1
6、下载程序包
请到各程序官方网站下载最新的稳定版本存放到/usr/local/src/目录
Apache 当前稳定版 2.2.15
http://apache.securedservers.com/httpd/
PHP 当前稳定版5.2.13
http://cn.php.net/releases/
Mysql 当前稳定版5.0.86
http://dev.mysql.coml/
Zend 当前稳定版3.3.3
http://downloads.zend.com/
Memcache 当前稳定版2.2.5
http://pecl.php.net/package/memcache/
Memcached 当前稳定版1.4.5
http://memcached.googlecode.com
文中的配置文件和脚本限于篇幅,请到以下地址下载
Apache控制脚本
http://c.sihost.net/jb/httpd
Apache配置文件
http://c.sihost.net/jb/httpd.conf
以上列出的程序最新稳定版下载列表
http://c.sihost.net/lamp_tools.list
在 /usr/local/src目录下执行
wget http://c.sihost.net/lamp_tools.list
wget -i lamp_tools.list
7、创建web运行用户
#groupadd www
#useradd -g www www
#mkdir -p /home/www/wwwroot
#chmod +w /home/www/wwwroot
# chown www:www /home/www/wwwroot -R
8、重新启动
# init 6

三、编译安装L.A.M.P环境
1、安装MySQL
# cd /usr/local/src
# tar zxvf mysql-5.0.86-linux-i686-icc-glibc23.tar.gz
# mv mysql-5.0.86-linux-i686-icc-glibc23 /usr/local/
# ln -s /usr/local/mysql-5.0.86-linux-i686-icc-glibc23/ /usr/local/mysql
#groupadd mysql
#useradd -g mysql mysql -d /home/mysql -s /sbin/nologin
#chown -R mysql:mysql /usr/local/mysql
#chown -R mysql:mysql /usr/local/mysql-5.0.86-linux-i686-icc-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] 段增加

  • datadir = /var/lib/mysql
  • skip-innodb
  • wait-timeout = 10
  • max_connections = 512
  • max_connect_errors = 10000000

复制代码

在 [mysqld] 段修改

  • max_allowed_packet = 16M
  • thread_cache_size = CPU个数*2

复制代码

将 log-bin 注释
service mysqld start
# bin/mysqladmin -u root password password
其中引号内的 password 是要设置的 root 密码
2、编译安装Apache
# cd /usr/local/src/
# tar jxvf httpd-2.2.15.tar.bz2
# cd httpd-2.2.15/
# ./configure --prefix=/usr/local/apache --enable-module=rewrite --disable-access --disable-auth --disable-charset-lite --disable-include --disable-log-config --disable-env --disable-setenvif --disable-mime --disable-status --disable-autoindex --disable-asis --disable-cgid --disable-cgi --disable-negotiation --disable-dir --disable-actions --disable-userdir --disable-alias --enable-so --enable-mods-shared=\' access auth auth_anon auth_dbm auth_digest dav dav_fs actions alias asis autoindex cache cern_meta cgi charset_lite deflate dir disk_cache env expires file_cache headers include info log_config logio mime mime_magic negotiation rewrite setenvif speling status unique_id userdir usertrack vhost_alias\'
# make
# make install
# cd /usr/local/src/
# mv /usr/local/apache/conf/httpd.conf /usr/local/apache/conf/httpd.conf.old
# cp -f /usr/local/src/httpd.conf /usr/local/apache/conf/httpd.conf
# cp -f /usr/local/src/httpd /etc/init.d/httpd
# chmod 755 /etc/init.d/httpd
# chkconfig --add httpd
# chkconfig httpd on
3、编辑安装PHP所需的支持库
Libiconv
# cd /usr/local/src/
# tar zxvf libiconv-1.13.1.tar.gz
# cd libiconv-1.13.1/
# ./configure --prefix=/usr/local
# make
# make install
# cd ..
Libmcrypt
# tar zxvf libmcrypt-2.5.8.tar.gz
# cd libmcrypt-2.5.8
# ./configure
# make
# make install
# /sbin/ldconfig
# cd libltdl/
# ./configure --enable-ltdl-install
# make
# make install
# cd /usr/local/src/
Mhash
# tar zxvf mhash-0.9.9.9.tar.gz
# cd mhash-0.9.9.9/
# ./configure
# make
# make install
# cd ..
# ln -s /usr/local/lib/libmcrypt.la /usr/lib/libmcrypt.la
$ ln -s /usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.so
$ ln -s /usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4
$ ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib/libmcrypt.so.4.4.8
# ln -s /usr/local/lib/libmhash.a /usr/lib/libmhash.a
# ln -s /usr/local/lib/libmhash.la /usr/lib/libmhash.la
# ln -s /usr/local/lib/libmhash.so /usr/lib/libmhash.so
# ln -s /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2
# ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib/libmhash.so.2.0.1
$ ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config
# tar zxvf mcrypt-2.6.8.tar.gz
# cd mcrypt-2.6.8
# /sbin/ldconfig
# ./configure
# make
# make install
4、编译安装PHP
# cd /usr/local/src
# tar zxvf php-5.2.13.tar.gz
# cd php-5.2.13
# ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/etc --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 --with-apxs2=/usr/local/apache/bin/apxs --with-iconv-dir=/usr/local --with-xmlrpc --enable-xml --enable-shmop --enable-zip --with-mhash --with-mcrypt --enable-discard-path --enable-bcmath --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --with-openssl
# make ZEND_EXTRA_LIBS=\'-liconv\'
# make install
# ./libtool --finish /usr/local/src/php-5.2.13/libs
# cp php.ini-dist /usr/local/etc/php.ini
# echo \'ulimit -SHn 65535\' >> /etc/rc.local
# service httpd start
5、安装PHP扩展模块(Discuz! X1.5 用户选装)
Memcache
# cd /usr/local/src
# tar zxvf memcache-2.2.5.tgz
# cd memcache-2.2.5/
# /usr/local/php/bin/phpize
# ./configure --with-php-config=/usr/local/php/bin/php-config
# make
# make install
修改php.ini文件,路径/usr/local/etc/
查找:

  • extension_dir = \"./\"

复制代码

修改为:

  • extension_dir = \"/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/\"

复制代码

在此句下面一行
添加:

  • extension = \"memcache.so\"

复制代码

查找:

  • output_buffering = Off

复制代码

修改为:

  • output_buffering = On

复制代码

保存。

Memcached
# cd /usr/local/src
# tar zxvf libevent-1.4.13-stable.tar.gz
# cd libevent-1.4.13-stable
# ./configure --prefix=/usr/lib
# make
# make install
# cd ../
# tar zxvf memcached-1.4.5.tar.gz
# cd memcached-1.4.5
# ./configure --prefix=/usr/local --with-libevent=/usr/lib/
# make
# make install
# /usr/local/bin/memcached -d -u www -m 128
-p 监听的TCP端口 (缺省: 11211)
-d 以守护进程方式运行 以守护进程方式运行 Memcached Memcached
-u 运行运行 Memcached的账户 非root用户
-m 最大的内存使用单位是MB 缺省是64MB
-c 软连接数量缺省是1024
-v 输出警告和错误信息
-vv 打印客户端的请求和返回信息
-h 打印帮助信息
-i 打印memcached和libevent的版权信息
6、安装Zend Optimizer
# cd /usr/local/src
# tar zxvf ZendOptimizer-3.3.3-linux-glibc23-i386.tar.gz
# cd ZendOptimizer-3.3.3-linux-glibc23-i386
# ./install
Please specify the location for installing
Zend Optimizer:
这里填写Zend的安装路径,按下面写即可
/usr/local/Zend
Confirm the location of your
php.ini file:
这里填写的是php.ini的路径,按下面写即可
/usr/local/etc
Are you using Apache Web server?
这里选YES
Apache的控制组件路径
/usr/local/apache/bin/apachectl
是否重启Apache,YES,回车
7、查看确认L.A.M.P环境信息、提升 PHP 安全性
保存以下内容为info.php到/home/www/wwwroot/,检查phpinfo中的各项信息是否正确。
<div class=\"blockcode\" style=\"overflow: hidden; padding-right: 0px; padding-bottom: 5px; padding-left: 10px; background-image: url(http://www.discuz.net/static/image/common/codebg.gif); color: rgb(102, 102, 102); zoom: 1; \"><div id=\"code_6Fg\"><ol style=\"margin-left: 10px !important; \"><li style=\"padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, \'Lucida Console\', \'Courier New\', serif; font-size: 12px; line-height: 1.8em; \">
维卡官网:www.onelife.eu
发表于 2012-9-29 15:48:59 | 显示全部楼层
初来乍到,请多多关照。。。嘿嘿,回个贴表明我来过。  
维卡官网:www.onelife.eu
发表于 2012-9-29 15:48:59 | 显示全部楼层
在看完这帖子以后,我没有立即回复,因为我生怕我庸俗不堪的回复会玷污了这网上少有的帖子。但是我还是回复了,因为我觉得如果不能在如此精彩的帖子后面留下自己的网名,那我死也不会瞑目的!
维卡官网:www.onelife.eu
发表于 2012-10-21 21:20:02 | 显示全部楼层
写得好啊 估计有马甲,楼主可以认识一下吗?  
维卡官网:www.onelife.eu
发表于 2012-10-21 21:20:02 | 显示全部楼层
楼主的帖子,就好比黑暗中刺裂夜空的闪电,又好比撕开乌云的阳光,一瞬间就让我如饮甘露,让我明白了永恒的真理在这个世界上是真实存在着的。
维卡官网:www.onelife.eu
发表于 2012-11-12 09:33:55 | 显示全部楼层
先看看怎么样!  
维卡官网:www.onelife.eu
发表于 2012-11-12 09:33:55 | 显示全部楼层
先顶后看  
维卡官网:www.onelife.eu
发表于 2012-11-12 09:33:55 | 显示全部楼层
不对,就是碗是铁的,里边没饭你吃啥去?  
维卡官网:www.onelife.eu
发表于 2012-11-12 09:33:55 | 显示全部楼层
楼主你的高尚情操太让人感动了。在现在这样一个物欲横流的金钱社会里,竟然还能见到楼主这样的性情中人,无疑是我这辈子最大的幸运。让我深深感受到了人性的伟大。
维卡官网:www.onelife.eu
发表于 2012-11-15 03:28:53 | 显示全部楼层
维卡官网:www.onelife.eu
您需要登录后才可以回帖 登录 | 中文注册

本版积分规则

精彩推荐
Copyright   ©2018-2020  One生态中文学习网  Powered by©onelife     豫ICP备12023128号 豫公网安备41010302002471号