如何在mac上顺利安装php5.5+memcache并且巧妙躲避各种坑

如何在mac上顺利安装php5.5+memcache并且巧妙躲避各种坑,第1张

用mac 做开发环境,封装 Cache,在没用 memcache 扩展的时候,使用 Cache 的时候,使用 file 替代。再生产环境的时棚庆漏候,如果有装 memcache 会差碧自动切换。

class TL_Cache

{

private $_file

private $_md5_key

private $_md5_val = ''

private $_mem

function __construct($key)

{

$this->_md5_key = $key

//$ever = 'var'.DIRECTORY_SEPARATOR.'cache'.DIRECTORY_SEPARATOR.'.ever'

$ever = 'var'.DIRECTORY_SEPARATOR.'cache'.DIRECTORY_SEPARATOR.'data'

$ever .= DIRECTORY_SEPARATOR.substr($this->_md5_key, 0, 2)

$ever .= DIRECTORY_SEPARATOR.substr($this->_md5_key, 2, 2)

$this->_file = TL_FSO::getMultDir(_ROOT_DIR_, $ever).$this->_md5_key

$this->_mem = TL_Mem::getInstance()

}

public function get()

{

$this->_md5_val = $this->_mem->get($this->_md5_key)

$res = TL_FSO::getFileContent($this->_file)

if (!$this->_mem->verify() || $this->_md5_val == md5($res)) {

 链烂 return unserialize($res)

}

//error_log('get from cache')

return null

}

public function set($val)

{

$val = serialize($val)

$this->_mem->set($this->_md5_key, md5($val))

return TL_FSO::createFile($this->_file, $val)

}

public function delete()

{

$this->_mem->delete($this->_md5_key)

TL_FSO::deleteFile($this->_file)

}

public function getVal($key)

{

return $this->get()

}

public function setVal($key, $val)

{

return $this->set($val)

}

}

配置php服务

安饥塌装yasm汇编器(解压与编译过程已省略):

[root@linuxprobenginx-1.6.0]cd/usr/local/src

[root@linuxprobesrc]tarzxvfyasm-1.2.0.tar.gz

[root@linuxprobesrc]cdyasm-1.2.0

[root@linuxprobeyasm-1.2.0]./configure

[root@linuxprobeyasm-1.2.0]make

[root@linuxprobeyasm-1.2.0]makeinstall

安装libmcrypt加密算法扩展库(解烂银圆压与编译过程已省略):

[root@linuxprobeyasm-1.2.0]cd/usr/local/src

[root@linuxprobesrc]tarzxvflibmcrypt-2.5.8.tar.gz

[root@linuxprobesrc]cdlibmcrypt-2.5.8

[root@linuxprobelibmcrypt-2.5.8]./configure

[root@linuxprobelibmcrypt-2.5.8]make

[root@linuxprobelibmcrypt-2.5.8]makeinstall

安装libvpx视频编码器(解压与编译过程搏旦已省略):

[root@linuxprobelibmcrypt-2.5.8]cd/usr/local/src

[root@linuxprobesrc]tarxjvflibvpx-v1.3.0.tar.bz2

[root@linuxprobesrc]cdlibvpx-v1.3.0

[root@linuxprobelibvpx-v1.3.0]./configure--prefix=/usr/local/libvpx--enable-shared--enable-vp9

[root@linuxprobelibvpx-v1.3.0]make

[root@linuxprobelibvpx-v1.3.0]makeinstall

安装Tiff标签图像文件格式(解压与编译过程已省略):

[root@linuxprobelibvpx-v1.3.0]cd/usr/local/src

[root@linuxprobesrc]tarzxvftiff-4.0.3.tar.gz

[root@linuxprobesrc]cdtiff-4.0.3

[root@linuxprobetiff-4.0.3]./configure--prefix=/usr/local/tiff--enable-shared

[root@linuxprobetiff-4.0.3]make

