apache的安装参考
http://fengwan.blog.51cto.com/508652/1360429
MySQL的安装参考
http://fengwan.blog.51cto.com/508652/1363566
一.环境准备
apache的安装路径为/webserver/httpd
MySQL的安装路径为/webserver/mysql
1.依赖包的安装
1 | [root@WebServer ~] # yum install -y gd-devel ncurses-devel libxml2-devel bzip2-devel libcurl-devel curl-devel libjpeg-devel libpng-devel freetype-devel net-snmp-devel |
2.PHP支持库的安装
用到的软件有
eaccelerator-eaccelerator-42067ac.tar.gz
ImageMagick.tar.gz
imagick-3.1.2.tgz
libevent-2.0.21-stable.tar.gz
libiconv-1.14.tar.gz
libmcrypt-2.5.8.tar.gz
mcrypt-2.6.8.tar.gz
memcache-2.2.7.tgz
memcached-1.4.17.tar.gz
mhash-0.9.9.9.tar.gz
php-5.4.25.tar.gz
12345678910111213141516171819202122232425262728 | [root@WebServer ~] # tar zxvf libiconv-1.14.tar.gz [root@WebServer ~] # cd libiconv-1.14 [root@WebServer libiconv-1.14] # ./configure --prefix=/webserver/libiconv [root@WebServer libiconv-1.14] # make && make install [root@WebServer libiconv-1.14] # cd .. [root@WebServer ~] # tar zxvf libmcrypt-2.5.8.tar.gz [root@WebServer ~] # cd libmcrypt-2.5.8 [root@WebServer libmcrypt-2.5.8] # ./configure [root@WebServer libmcrypt-2.5.8] # make && make install [root@WebServer libmcrypt-2.5.8] # /sbin/ldconfig [root@WebServer libmcrypt-2.5.8] # cd libltdl/ [root@WebServer libltdl] # ./configure --enable-ltdl-install [root@WebServer libltdl] # make && make install [root@WebServer libltdl] # cd ../.. [root@WebServer ~] # tar zxvf mhash-0.9.9.9.tar.gz [root@WebServer ~] # cd mhash-0.9.9.9 [root@WebServer mhash-0.9.9.9] # ./configure [root@WebServer mhash-0.9.9.9] # make && make install [root@WebServer mhash-0.9.9.9] # cd /usr/lib64/ [root@WebServer lib64] # ln -s /usr/local/lib/* . [root@WebServer lib64] # ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config [root@WebServer lib64] # cd [root@WebServer ~] # tar zxvf mcrypt-2.6.8.tar.gz [root@WebServer ~] # cd mcrypt-2.6.8 [root@WebServer mcrypt-2.6.8] # /sbin/ldconfig [root@WebServer mcrypt-2.6.8] # ./configure [root@WebServer mcrypt-2.6.8] # make && make install [root@WebServer mcrypt-2.6.8] # cd .. |
二.开始编译安装PHP
1.解压PHP并进入安装目录
12 | [root@WebServer ~] # tar zxvf php-5.4.25.tar.gz [root@WebServer ~] # cd php-5.4.25 |
2.编译PHP
1 | [root@WebServer php-5.4.25] # ./configure --prefix=/webserver/php --with-config-file-path=/webserver/php/etc --with-apxs2=/webserver/httpd/bin/apxs --with-mysql=/webserver/mysql/ --with-mysqli=/webserver/mysql/bin/mysql_config --with-pdo-mysql=/webserver/mysql/ --with-iconv-dir=/webserver/libiconv/ --disable-phar --with-pcre-regex --with-zlib --with-bz2 --enable-calendar --with-curl --enable-dba --with-libxml-dir --enable-ftp --with-gd --with-jpeg-dir --with-png-dir --with-zlib-dir --with-freetype-dir --enable-gd-native-ttf --enable-gd-jis-conv --with-mhash --enable-mbstring --with-mcrypt --enable-pcntl --enable-xml --disable-rpath --enable-shmop --enable-sockets --enable-zip --enable-bcmath --with-snmp --disable-ipv6 --with-gettext |
另外一个版本
1 | . /configure --prefix= /usr/local/php5 .5.32 --with-config- file -path= /usr/local/php5 .5.32 /etc --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-iconv- dir = /usr/local/libiconv1 .14 --disable-phar --with-pcre-regex --with-zlib --with-bz2 -- enable -calendar --with-curl -- enable -dba --with-libxml- dir -- enable - ftp --with-gd --with-jpeg- dir --with-png- dir --with-zlib- dir --with-freetype- dir -- enable -gd-native-ttf -- enable -gd-jis-conv --with-mhash -- enable -mbstring --with-mcrypt -- enable -pcntl -- enable -xml --disable-rpath -- enable -shmop -- enable -sockets -- enable -zip -- enable -bcmath --with-snmp --disable-ipv6 --with-gettext -- enable -opcache -- enable -fpm --with-fpm-user=www --with-fpm-group=www |
3.安装
12 | [root@WebServer php-5.4.25] # make [root@WebServer php-5.4.25] # make install |
4.复制php配置文件
1 | [root@WebServer php-5.4.25] # cp php.ini-production /webserver/php/etc/php.ini |
三.编译安装PHP的扩展模块
1.安装memcache
123456789101112 | [root@WebServer ~] # tar zxvf memcache-2.2.7.tgz [root@WebServer ~] # cd memcache-2.2.7 [root@WebServer memcache-2.2.7] # /webserver/php/bin/phpize Configuring for : PHP Api Version: 20100412 Zend Module Api No: 20100525 Zend Extension Api No: 220100525 [root@WebServer memcache-2.2.7] # ./configure --enable-memcache --with-php-config=/webserver/php/bin/php-config [root@WebServer memcache-2.2.7] # make [root@WebServer memcache-2.2.7] # make install Installing shared extensions: /webserver/php/lib/php/extensions/no-debug-zts-20100525/ [root@WebServer memcache-2.2.7] # cd .. |
2.安装memcached
123456789101112 | [root@WebServer ~] # tar zxvf libevent-2.0.21-stable.tar.gz [root@WebServer ~] # cd libevent-2.0.21-stable [root@WebServer libevent-2.0.21-stable] # ./configure --prefix=/webserver/libevent [root@WebServer libevent-2.0.21-stable] # make && make install [root@WebServer libevent-2.0.21-stable] # cd .. [root@WebServer ~] # tar zxvf memcached-1.4.17.tar.gz [root@WebServer ~] # cd memcached-1.4.17 [root@WebServer memcached-1.4.17] # ./configure --prefix=/webserver/memcached --with-libevent=/webserver/libevent [root@WebServer memcached-1.4.17] # make && make install [root@WebServer memcached-1.4.17] # cd .. #启动memcached,使用如下命令: [root@WebServer ~] # /webserver/memcached/bin/memcached -d -m 512 -c 2048 -p 11211 -P /tmp/memcached.pid -u nobody |
memcached启动参数:
-p 指定端口号(默认11211)
-U <num> UDP监听端口 (默认: 11211, 0 时关闭)
-s <file> 用于监听的UNIX套接字路径(禁用网络支持)
-a <mask> UNIX套接字访问掩码,八进制数字(默认:0700)
-m 指定最大使用内存大小(默认64MB)
-t 线程数(默认4)
-l <ip_addr> 绑定地址 (默认:所有都允许,无论内外网或者本机更换IP,有安全隐患,若设置为127.0.0.1就只能本机访问)
-d start 启动memcached服务
-d restart 重起memcached服务
-d stop|shutdown 关闭正在运行的memcached服务
-u <username> 绑定使用指定用于运行进程 <username> (只有root用户可以使用这个参数,memcached不允许使用root权限运行)
-P <file> 将PID写入文件<file>,这样可以使得后边进行快速进程终止, 需要与 -d 一起使用
-m 最大内存使用,单位MB。默认64MB
-M 内存耗尽时返回错误,而不是删除项
-c 最大同时连接数,默认是1024
-f 块大小增长因子,默认是1.25
-n <bytes>最小分配空间,key+value+flags默认是48
-k锁定所有内存页。注意你可以锁定的内存上限。
3.安装ImageMagick
12345 | [root@WebServer ~] # tar zxvf ImageMagick.tar.gz [root@WebServer ~] # cd ImageMagick-6.8.8-7/ [root@WebServer ImageMagick-6.8.8-7] # ./configure [root@WebServer ImageMagick-6.8.8-7] # make && make install [root@WebServer ImageMagick-6.8.8-7] # cd .. |
4.安装imagick
12345678910 | [root@WebServer ~] # tar zxvf imagick-3.1.2.tgz [root@WebServer ~] # cd imagick-3.1.2 [root@WebServer imagick-3.1.2] # export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig/ [root@WebServer imagick-3.1.2] # /webserver/php/bin/phpize [root@WebServer imagick-3.1.2] # ./configure --with-php-config=/webserver/php/bin/php-config [root@WebServer imagick-3.1.2] # make [root@WebServer imagick-3.1.2] # make install Installing shared extensions: /webserver/php/lib/php/extensions/no-debug-zts-20100525/ Installing header files: /webserver/php/include/php/ [root@WebServer imagick-3.1.2] # cd .. |
5.安装eaccelerator
123456789 | [root@WebServer ~] # tar zxvf eaccelerator-eaccelerator-42067ac.tar.gz [root@WebServer ~] # cd eaccelerator-eaccelerator-42067ac [root@WebServer eaccelerator-eaccelerator-42067ac] # /webserver/php/bin/phpize Configuring for : PHP Api Version: 20100412 Zend Module Api No: 20100525 Zend Extension Api No: 220100525 [root@WebServer eaccelerator-eaccelerator-42067ac] # ./configure --enable-eaccelerator=shared --with-php-config=/webserver/php/bin/php-config [root@WebServer eaccelerator-eaccelerator-42067ac] # make && make install |
建立eaccelerator缓存目录以及权限更改
12 | [root@WebServer eaccelerator-eaccelerator-42067ac] # mkdir -p /webserver/cache/eaccelerator [root@WebServer eaccelerator-eaccelerator-42067ac] # chmod 777 /webserver/cache/eaccelerator |
6.修改php配置文件
1234567891011121314151617181920 | [root@WebServer php-5.4.25] # vim /webserver/php/etc/php.ini // 按 shift +g键跳到配置文件的最末尾,加上以下配置信息: extension_dir = "/webserver/php/lib/php/extensions/no-debug-zts-20100525/" extension = "memcache.so" extension = "imagick.so" [eaccelerator] zend_extension= "/webserver/php/lib/php/extensions/no-debug-zts-20100525/eaccelerator.so" eaccelerator.shm_size= "64" eaccelerator.cache_dir= "/webserver/cache/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" |
7.检查PHP模块是否正常挂载
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 | [root@WebServer ~] # /webserver/php/bin/php -m [PHP Modules] bcmath bz2 calendar Core ctype curl date dba dom eAccelerator ereg fileinfo filter ftp gd hash iconv imagick json libxml mbstring mcrypt memcache mhash mysql mysqli pcntl pcre PDO pdo_mysql pdo_sqlite posix Reflection session shmop SimpleXML snmp sockets SPL sqlite3 standard tokenizer xml xmlreader xmlwriter zip zlib [Zend Modules] eAccelerator |
可以看到是挂载正常的
8.PHP安全性设置
a.禁用部分功能
1234 | [root@WebServer ~] # vim /webserver/php/etc/php.ini 修改这些: cgi.fix_pathinfo=0 disable_functions= exec ,system, eval ,passthru,chroot,scandir, chgrp , chown ,shell_exec,proc_open,proc_get_status,ini_alter,ini_alter,ini_restore,dl,pfsockopen,fsocket,fsockopen,openlog,syslog,readlink, symlink ,popepassthru,stream_socket_server |
b.隐藏apache版本信息
123456 | [root@WebServer ~] # vim /webserver/httpd/conf/httpd.conf // 加入如下2行 ServerTokens ProductOnly ServerSignature Off // 重启 apache,在 http 头里面只能看到: Server: Apache |
c.隐藏PHP版本信息
12345 | [root@WebServer ~]# vim /webserver/php/etc/php.ini expose_php = On 改成 expose_php = Off 重启apache后,php版本在http头中隐藏了 |
d.将session保存到memcached中,php的设置
1234 | [root@WebServer ~] # vim /webserver/php/etc/php.ini #修改如下信息 session.save_handler = memcache session.save_path = "tcp://127.0.0.1:11211" |
四.apache配置文件的修改
12345678 | [root@WebServer ~] # vim /webserver/httpd/conf/httpd.conf // 找到如下位置添加index.php <IfModule dir_module> DirectoryIndex index.php index.html < /IfModule > // 在文件末尾添加 AddType application /x-httpd-php .php .phtml AddType application /s-httpd-php-source .phps |
新建一个测试的index.php
1234 | [root@WebServer ~]# vim /webserver/httpd/htdocs/index.php <?php phpinfo(); ?> |
新建一个测试session保存到memcached的test.php
123456789101112131415161718 | <?php session_start(); if (!isset( $_SESSION [ 'TEST' ])) { $_SESSION [ 'TEST' ] = time(); } $_SESSION [ 'TEST3' ] = time(); echo $_SESSION [ 'TEST' ]; echo "<br><br>" ; echo $_SESSION [ 'TEST3' ]; echo "<br><br>" ; echo "session_id: " . $a =session_id(); echo "<br><br>" ; echo "===============================================<br><br>" ; $memcache = memcache_connect( '127.0.0.1' , 11211) or die ( "memcached connected error" ); echo "memcached version: " . $memcache ->getVersion(); echo "<br><br>" ; var_dump( $memcache ->get( "$a" )); ?> |
重新启动apache服务
123 | [root@WebServer ~] # service httpd restart Stopping httpd: [ OK ] Starting httpd: [ OK ] |
打开网页进行测试
现在测试memcache是否安装及配置好,测试的时候一定要刷新2次
如果以上出现了string(37) "TEST|i:1407375446;TEST3|i:1407376026;"这个字样说明安装成功,否则再刷新一次页面,如出现的依旧是bool(false),则说明php的配置出现问题,是php未加载memcache模块(可使用/webserver/php/bin/php -m |grep memcache查看,或者session的配置出现问题)