需要安装的软件:
MYSQL安装
- mysql-5.0.56.tar.gz
- libiconv-1.13.1.tar.gz
- http-2.2.15.tar.gz
- php-5.2.13.tar.gz
- eaccelerator-0.9.6.1.tar.bz2
- memcache-2.2.5.tgz
- PDO_MYSQL-1.0.2.tgz
- ImageMagick-6.6.1-10.tar.gz
- imagick-2.3.0.tgz
- ZendOptimizer-3.3.9-linux-glibc23-i386.tar.gz
- groupadd mysql
- useradd -s /sbin/nologin -g mysql -M mysql
- tar zxvf mysql-5.0.56.tar.gz
- cd mysql-5.0.56
- ./configure \
- --prefix=/usr/local/mysql \
- --with-unix-socket-path=/usr/local/mysql/tmp/mysql.sock \
- --localstatedir=/usr/local/mysql/data \
- --enable-assembler \
- --enable-thread-safe-client \
- --with-mysqld-user=mysql \
- --with-big-tables \
- --without-debug \
- --with-pthread \
- --enable-assembler \
- --with-extra-charsets=complex \
- --with-readline \
- --with-ssl \
- --with-embedded-server \
- --enable-local-infile \
- --with-plugins=partition,innobase \
- --with-plugin-PLUGIN \
- --with-mysqld-ldflags=-all-static \
- --with-client-ldflags=-all-static
- make
- make install
- cp support-files/my-small.cnf /etc/my.cnf
- mkdir -p /usr/local/mysql/data
- /usr/local/mysql/bin/mysql_install_db --user=mysql
- chgrp -R mysql /usr/local/mysql
- /usr/local/mysql/bin/mysqld_safe --user=mysql&
- ps -ef |grep mysql
- echo "export PATH=$PATH:/usr/local/mysql/bin/">>/etc/profile #设置环境变量
- source /etc/profile
- cp support-files/mysql.server /etc/init.d/mysqld #设置为service启动方式
- chmod 755 /etc/init.d/mysqld
- chkconfig --add mysqld #添加为开机自启动
- service mysqld restart
- cd ..
- mysqladmin -uroot password elain //设置密码
- mysql -uroot -p
APACHE安装 首先检查 PHP LIB库是否缺
- rpm -qa zlib libxml libjpeg freetype libpng gd curl libico \
- zlib-devel libxml2-devel libjpeg-devel freetype-devel libpng-devel gd-devel curl-devel
若未安装,可手动安装或用:
- yum groupinstall "x software development"
安装 libiconv 库
- tar zxvf libiconv-1.13.1.tar.gz
- cd libiconv-1.13.1
- ./configure --prefix=/usr/local/libiconv
- make
- make install
- cd ..
开始安装apache
- tar zxvf httpd-2.2.15.tar.gz
- cd httpd-2.2.15
- ./configure \
- --prefix=/application/apache2.2.15 \
- --enable-deflate \
- --enable-headers \
- --enable-modules=so \
- --enable-so \
- --with-mpm=worker \
- --enable-rewrite \
- --enable-cgi \
- --enable-file-cache \
- --enable-cache \
- --enable-disk-cache \
- --enable-mem-cache
- make
- make install
- ln -s /application/apache2.2.15 /usr/local/apache
- cp /usr/local/apache/bin/apachectl /etc/init.d/httpd
- cd ..
- chmod -R 755 /etc/init.d/httpd
- echo "/usr/local/apache/bin/apachectl start" >>/etc/rc.local
PHP安装
- tar zxvf php-5.2.13.tar.gz
- cd php-5.2.13
- ./configure \
- --prefix=/usr/local/php \
- --with-apxs2=/application/apache2.2.15/bin/apxs \
- --with-mysql=/usr/local/mysql \
- --with-ttf \
- --with-xmlrpc \
- --with-openssl \
- --with-zlib \
- --with-freetype-dir \
- --with-gd \
- --with-jpeg-dir \
- --with-png-dir \
- --with-iconv=/usr/local/libiconv \
- --enable-short-tags \
- --enable-sockets \
- --enable-zend-multibyte \
- --enable-soap \
- --enable-mbstring \
- --enable-static \
- --enable-gd-native-ttf \
- --with-curl
- make
- make install
- cp php.ini-recommended /usr/local/php/lib/php.ini
- cd ..
- vi /etc/selinux/config
将SELINUX=enforcing 改成SELINUX=disabled 需要重启 //关闭SELINUX 配置httpd.conf
- vi /usr/local/apache/conf/httpd.conf
#修改 damon用户为 apache (约65行)
- User apache
- Group apache
#注:若系统不存在apache用户,请执行如下命令建立
- useradd apache -M -s /sbin/nologin
- vim /application/apache2.2.15/conf/httpd.conf
#在#ServerName www.example.com:80(约98行)下添加
- ServerName 127.0.0.1:80
#在DirectoryIndex index.html处(约168行)添加
- DirectoryIndex index.html index.php
#在AddType application/x-compress .Z
- AddType application/x-gzip .gz .tgz #(约309行)下添加
- AddType application/x-httpd-php .php .php3
- AddType application/x-httpd-php-source .phps
- /usr/local/apache/bin/apachectl -t #检查httpd.conf文件的语法
- Syntax OK
- tail -100 /application/apache/logs/error_log #检查错误日志
- service httpd start
添加php测试文件
- vim /application/apache2.2.15/htdocs/info.php
- <?php
- phpinfo();
- ?>;
- service httpd start
访问http://10.0.0.83/info.php
看到上图,说成LAMP环境初步搭建成功!!
以下是LMAP环境的优化及扩展配置
PHP扩展缓存加速安装
- tar jxvf eaccelerator-0.9.6.1.tar.bz2
- cd eaccelerator-0.9.6.1
- /usr/local/php/bin/phpize
- ./configure --enable-eaccelerator=shared --with-php-config=/usr/local/php/bin/php-config
- make
- make install
- cd ..
- 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
- cd ..
- tar zxvf PDO_MYSQL-1.0.2.tgz
- cd PDO_MYSQL-1.0.2
- /usr/local/php/bin/phpize
- ./configure \
- --with-php-config=/usr/local/php/bin/php-config --with-pdo-mysql=/usr/local/mysql
- make
- make install
- cd ..
- tar zxvf ImageMagick-6.6.1-10.tar.gz
- cd ImageMagick-6.6.1-10
- ./configure
- make
- make install
- cd ..
- tar zxvf imagick-2.3.0.tgz
- cd imagick-2.3.0
- /usr/local/php/bin/phpize
- ./configure --with-php-config=/usr/local/php/bin/php-config
- make
- make install
- cd ..
- tar zxvf ZendOptimizer-3.3.9-linux-glibc23-i386.tar.gz
- cd ZendOptimizer-3.3.9-linux-glibc23-i386
- cd data/5_2_x_comp
- cp ZendOptimizer.so /usr/local/php/lib/php/extensions/no-debug-zts-20060613/
- cd ..
- ll /usr/local/php/lib/php/extensions/no-debug-zts-20060613/
#检查
须看到以上信息
配置相关PHP的扩展
- vi /usr/local/php/lib/php.ini
#查找 extension_dir=”./” (约542行)
#添加路径
#在结尾处添加下面几行,保存退出
- extension_dir = "/usr/local/php/lib/php/extensions/no-debug-zts-20060613/"
- extension=memcache.so
- extension=pdo_mysql.so
- extension=imagick.so
#配置eaccelerator加速PHP解析
- mkdir -p /tmp/eaccelerator
- chmod -R 777 /tmp/eaccelerator
- vi /usr/local/php/lib/php.ini
在结尾处添加下面几行
- [eaccelerator]
- extension=eaccelerator.so
- eaccelerator.shm_size="64"
- eaccelerator.cache_dir="/tmp/eaccelerator"
- eaccelerator.enable="1"
- eaccelerator.optimizer="1"
- eaccelerator.check_mtime="1"
- eaccelerator.debug="0"
- eaccelerator.filter=""
- eaccelerator.shm_max="0"
- eaccelerator.shm_ttl="3600"
- eaccelerator.shm_prune_period="3600"
- eaccelerator.shm_only="0"
- eaccelerator.compress="1"
- eaccelerator.compress_level="9"
检查
- /usr/local/php/bin/php –v
也可访问 http://10.0.0.83/info.php 图形化查看PHP扩展 日志轮询工具cronolog的安装 ————————————–
- tar zxvf cronolog-1.6.2.tar.gz
- cd cronolog-1.6.2
- ./configure
- make
- make install
- cd ..
注:此工具是用用记录网站访问记录的,在下面的虚拟主机配置中用到 —————————————– apache虚拟主机 ——————————————-
- vi /application/apache2.2.15/conf/httpd.conf
找到
- #Include conf/extra/httpd-vhosts.conf
取消 Include 前的注释(约391行) //开启httpd-vhosts.conf配置
- cd /application/apache2.2.15/conf/extra
- vi httpd-vhosts.conf
删除27-42行默认的apache虚拟主机的配置
- 27<VirtualHost *:80>
- …………
- 42</VirtualHost>
末尾添加新配置:
- <VirtualHost *:80>
- ServerAdmin [email protected]
- DocumentRoot "/application/apache2.2.15/htdocs/wiki"
- ServerName wiki.cgzg.net
- ErrorLog "logs/wiki-error.log"
- CustomLog "|/usr/local/sbin/cronolog logs/wiki_access_%Y%m%d%H%.log"combined
- </VirtualHost> #注:加粗一行是用轮询工具按天记日志,按周循环覆盖
- <VirtualHost *:80>
- ServerAdmin [email protected]
- DocumentRoot "/application/apache2.2.15/htdocs/blog"
- ServerName blog.cgzg.net
- ErrorLog "logs/blog-error.log"
- CustomLog "|/usr/local/sbin/cronolog logs/blog_access_%Y%m%d%H%.log"combined
- </VirtualHost>
建立网站目录
- mkdir -p /usr/local/apache/htdocs/wiki
- mkdir -p /usr/local/apache/htdocs/blog
- /application/apache2.2.15/bin/apachectl configtest #检查语法是否正确
- service httpd start
注:如果是实验环境,需把客户机上的hosts修改
安装wiki网站程序
——————————————–
WIKI网站程序地址 http://kaiyuan.hudong.com/down.php, 选择utf8 编码
- cd /application/apache2.2.15/htdocs/wiki
#下载wiki 程序包
- unzip HDWiki-v5.0UTF8-20100917.zip
- rm -rf *.txt *.zip
- rm -Rf document/
- cd hdwiki/
- mv * ../
- rm –Rf
- rm -Rf hdwiki/
- vi /usr/local/php/lib/php.ini #查找short_open_tag (约132行)改为:
- short_open_tag = On
- service httpd restart
在DB1 3306数据库里为wiki 创建一个数据库
- mysql -uroot -p -S /data/3306/mysql.sock
#登录mysql 输入密码elain
- create database wiki; #建立数据库
- grant all privileges on wiki.* to 'elain'@'10.0.10.%' identified by 'elain';
#建立wiki的帐号elain,密码elain,并授权管理wiki这个库
注:’10.0.0.%’ 这里的“%”表示10.0.10这个网段都可访问
- chmod -R ./uploads/ ./data/ ./config.php ./plugins/ ./style/
#按安装要求更改网站程序相应目录的权限为777
填写数据库信息:(如下图)
上图为设置管理员帐号admin 及密码 123456
删除整个 install 目录或把install.php改名,以免被他人恶意利用。
rm -Rf install/
访问 http://wiki.cgzg.net
登录进去写入数据进行测试!
看到以上页面即安装成功!!
到此,LAMP 架设完成!!
转载请注明: 转载自http://www.elain.org
本文链接地址:[跟我学中小企业架构部署]之四:WEB服务器LAMP部署