我是新手,想学学linux的下web服务器的搭建和配置其实就是搭建既支持php 又支持jsp的环境请说明版本下载地址安装配置的详细方法,希望是最新版本的!有视频教程的话 再加50分谢谢大家了!
解决方案 »
- 求高手解惑,关于struts2的session问题
- jsp代码分离问题
- 请教:对于格式文本文件,如何实现数据库存储与显示?
- jsp 虚拟目录下面的子文件夹加密问题~Tomcat 为例最好
- HttpClient 需要的jar包谁给份啊 谢谢各位大神了啊
- 求一个createStatement.executeQuery()问题?
- 谁用过jspsmart文件上传的??进来指点2招!!!急等!!
- 求高手指教
- Safari 5.1加载applet时 提示Missing plug-in 如何处理?
- SOCKET改websocket,这个连接代码改怎么写?
- ServletEx2 1.0 Java WEB 应用开发框架 完整版 (release, source, document, example 2010-01-1
- 祝福
软件源代码包存放位置 /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 (检查硬件设备是否有错误信息)
# ifconfig(检查网卡设置是否正确)
# ping www.britepic.org (检查网络是否正常)
2.关闭不需要的服务
# ntsysv
以下仅列出需要启动的服务,未列出的服务一律关闭:
atd
crond
irqbalance
microcode_ctl
network
sendmail
sshd
syslog
3.重新启动系统
# init 6
4.配置 vim
# vi /root/.bashrc
在 alias mv='mv -i' 下面添加一行:alias vi='vim' 保存退出。
# echo 'syntax on' > /root/.vimrc
5.使用yum程序安装所需软件包(以下为标准的RPM包名称)
# yum install ntp vim-enhanced gcc gcc-c++ flex bison autoconf automake bzip2-devel ncurses-devel libjpeg-devel libpng-devel libtiff-devel freetype-devel pam-devel kernel
6.定时校正服务器时钟,定时与中国国家授时中心授时服务器同步
# crontab -e
加入一行:
*/30 * * * * ntpdate 210.72.145.44
7.源代码编译安装所需包
(1) GD2
# cd /usr/local/src
# wgethttp://www.libgd.org/releases/oldreleases/gd-2.0.34.tar.gz
# tar xzvf gd-2.0.34.tar.gz
# cd gd-2.0.34
# ./configure --prefix=/usr/local/gd2
# make
# make install
(2) LibXML2
# cd /usr/local/src
# wget ftp://xmlsoft.org/libxml2/libxml2-2.6.29.tar.gz
# tar xzvf libxml2-2.6.29.tar.gz
# cd libxml2-2.6.29
# ./configure --prefix=/usr/local/libxml2
# make
# make install
(3) LibMcrypt
# cd /usr/local/src
#wgethttp://jaist.dl.sourceforge.net/sourceforge/mcrypt/libmcrypt-2.5.8.tar.bz2
# tar xjvf libmcrypt-2.5.8.tar.bz2
# cd libmcrypt-2.5.8
# ./configure –prefix=/usr/local/libmcrypt
# make
# make install
(4) Apache 日志截断程序
# cd /usr/local/src
# wgethttp://cronolog.org/download/cronolog-1.6.2.tar.gz
# tar xzvf cronolog-1.6.2.tar.gz
# cd cronolog-1.6.2
# ./configure –prefix=/usr/local/cronolog
# make
# make install
8.升级OpenSSL和OpenSSH
# cd /usr/local/src
# wgethttp://www.openssl.org/source/openssl-0.9.8e.tar.gz
# wgethttp://mirror.mcs.anl.gov/openssh/portable/openssh-4.6p1.tar.gz
# tar xzvf openssl-0.9.8e.tar.gz
# cd openssl-0.9.8e
# ./config --prefix=/usr/local/openssl
# make
# make test
# make install
# cd ..
# tar xzvf openssh-4.6p1.tar.gz
# cd openssh-4.6p1
# ./configure \
"--prefix=/usr" \
"--with-pam" \
"--with-zlib" \
"--sysconfdir=/etc/ssh" \
"--with-ssl-dir=/usr/local/openssl" \
"--with-md5-passwords"
# make
# make install
(1)禁用 SSH V1 协议
找到:
#Protocol 2,1
改为:
Protocol 2
(2)禁止root直接登录
此处先建立一个普通系统用户:
# useradd username
# passwd username
找到:
#PermitRootLogin yes
改为:
PermitRootLogin no
(3)禁用服务器端GSSAPI
找到以下两行,并将它们注释:
GSSAPIAuthentication yes
GSSAPICleanupCredentials yes
(4)禁用 DNS 名称解析
找到:
#UseDNS yeas
改为:
UseDNS no
(5)禁用客户端 GSSAPI
# vi /etc/ssh/ssh_config
找到:
GSSAPIAuthentication yes
将这行注释掉。
最后,确认修改正确后重新启动 SSH 服务
# service sshd restart
# ssh -v
确认 OpenSSH 以及 OpenSSL 版本正确。三、编译安装L.A.M.P环境
1. 下载软件
# cd /usr/local/src
# wgethttp://apache.mirror.phpchina.com/httpd/httpd-2.2.4.tar.bz2
# wgethttp://download.discuz.net/env/mysql-5.0.27.tar.gz
# wgethttp://cn.php.net/distributions/php-5.2.3.tar.bz2
#wgethttp://downloads.phpchina.com/zend/optimizer/3.3.0/ZendOptimizer-3.3.0-linux-glibc21-i386.tar.gz
2. 编译安装MySQL
# tar xzvf mysql-5.0.27.tar.gz
# cd mysql-5.0.27
# ./configure \
"--prefix=/usr/local/mysql" \
"--localstatedir=/var/lib/mysql" \ (注意:/var 分区是否适合?)
"--with-comment=Source" \
"--with-server-suffix=-Comsenz" \
"--with-mysqld-user=mysql" \
"--without-debug" \
"--with-big-tables" \
"--with-charset=" \ (此处设置MySQL默认字符集)
"--with-collation= " \ (此处设置MySQL校正字符集)
"--with-extra-charsets=all" \
"--with-pthread" \
"--enable-static" \
"--enable-thread-safe-client" \
"--with-client-ldflags=-all-static" \
"--with-mysqld-ldflags=-all-static" \
"--enable-assembler" \
"--without-isam" \
"--without-innodb" \
"--without-ndb-debug"
# make
# make install
# useradd mysql
# cd /usr/local/mysql
# bin/mysql_install_db --user=mysql
# chown -R root:mysql .
# chown -R mysql /var/lib/mysql
# cp share/mysql/my-huge.cnf /etc/my.cnf
# cp share/mysql/mysql.server /etc/rc.d/init.d/mysqld
# chmod 755 /etc/rc.d/init.d/mysqld
# chkconfig --add mysqld
# chkconfig --level 3 mysqld on
# /etc/rc.d/init.d/mysqld start
# bin/mysqladmin -u root password 'password_for_root'
3. 编译安装Apache
# cd /usr/local/src
# tar xjvf httpd-2.2.4.tar.bz2
# cd httpd-2.2.4
# ./configure \
"--prefix=/usr/local/apache2" \
"--with-included-apr" \
"--enable-so" \
"--enable-deflate=shared" \
"--enable-expires=shared" \
"--enable-rewrite=shared" \
"--enable-static-support" \
"--disable-userdir"
# make
# make install
# echo '/usr/local/apache2/bin/apachectl start ' >> /etc/rc.local
4. 编译安装PHP
# cd /usr/local/src
# tar xjvf php-5.2.3.tar.bz2
# cd php-5.2.3
# ./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-openssl=/usr/local/openssl" \
"--with-mcrypt=/usr/local/libmcrypt" \
"--enable-soap" \
"--enable-gd-native-ttf" \
"--enable-memory-limit" \
"--enable-ftp" \
"--enable-mbstring" \
"--enable-exif" \
"--disable-ipv6" \
"--disable-cgi" \
"--disable-cli"
# make
# make install
# mkdir /usr/local/php/etc
# cp php.ini-dist /usr/local/php/etc/php.ini
5. 安装Zend Optimizer
# cd /usr/local/src
# tar xzvf ZendOptimizer-3.2.8-linux-glibc21-i386.tar.gz
# ./ZendOptimizer-3.2.8-linux-glibc21-i386/install.sh
安装Zend Optimizer过程的最后不要选择重启Apache。
6. 整合Apache与PHP
# vi /usr/local/apache2/conf/httpd.conf
找到:
AddType application/x-gzip .gz .tgz
在该行下面添加
AddType application/x-httpd-php .php
找到:
<IfModule dir_module>
DirectoryIndex index.html
</IfModule>
将该行改为
<IfModule dir_module>
DirectoryIndex index.html index.htm index.php
</IfModule>
找到:
#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 个扩展配置文件中的设置请按照相关原则进行合理配置!
修改完成后保存退出。
# /usr/local/apache2/bin/apachectl restart
7. 查看确认L.A.M.P环境信息、提升 PHP 安全性
在网站根目录放置 phpinfo.php 脚本,检查phpinfo中的各项信息是否正确。
#vi phpinfo.php
<?php
phpinfo();
?>
确认 PHP 能够正常工作后,在 php.ini 中进行设置提升 PHP 安全性。
# vi /etc/php.ini
找到:
disable_functions =
设置为:
phpinfo,passthru,exec,system,chroot,scandir,chgrp,chown,escapeshellcmd,escapeshellarg,shell_exec,proc_open,proc_get_status,error_log,ini_alter,ini_alter,ini_restore,dl,pfsockopen,openlog,syslog,readlink,symlink,leak,popepassthru,stream_socket_server
三、服务器安全性设置
1. 设置系统防火墙
# touch /usr/local/sbin/fw.sh
将以下脚本命令(绿色部分)粘贴到 fw.sh 文件中。
#!/bin/bash
# Stop iptables service first
service iptables stop
# Load FTP Kernel modules
/sbin/modprobe ip_conntrack_ftp
/sbin/modprobe ip_nat_ftp
# Inital chains default policy
/sbin/iptables -F -t filter
/sbin/iptables -P INPUT DROP
/sbin/iptables -P OUTPUT ACCEPT
# Enable Native Network Transfer
/sbin/iptables -A INPUT -i lo -j ACCEPT
# Accept Established Connections
/sbin/iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
# ICMP Control
/sbin/iptables -A INPUT -p icmp -m limit --limit 1/s --limit-burst 10 -j ACCEPT
# WWW Service
/sbin/iptables -A INPUT -p tcp --dport 80 -j ACCEPT
# FTP Service
/sbin/iptables -A INPUT -p tcp --dport 21 -j ACCEPT
# SSH Service
/sbin/iptables -A INPUT -p tcp --dport 22 -j ACCEPT
# chmod 755 /usr/local/sbin/fw.sh
# echo '/usr/local/sbin/fw.sh' >> /etc/rc.local
# /usr/local/sbin/fw.sh
本文介绍 suse linux 下简单WEB环境的配置方法:
1 安装软件。
一、准备软件包
存放/home/xiutuo/software/目录下。
主要软件包,(这里没有选择 mysql-standard-5.0.20-linux-i686.tar.gz,呆会再说明原因。)
httpd-2.2.0.tar.gz
mysql-max-5.0.21-linux-i686-glibc23.tar.gz
php-5.1.2.tar.gz
安装 php所需的软件包
(其中 libxml2 是安装 php5 必须的,为什么还需要 perl 呆会说明原因。)
libxml2-2.6.19.tar.gz
libxslt-1.1.15.tar.gz
ActivePerl-5.8.8.817-i686-linux-2.2.17-gcc-257965.rpm
curl-7.15.0.tar.gz
GD库所需要软件包(有人说 PHP 源码包里自带了 GD2.0.28 和 zlib,只要安装 GD 的三个支持包:jpg,png
和freetype,但是我们还是下载)
gd-2.0.33.tar.gz
freetype-2.1.10.tar.gz
jpegsrc.v6b.tar.gz
libpng-1.2.8.tar.gz
zlib-1.2.3.tar.gz
相关下载(根据自己的 linux 版本下载相应的包,查看操作系统版本:# uname -r )
http://ftp.gnome.org/pub/GNOME/sour...2-2.6.19.tar.gz
http://ftp.gnome.org/pub/GNOME/sour...t-1.1.15.tar.gz
http://downloads.activestate.com/Ac...-i686-linux.rpm
http://curl.haxx.se/download/curl-7.15.0.tar.gz
http://www.boutell.com/gd/http/gd-2.0.33.tar.gz
http://keihanna.dl.sourceforge.net/...e-2.1.10.tar.gz
http://www.ijg.org/files/jpegsrc.v6b.tar.gz
http://nchc.dl.sourceforge.net/sour...ng-1.2.8.tar.gz
http://www.zlib.net/zlib-1.2.3.tar.gz 以上地址可能有些已经不能使用,这里推荐使用http://www.filewatcher.com查找相应的软件包.把以上所有软件包下载到:/home/xiutuo/software/目录下。
二、安装 apache2。
# cd /home/xiutuo/software/
进入目录/home/xiutuo/software/
# tar -zvxf httpd-2.2.0.tar.gz
解压 httpd-2.2.0.tar.gz
# cd httpd-2.2.0
进入 httpd-2.2.0 目录
# mkdir -p /usr/local/apache2
生成/usr/local/apache2 目录 # ./configure --prefix=/usr/local/apache
或者
# ./configure --prefix=/usr/local/apache --enable-modules=so --enable-rewrite
# make; make install
安装 apache
# vi /usr/local/apache/conf/httpd.conf
#ServerName www.example.com:80 在其下增加
ServerName www.xiutuo.com:80
保存退出,现在就这么简单配置 apache。
# /usr/local/apache/bin/apachectl -k start
启动 apahce,
用浏览器查看 http://www.xiutuo.com,得到 it works,说明 apache 已经配置成功了。
# /usr/local/apache/bin/apachectl -k stop
停止 apache。
三、安装 mysql
# cd /home/xiutuo/software/
# tar -zvxf mysql-max-5.0.21-linux-i686-glibc23.tar.gz
# mkdir -p /usr/local/mysql (省略也可)
# cp -r mysql-max-5.0.21-linux-i686-glibc23.tar.gz /usr/local/mysql
# cp /usr/local/mysql/support-files/my-medium.cnf /etc/my.cnf
添加 mysql 用户及用户组
# groupadd mysql
# useradd -g mysql mysql
修改 mysql 目录权限
# chown -R root /usr/local/mysql
# chgrp -R mysql /usr/local/mysql
# chown -R mysql /usr/local/mysql/data
生成 mysql 系统数据库
#/cp /usr/local/mysql/scripts/mysql_install_db ../
# /usr/local/mysql/mysql_install_db --user=mysql&
启动 mysql 服务
# /usr/local/mysql/bin/mysqld_safe --user=mysql&
如出现 Starting mysqld daemon with databases from /usr/local/mysql/data
代表正常启动 mysql 服务了, 按 Ctrl + C 跳出
修改 mysql 的 root 密码
# /usr/local/mysql/bin/mysqladmin -u root -p password "123456"
如果在安装的过程中,mysql 不是被安装在/usr/local/mysql,注意调整../mysql/bin/mysqld_safe 这个
文件中的路径。
四、安装 GD 库(让PHP 支持 GIF,PNG,JPEG)
a.安装 jpeg6
建立目录:
# mkdir -p /usr/local/jpeg6
# mkdir -p /usr/local/jpeg6/bin
# mkdir -p /usr/local/jpeg6/lib # mkdir -p /usr/local/jpeg6/include
# mkdir -p /usr/local/jpeg6/man
# mkdir -p /usr/local/jpeg6/man1
# mkdir -p /usr/local/jpeg6/man/man1
# cd /home/xiutuo/software/
# tar -zvxf jpegsrc.v6b.tar.gz
# cd jpeg-6b
# ./configure --prefix=/usr/local/jpeg6 --enable-shared --enable-static
# make; make install
b.安装 libpng
# cd /home/xiutuo/software/
# tar -zvxf libpng-1.2.8.tar.gz
# cd libpng-1.2.8
# cp scripts/makefile.std makefile
# make; make install
c.安装 freetype
# cd /home/xiutuo/software/
# tar -zvxf freetype-2.1.10.tar.gz
# cd freetype-2.1.10
# mkdir -p /usr/local/freetype
# ./configure --prefix=/usr/local/freetype
# make;make install
d.:安装 zlib
# cd /home/xiutuo/software/
#tar -zxvf zlib-1.2.3.tar.gz
#cd zlib.1.2.3
# ./configure
# make;make install
e.安装 GD 库
# cd /home/xiutuo/software/
# tar -zvxf gd-2.0.33.tar.gz
# mkdir -p /usr/local/gd2
# cd gd-2.0.33
# ./configure --prefix=/usr/local/gd2 --with-jpeg=/usr/local/jpeg6/ --with-png=/usr/local/li
b/ --with-zlib=/usr/local/lib/ --with-freetype=/usr/local/freetype/
# make; make install
e.安装 Curl 库
# cd /home/xiutuo/software/
# tar -zxf curl-7.15.0.tar.gz
# mkdir -p /usr/local/curl
# ./configure --prefix=/usr/local/curl
# make; make install
五、安装 php5,php5 必须有 libxml2 支持!
a.安装 libxml2 # cd /home/xiutuo/software/
# tar -zxf libxml2-2.6.19.tar.gz
# cd libxml2-2.6.19
# mkdir -p /usr/local/libxml2
# ./configure --prefix=/usr/local/libxml2
# make; make install
b.安装 libxslt(可选安装,你可以不安装)
# cd /home/xiutuo/software/
# tar -zxf libxslt-1.1.15.tar.gz
# mkdir -p /usr/local/libxslt
# cd libxslt-1.1.15
# ./configure --prefix=/usr/local/libxslt --with-libxml-prefix=/usr/local/libxml2
# make; make install
c.安装 php5
# cd /home/xiutuo/software/
# tar -zvxf php-5.1.2.tar.gz
# mkdir -p /usr/local/php
# cd php-5.05
# ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache/bin/apxs
--with-mysql=/usr/local/mysql/
--with-curl=/usr/local/curl --enable-ftp
--with-libxml-dir=/usr/local/libxml2
--with-expat-dir=/usr/lib --enable-soap
--with-xsl=/usr/local/libxslt --enable-xslt
--with-gd=/usr/local/gd2/
--with-jpeg-dir=/usr/local/jpeg6/
--with-zlib-dir=/usr/local/lib/
--with-png=/usr/local/lib/
--with-freetype-dir=/usr/local/freetype/
//…编译程序时提示下面的信息解决方
法: configure: error: cannot find output from lex; giving up 方法很简单,在编译语句之前执行命
令: touch lex.yy.c 这样就 OK 了…//
# make
# make install
# cp php.ini-dist /usr/local/php/lib/php.ini (别忘记了呵呵)
其中./configure 后的
--prefix=/usr/local/php
--with-apxs2=/usr/local/apache/bin/apxs
--with-mysql=/usr/local/mysql/
--with-libxml-dir=/usr/local/libxml2
是必要的选项
--with-gd=/usr/local/gd2/
--with-jpeg-dir=/usr/local/jpeg6/
--with-png=/usr/local/lib --with-zlib-dir=/usr/lib
--with-freetype-dir=/usr/local/freetype
这是让 PHP 支持 GD库的配置选项
--with-curl=/usr/local/curl 支持 CURL 库
--enable-ftp 打开 FTP库函数支持
--enable-soap --with-xsl=/usr/local/libxslt --enable-xslt
让PHP 支持 SOAP, 上面这些一般用得少, 可以去掉
六、重新配置 apache2 让他支持 php。
配置 httpd.conf 让 apache 支持 PHP
# vi /usr/local/apache/conf/httpd.conf
找到 AddType application/x-gzip .gz .tgz 在其下添加如下内容
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
重启 apache
# /usr/local/apache/bin/apachectl restart
在htdocs 目录里建一内容为 PHP 文件, 输入 URL地址查看 PHP 配置是否正确 2 安装中出现的问题
1、当你看到 mysql 有很多版本,如:
mysql-max-5.0.21-linux-i686-glibc23.tar.gz 和
mysql-max-5.0.21-linux-i686.tar.gz
这俩个到底选哪个呢,请你使用如下命令来决定
# rpm -qa | grep glibc
glibc-kernheaders-2.4-8.10
glibc-common-2.3.2-11.9
glibc-2.3.2-11.9
glibc-devel-2.3.2-11.9
如果出现以上信息,请选择 mysql-max-5.0.21-linux-i686-glibc23.tar.gz 版本
2、编译 php 时出现
./configure: /usr/local/apache2/bin/apxs:
/replace/with/path/to/perl/interpreter:
bad interpreter: No such file or directory
这是找不到 perl 解释器的缘故。
修改/usr/local/apache2/bin/apxs 文件中:
/replace/with/path/to/perl/interpreter
把他替换成 perl 所在的路径如/opt/ActivePerl-5.8/bin/perl,
(如果你下载的是 active perl5.8的 rpm,他默认安装路径是/opt/ActivePerl-5.8/bin/perl)
3、安装了 perl 后,发现所有的文本编辑器都不能用了。
运行 vi或者 gedit 时候,提示找不到 libperl.so
到perl 的安装目录下找一个 libperl.so 放到/usr/lib 目录下就解决问题了
我的 libperl.so 在/opt/ActivePerl-5.8/lib/5.8.8/i686-linux-thread-multi-CORE/目录下。
如果不知道 libperl.so在什么地方,可以用
# locate libperl.so 查找,或者用 find 命令
4、当我使用 mysql-standard-5.0.20,编译 php 时出现 mysql 错误:
checking for mSQL support... no
checking for MSSQL support via FreeTDS... no
checking for MySQL support... yes
checking for specified location of the MySQL UNIX socket... no
checking for MySQL UNIX socket location... /tmp/mysql.sock
checking for mysql_close in -lmysqlclient... no
checking for mysql_error in -lmysqlclient... no
configure: error: mysql configure failed. Please check config.log
for more information.
网查找说:安装 PHP 的时候没有指定一下 mysql 的安装目录。但是我已经指定了,所以这个说法是错误的,
其实主要原因是 mysql-level 没有装,也就是 mysql 的版本不对,应该换 mysql-max-5.0.21 版本(包含
所有 mysql 相关内容的软件包)
5、编译 php 时出现
configure: error: freetype2 not found!
没有安装 freetype-level
configure: error: libpng.(a|so) not found.
没有安装 libpng-devel
6、忘了 mysql 的 root 口令怎么办
# /usr/local/mysql/support-files/mysql.server stop
# mysqld_safe --skip-grant-tables &
# mysqladmin -u user password 'newpassword'
# mysqladmin flush-privileges