【魄爺】 发表于 2018-12-20 08:20:01

CentOS 6.5编译安装PHP 5.4.25

  apache的安装参考

  http://fengwan.blog.运维网.com/508652/1360429

  MySQL的安装参考
  http://fengwan.blog.运维网.com/508652/1363566

  一.环境准备
  apache的安装路径为/webserver/httpd
  MySQL的安装路径为/webserver/mysql
  1.依赖包的安装
# 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
# tar zxvf libiconv-1.14.tar.gz
# cd libiconv-1.14
# ./configure --prefix=/webserver/libiconv
# make && make install
# cd ..
# tar zxvf libmcrypt-2.5.8.tar.gz
# cd libmcrypt-2.5.8
# ./configure
# make && make install
# /sbin/ldconfig
# cd libltdl/
# ./configure --enable-ltdl-install
# make && make install
# cd ../..
# tar zxvf mhash-0.9.9.9.tar.gz
# cd mhash-0.9.9.9
# ./configure
# make && make install
# cd /usr/lib64/
# ln -s /usr/local/lib/* .
# ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config
# cd
# tar zxvf mcrypt-2.6.8.tar.gz
# cd mcrypt-2.6.8
# /sbin/ldconfig
# ./configure
# make && make install
# cd ..  二.开始编译安装PHP
  1.解压PHP并进入安装目录
# tar zxvf php-5.4.25.tar.gz
# cd php-5.4.25  2.编译PHP
# ./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  另外一个版本
./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.安装

# make
# make install  4.复制php配置文件
# cp php.ini-production /webserver/php/etc/php.ini  三.编译安装PHP的扩展模块
  1.安装memcache
# tar zxvf memcache-2.2.7.tgz
# cd memcache-2.2.7
# /webserver/php/bin/phpize
Configuring for:
PHP Api Version:         20100412
Zend Module Api No:      20100525
Zend Extension Api No:   220100525
# ./configure --enable-memcache --with-php-config=/webserver/php/bin/php-config
# make
# make install
Installing shared extensions:   /webserver/php/lib/php/extensions/no-debug-zts-20100525/
# cd ..  2.安装memcached

# tar zxvf libevent-2.0.21-stable.tar.gz
# cd libevent-2.0.21-stable
# ./configure --prefix=/webserver/libevent
# make && make install
# cd ..
# tar zxvf memcached-1.4.17.tar.gz
# cd memcached-1.4.17
# ./configure --prefix=/webserver/memcached --with-libevent=/webserver/libevent
# make && make install
# cd ..
#启动memcached,使用如下命令:
# /webserver/memcached/bin/memcached -d -m 512 -c 2048 -p 11211 -P /tmp/memcached.pid -u nobody  memcached启动参数:
  -p 指定端口号(默认11211)
  -UUDP监听端口 (默认: 11211, 0 时关闭)
  -s      用于监听的UNIX套接字路径(禁用网络支持)
  -a      UNIX套接字访问掩码,八进制数字(默认:0700)
  -m 指定最大使用内存大小(默认64MB)
  -t 线程数(默认4)
  -l绑定地址 (默认:所有都允许,无论内外网或者本机更换IP,有安全隐患,若设置为127.0.0.1就只能本机访问)
  -d start 启动memcached服务
  -d restart 重起memcached服务
  -d stop|shutdown 关闭正在运行的memcached服务
  -u绑定使用指定用于运行进程   (只有root用户可以使用这个参数,memcached不允许使用root权限运行)
  -P将PID写入文件,这样可以使得后边进行快速进程终止, 需要与 -d 一起使用
  -m 最大内存使用,单位MB。默认64MB      

  -M 内存耗尽时返回错误,而不是删除项
  -c 最大同时连接数,默认是1024
  -f 块大小增长因子,默认是1.25
  -n 最小分配空间,key+value+flags默认是48
  -k锁定所有内存页。注意你可以锁定的内存上限。
  

  3.安装ImageMagick

# tar zxvf ImageMagick.tar.gz
# cd ImageMagick-6.8.8-7/
# ./configure
# make && make install
# cd ..  4.安装imagick

# tar zxvf imagick-3.1.2.tgz
# cd imagick-3.1.2
# export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig/
# /webserver/php/bin/phpize
# ./configure --with-php-config=/webserver/php/bin/php-config
# make
# make install
Installing shared extensions:   /webserver/php/lib/php/extensions/no-debug-zts-20100525/
Installing header files:          /webserver/php/include/php/
# cd ..  5.安装eaccelerator
# tar zxvf eaccelerator-eaccelerator-42067ac.tar.gz
# cd eaccelerator-eaccelerator-42067ac
# /webserver/php/bin/phpize
Configuring for:
PHP Api Version:         20100412
Zend Module Api No:      20100525
Zend Extension Api No:   220100525
# ./configure --enable-eaccelerator=shared --with-php-config=/webserver/php/bin/php-config
# make && make install  建立eaccelerator缓存目录以及权限更改

# mkdir -p /webserver/cache/eaccelerator
# chmod 777 /webserver/cache/eaccelerator  

  6.修改php配置文件
# 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"

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模块是否正常挂载
# /webserver/php/bin/php -m

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

eAccelerator  可以看到是挂载正常的
  8.PHP安全性设置
  a.禁用部分功能

# 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版本信息

# vim /webserver/httpd/conf/httpd.conf
//加入如下2行
ServerTokens ProductOnly
ServerSignature Off
//重启 apache,在 http 头里面只能看到:
Server: Apache  c.隐藏PHP版本信息
# vim /webserver/php/etc/php.ini
expose_php = On
改成
expose_php = Off
重启apache后,php版本在http头中隐藏了  d.将session保存到memcached中,php的设置
# vim /webserver/php/etc/php.ini
#修改如下信息
session.save_handler = memcache
session.save_path = "tcp://127.0.0.1:11211"  四.apache配置文件的修改
# vim /webserver/httpd/conf/httpd.conf
//找到如下位置添加index.php

    DirectoryIndex index.php index.html

//在文件末尾添加
AddType application/x-httpd-php .php .phtml
AddType application/s-httpd-php-source .phps  新建一个测试的index.php
# vim /webserver/httpd/htdocs/index.php
  新建一个测试session保存到memcached的test.php
  重新启动apache服务
# service httpd restart
Stopping httpd:                                          
Starting httpd:                                            打开网页进行测试
http://s3.运维网.com/wyfs02/M01/12/BE/wKioL1MNeSPz0z-QAADEuZendv8320.png
  现在测试memcache是否安装及配置好,测试的时候一定要刷新2次
http://s3.运维网.com/wyfs02/M02/44/D0/wKioL1Pi3HmDByL_AAAfRg_8g40759.png
  如果以上出现了string(37) "TEST|i:1407375446;TEST3|i:1407376026;"这个字样说明安装成功,否则再刷新一次页面,如出现的依旧是bool(false),则说明php的配置出现问题,是php未加载memcache模块(可使用/webserver/php/bin/php -m |grep memcache查看,或者session的配置出现问题)



页: [1]
查看完整版本: CentOS 6.5编译安装PHP 5.4.25