[root@linuxprobetiff-4.0.3]makeinstall

安装libpng图片(png格式)函数库(解压与编译过程已省略):

[root@linuxprobetiff-4.0.3]cd/usr/local/src

[root@linuxprobesrc]tarzxvflibpng-1.6.12.tar.gz

[root@linuxprobesrc]cdlibpng-1.6.12

[root@linuxprobelibpng-1.6.12]./configure--prefix=/usr/local/libpng--enable-shared

[root@linuxprobelibpng-1.6.12]make

[root@linuxprobelibpng-1.6.12]makeinstall

安装freetype字体引擎(解压与编译过程已省略):

[root@linuxprobelibpng-1.6.12]cd/usr/local/src

[root@linuxprobesrc]tarzxvffreetype-2.5.3.tar.gz

[root@linuxprobesrc]cdfreetype-2.5.3

[root@linuxprobefreetype-2.5.3]./configure--prefix=/usr/local/freetype--enable-shared

[root@linuxprobefreetype-2.5.3]make

[root@linuxprobefreetype-2.5.3]makeinstall

安装jpeg图片(jpeg格式)函数库(解压与编译过程已省略):

[root@linuxprobefreetype-2.5.3]cd/usr/local/src

[root@linuxprobesrc]tarzxvfjpegsrc.v9a.tar.gz

[root@linuxprobesrc]cdjpeg-9a

[root@linuxprobejpeg-9a]./configure--prefix=/usr/local/jpeg--enable-shared

[root@linuxprobejpeg-9a]make

[root@linuxprobejpeg-9a]makeinstall

安装libgd图像处理程序(解压与编译过程已省略):

[root@linuxprobejpeg-9a]cd/usr/local/src

[root@linuxprobesrc]tarzxvflibgd-2.1.0.tar.gz

[root@linuxprobesrc]cdlibgd-2.1.0

[root@linuxprobelibgd-2.1.0]./configure--prefix=/usr/local/libgd--enable-shared--with-jpeg=/usr/local/jpeg--with-png=/usr/local/libpng--with-freetype=/usr/local/freetype--with-fontconfig=/usr/local/freetype--with-xpm=/usr/--with-tiff=/usr/local/tiff--with-vpx=/usr/local/libvpx

[root@linuxprobelibgd-2.1.0]make

[root@linuxprobelibgd-2.1.0]makeinstall

安装t1lib图片生成函数库(解压与编译过程已省略):

[root@linuxprobecdlibgd-2.1.0]cd/usr/local/src

[root@linuxprobesrc]tarzxvft1lib-5.1.2.tar.gz

[root@linuxprobesrc]cdt1lib-5.1.2

[root@linuxprobet1lib-5.1.2]./configure--prefix=/usr/local/t1lib--enable-shared

[root@linuxprobet1lib-5.1.2]make

[root@linuxprobet1lib-5.1.2]makeinstall

将函数库文件放至合适的位置:

[root@linuxprobet1lib-5.1.2]cd/usr/local/src

[root@linuxprobesrc]ln-s/usr/lib64/libltdl.so/usr/lib/libltdl.so

[root@linuxprobesrc]cp-frp/usr/lib64/libXpm.so*/usr/lib/

安装php服务程序(命令比较长,请一定要复制完整!!!):

[root@linuxprobesrc]tar-zvxfphp-5.5.14.tar.gz

[root@linuxprobesrc]cdphp-5.5.14

[root@linuxprobephp-5.5.14]exportLD_LIBRARY_PATH=/usr/local/libgd/lib

