检查相关依赖包是否安装
- [root@localhost ~]# for i in gcc gcc-c++ flex bison autoconf automake bzip2-devel ncurses-devel libjpeg-devel libpng-devel libtiff-devel freetype-devel pam-devel ; do rpm -q $i ;done
gcc-4.1.2-48.el5
gcc-c++-4.1.2-48.el5
flex-2.5.4a-41.fc6
bison-2.3-2.1
autoconf-2.59-12
automake-1.9.6-2.3.el5
bzip2-devel-1.0.3-4.el5_2
bzip2-devel-1.0.3-4.el5_2
ncurses-devel-5.5-24.20060715
ncurses-devel-5.5-24.20060715
libjpeg-devel-6b-37
libjpeg-devel-6b-37
libpng-devel-1.2.10-15.el5_7
libpng-devel-1.2.10-15.el5_7
libtiff-devel-3.8.2-7.el5_6.7
libtiff-devel-3.8.2-7.el5_6.7
freetype-devel-2.2.1-28.el5_7.2
freetype-devel-2.2.1-28.el5_7.2
pam-devel-0.99.6.2-6.el5_4.1
pam-devel-0.99.6.2-6.el5_4.1
没有yum install 安装之
编译安装源码包
gd2
- tar -xf gd-2.0.34.tar.gz
- cd gd-2.0.34
- ./configure --prefix=/usr/local/gd2
- make && make install
libxml2
一个xml c语言版的解析器
- tar xf libxml2-2.7.2.tar.gz
- cd libxml2-2.7.2
- ls
- ./configure --prefix=/usr/local/libxml2
- make && make install
编译安装libmcrypt
libmcrypt是加密算法扩展库。支持DES, 3DES, RIJNDAEL, Twofish, IDEA, GOST, CAST-256, ARCFOUR, SERPENT, SAFER+等算法
- tar -xf libmcrypt-2.5.8.tar.bz2
- cd libmcrypt-2.5.8
- ./configure --prefix=/usr/local/libmcrypt
- make && make install
编译安装openssl
为网络通信提供安全及数据完整性的一种安全协议,囊括了主要的密码算法、常用的密钥和证书封装管理功能以及SSL协议
- ./config --prefix=/usr/local/openssl
- make
- make test
- make install
编译安装mysql
- [root@localhost mysql-5.0.27]# ./configure \
- > --prefix=/usr/local/mysql \
- > --localstatedir=/var/lib/mysql \
- > --with-mysqld-user=mysql \
- > --without-debug \
- > --with-big-tables \
- > --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
- id 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/init.d/mysqld
- chmod 755 /etc/init.d/mysqld
- chkconfig --add mysqld
- chkconfig mysqld on
- service mysqld start
- bin/mysqladmin -u root password newbie
- ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql 建议做个符号链接到/usr/bin,也可以加到PATH,不过这样PATH会很乱。
- 或者我现在笔记本的做法,放/home/bin,然后这个放到PATH
编译安装apache
- [root@localhost httpd-2.2.9]# ./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
编译安装php
4. 编译安装PHP
- 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-jpeg-dir" \
- "--with-png-dir" \
- "--with-bz2" \
- "--with-freetype-dir" \
- "--with-iconv-dir" \
- "--with-zlib-dir " \
- "--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
:Zend Optimizer用优化代码的方法来提高PHP应用程序的执行速度。实现的原理是对那些在被最终执行之前由运行编译器(Run-Time Compiler)产生的代码进行优化。
- 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。
整合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中的各项信息是否正确。
<?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