CentOS 6.5编译安装PHP 5.4.25
apache的安装参考
http://fengwan.blog.51cto.com/508652/1360429
MySQL的安装参考
http://fengwan.blog.51cto.com/508652/1363566
一.环境准备
apache的安装路径为/webserver/httpd
MySQL的安装路径为/webserver/mysql
1.依赖包的安装
[root@WebServer ~]# yum install -y 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
[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并进入安装目录
[root@WebServer ~]# tar zxvf php-5.4.25.tar.gz [root@WebServer ~]# cd php-5.4.25
2.编译PHP
[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
3.安装
[root@WebServer php-5.4.25]# make [root@WebServer php-5.4.25]# make install
4.复制php配置文件
[root@WebServer php-5.4.25]# cp php.ini-production /webserver/php/etc/php.ini
三.编译安装PHP的扩展模块
1.安装memcache
[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
[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 ..
3.安装ImageMagick
[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
[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
[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缓存目录以及权限更改
[root@WebServer eaccelerator-eaccelerator-42067ac]# mkdir -p /webserver/cache/eaccelerator [root@WebServer eaccelerator-eaccelerator-42067ac]# chmod 777 /webserver/cache/eaccelerator
6.修改php配置文件
[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模块是否正常挂载
[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.禁用部分功能
[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版本信息
[root@WebServer ~]# vim /webserver/httpd/conf/httpd.conf //加入如下2行 ServerTokens ProductOnly ServerSignature Off //重启 apache,在 http 头里面只能看到: Server: Apache
c.隐藏PHP版本信息
[root@WebServer ~]# vim /webserver/php/etc/php.ini expose_php On 改成 expose_php Off 重启apache后,php版本在http头中隐藏了
四.apache配置文件的修改
[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
[root@WebServer ~]# vim /webserver/httpd/htdocs/index.php <?php phpinfo(); ?>
重新启动apache服务
[root@WebServer ~]# service httpd restart Stopping httpd: [ OK ] Starting httpd: [ OK ]
打开网页进行测试
本文出自 “枫林晚” 博客,请务必保留此出处http://fengwan.blog.51cto.com/508652/1363709
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。