[root@linuxprobephp-5.5.14]./configure--prefix=/usr/local/php--with-config-file-path=/usr/local/php/etc--with-mysql=/usr/local/mysql--with-mysqli=/usr/local/mysql/bin/mysql_config--with-mysql-sock=/tmp/mysql.sock--with-pdo-mysql=/usr/local/mysql--with-gd--with-png-dir=/usr/local/libpng--with-jpeg-dir=/usr/local/jpeg--with-freetype-dir=/usr/local/freetype--with-xpm-dir=/usr/--with-vpx-dir=/usr/local/libvpx/--with-zlib-dir=/usr/local/zlib--with-t1lib=/usr/local/t1lib--with-iconv--enable-libxml--enable-xml--enable-bcmath--enable-shmop--enable-sysvsem--enable-inline-optimization--enable-opcache--enable-mbregex--enable-fpm--enable-mbstring--enable-ftp--enable-gd-native-ttf--with-openssl--enable-pcntl--enable-sockets--with-xmlrpc--enable-zip--enable-soap--without-pear--with-gettext--enable-session--with-mcrypt--with-curl--enable-ctype

[root@linuxprobephp-5.5.14]make

[root@linuxprobephp-5.5.14]makeinstall

复制php服务程序的配置文件到安装目录:

[root@linuxprobephp-5.5.14]cpphp.ini-proction/usr/local/php/etc/php.ini

删除默认的php配置文件:

[root@linuxprobephp-5.5.14]rm-rf/etc/php.ini

创建php配置文件的软连接到/etc/目录中:

[root@linuxprobephp-5.5.14]cp/usr/local/php/etc/php-fpm.conf.default/usr/local/php/etc/php-fpm.conf

[root@linuxprobephp-5.5.14]ln-s/usr/local/php/etc/php-fpm.conf/etc/php-fpm.conf

[root@linuxprobephp-5.5.14]ln-s/usr/local/php/etc/php.ini/etc/php.ini

编辑php服务程序的配置文件:

[root@linuxprobephp-5.5.14]vim/usr/local/php/etc/php-fpm.conf

//将第25行参数前面的分号去掉。

pid=run/php-fpm.pid

//修改第148和149行,将user与group修改为www。

user=www

group=www

添加php-fpm服务程序到开机启动项:

[root@linuxprobephp-5.5.14]cpsapi/fpm/init.d.php-fpm/etc/rc.d/init.d/php-fpm

[root@linuxprobephp-5.5.14]chmod+x/etc/rc.d/init.d/php-fpm

[root@linuxprobephp-5.5.14]chkconfigphp-fpmon

为了保障网站的安全性,禁用掉不安全的功能:

[root@linuxprobephp-5.5.14]vim/usr/local/php/etc/php.ini

//修改第305行的disable_functions参数,追加参数为:

disable_functions=passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,escapeshellcmd,dll,popen,disk_free_space,checkdnsrr,checkdnsrr,getservbyname,getservbyport,disk_total_space,posix_ctermid,posix_get_last_error,posix_getcwd,posix_getegid,posix_geteuid,posix_getgid,posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid,posix_getppid,posix_getpwnam,posix_getpwuid,posix_getrlimit,posix_getsid,posix_getuid,posix_isatty,posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid,posix_setpgid,posix_setsid,posix_setuid,posix_strerror,posix_times,posix_ttyname,posix_uname

配置nginx服务程序支持php:

[root@linuxprobephp-5.5.14]vim/usr/local/nginx/conf/nginx.conf

//将第2行前面的号去掉并修改为userwwwwww

//将第45行参数修改为indexindex.htmlindex.htmindex.php

//将第65-71行前面的号去掉,修改为:

location~.php${

roothtml

fastcgi_pass127.0.0.1:9000

fastcgi_indexindex.php

fastcgi_paramSCRIPT_FILENAME$document_root$fastcgi_script_name

includefastcgi_params

}

重启nginx与php-fpm服务程序:

[root@linuxprobephp-5.5.14]systemctlrestartnginx

[root@linuxprobephp-5.5.14]systemctlrestartphp-fpm


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/tougao/12528008.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-26
下一篇 2023-05-26

发表评论

登录后才能评论

评论列表(0条)

保存