Home php教程 php手册 在Mac OS X中完善PHP环境:memcache、mcrypt、igbinary

在Mac OS X中完善PHP环境:memcache、mcrypt、igbinary

Jun 12, 2016 pm 08:08 PM
mac os x mcrypt memcache php code Open source environment programming programming language software development

<span style="color: #000000;">本文环境:
Mac OS X </span>10.8.5<span style="color: #000000;">
Xcode </span>5.0
Copy after login

  Mac OS X升级到10.8.5之后,内置的Apache升级到2.2.24,PHP升级到了5.3.26。本文以此环境为基础。

  本文简介安装memcache、mcrypt、igbinary。

一、首先准备Xcode和autoconf。

  安装的过程需要Xcode的命令行工具,编译PHP扩展需要有autoconf。

  Xcode是苹果公司提供的免费开发工具,请从App Store中搜索安装。完成安装之后,请通过Xcode的菜单【Xcode】-【Preferences...】打开对话框并切换到【Downloads】页,下载Command Line Tools

  autoconf请从如下地址下载:

http://ftp.gnu.org/gnu/autoconf/
Copy after login
<span style="color: #000000;">提醒:
本文涉及的所有下载和编译安装,建议把源代码存放到路径不存在空格(和其他特殊符号)的位置,以避免执行make install时发生意外。</span>
Copy after login

  解压并进入autoconf目录,依次执行如下命令:

./<span style="color: #000000;">configure
make
</span><span style="color: #0000ff;">sudo</span> <span style="color: #0000ff;">make</span> <span style="color: #0000ff;">install</span>
Copy after login

二、安装memcache

  memcached是一套高性能的内存对象缓存系统。在PHP中,有两套扩展可以用来支持memcached。其中一套是原生的扩展,称为“memcache”,下面介绍的就是这个扩展。还有另外一个套扩展是基于libmemcached库的,功能更强一些。

  10.8的mac中,可以在/usr/bin/路径下找到memcached这个文件,/System/Library/LaunchDaemons/路径下还有个com.danga.memcached.plist文件。打开com.danga.memcached.plist文件,删除掉如下两行:

<span style="color: #008080;">1</span> <span style="color: #0000ff;"><span style="color: #800000;">key</span><span style="color: #0000ff;">></span>Disable<span style="color: #0000ff;"></span><span style="color: #800000;">key</span><span style="color: #0000ff;">></span>
<span style="color: #008080;">2</span> <span style="color: #0000ff;"><span style="color: #800000;">true</span><span style="color: #0000ff;">/></span></span></span>
Copy after login

  保存文件之后重新启动,打开终端执行:

<span style="color: #008080;">1</span> <span style="color: #000000;">#memcached的默认端口为11211
</span><span style="color: #008080;">2</span> telnet <span style="color: #800080;">127.0</span>.<span style="color: #800080;">0.1</span> <span style="color: #800080;">11211</span>
<span style="color: #008080;">3</span> <span style="color: #000000;">#stats命令显示memcached的各种状态信息
</span><span style="color: #008080;">4</span> <span style="color: #000000;">stats
</span><span style="color: #008080;">5</span> <span style="color: #000000;">#quit退出与memcached的连接
</span><span style="color: #008080;">6</span> quit
Copy after login

  如果一切正常,开始安装memcache的PHP扩展。请从如下地址下载:

http://pecl.php.net/package/memcache
Copy after login

  解包下载的文件之后进入文件目录,请依次执行如下命令:

<span style="color: #000000;">phpize
.</span>/<span style="color: #000000;">configure
</span><span style="color: #0000ff;">make</span>
<span style="color: #0000ff;">sudo</span> <span style="color: #0000ff;">make</span> <span style="color: #0000ff;">install</span>
Copy after login
Copy after login
Copy after login

  如果看到如下结果:

Installing shared extensions:     /usr/lib/php/extensions/no-debug-non-zts-20090626/
Copy after login

  说明安装正常,接下去打开/etc/php.ini文件,添加如下行:

<span style="color: #008080;">1</span> extension=memcache.so
Copy after login

  重启apache之后,看一下phpinfo结果:

  

三、安装mcrypt

  Mcrypt是一个功能强大的加密算法扩展库,它持20多种加密算法和8种加密模式。Mac OS X中,需要先安装这个库然后再安装PHP扩展。

  首先是下载扩展库的源文件,下载地址在这里:

http://sourceforge.net/projects/mcrypt/files/Libmcrypt/2.5.8/
Copy after login

  下载到本地之后,解压缩,进入目录,请依次执行如下命令:

./<span style="color: #000000;">configure<span> --disable-posix-threads --enable-static</span>
</span><span style="color: #0000ff;">make</span>
<span style="color: #0000ff;">sudo</span> <span style="color: #0000ff;">make</span> <span style="color: #0000ff;">install</span>
Copy after login

  安装好扩展库之后,请下载PHP的源代码。Mac OS X 10.8.5中的PHP是5.3.26版本的,下载地址如下(如果您的PHP版本不同,请自行下载相应版本的代码):

http://cn2.php.net/get/php-5.3.26.tar.bz2/from/a/mirror
Copy after login

  完成下载之后,请解包进入代码目录,再cd ext/mcrypt/,然后依次执行如下命令:

<span style="color: #000000;">phpize
.</span>/<span style="color: #000000;">configure
</span><span style="color: #0000ff;">make</span>
<span style="color: #0000ff;">sudo</span> <span style="color: #0000ff;">make</span> <span style="color: #0000ff;">install</span>
Copy after login
Copy after login
Copy after login

  正确完成安装之后,请编辑/etc/php.ini文件,加入如下配置行:

<span style="color: #008080;">1</span> extension=mcrypt.so
Copy after login

  很熟悉是不是?重启apache之后,再次用phpinfo进行检查:

  

四、安装igbinary

  用igbinary实现序列化和反序列化,效率更高,占用的字节数更少,性能远远高于PHP自带的序列化功能。有两个下载地址:

#PECL官方的地址,这里提供1.<span style="color: #800080;">1</span><span style="color: #000000;">.1版本(稳定版)下载
http:</span><span style="color: #008000;">//</span><span style="color: #008000;">pecl.php.net/package/igbinary</span>
<span style="color: #000000;">#另外一个地址,提供1.1.2版本(开发版)下载
https:</span><span style="color: #008000;">//</span><span style="color: #008000;">nodeload.github.com/phadej/igbinary/zip/master</span>
Copy after login

  下载之后,依旧是很熟悉的路数:解包、进入目录,下列命令步骤:

<span style="color: #000000;">phpize
.</span>/<span style="color: #000000;">configure
</span><span style="color: #0000ff;">make</span>
<span style="color: #0000ff;">sudo</span> <span style="color: #0000ff;">make</span> <span style="color: #0000ff;">install</span>
Copy after login
Copy after login
Copy after login

  编辑/etc/php.ini添加如下配置行:

<span style="color: #008080;">1</span> extension=igbinary.so
Copy after login

  重启apache,检查一下效果:

  

  可以改动一下PHP的如下配置行:session.serialize_handler = php,修改成:

<span style="color: #008080;">1</span> session.serialize_handler = igbinary
Copy after login

  另外,推荐一篇关于igbinary性能测试的文章:

http://www.ooso.net/archives/538
Copy after login

 

  好了,就这些。

<span style="color: #000000;">总结博客的过程,就是重新学习的过程。
感谢如下网友:
秦歌、yifangyou、Volcano
还有其他共享知识于网络的朋友</span>
Copy after login
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

How do you parse and process HTML/XML in PHP? How do you parse and process HTML/XML in PHP? Feb 07, 2025 am 11:57 AM

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

PHP Program to Count Vowels in a String PHP Program to Count Vowels in a String Feb 07, 2025 pm 12:12 PM

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

The Key to Coding: Unlocking the Power of Python for Beginners The Key to Coding: Unlocking the Power of Python for Beginners Oct 11, 2024 pm 12:17 PM

Python is an ideal programming introduction language for beginners through its ease of learning and powerful features. Its basics include: Variables: used to store data (numbers, strings, lists, etc.). Data type: Defines the type of data in the variable (integer, floating point, etc.). Operators: used for mathematical operations and comparisons. Control flow: Control the flow of code execution (conditional statements, loops).

Problem-Solving with Python: Unlock Powerful Solutions as a Beginner Coder Problem-Solving with Python: Unlock Powerful Solutions as a Beginner Coder Oct 11, 2024 pm 08:58 PM

Pythonempowersbeginnersinproblem-solving.Itsuser-friendlysyntax,extensivelibrary,andfeaturessuchasvariables,conditionalstatements,andloopsenableefficientcodedevelopment.Frommanagingdatatocontrollingprogramflowandperformingrepetitivetasks,Pythonprovid

7 PHP Functions I Regret I Didn't Know Before 7 PHP Functions I Regret I Didn't Know Before Nov 13, 2024 am 09:42 AM

If you are an experienced PHP developer, you might have the feeling that you’ve been there and done that already.You have developed a significant number of applications, debugged millions of lines of code, and tweaked a bunch of scripts to achieve op

Demystifying C: A Clear and Simple Path for New Programmers Demystifying C: A Clear and Simple Path for New Programmers Oct 11, 2024 pm 10:47 PM

C is an ideal choice for beginners to learn system programming. It contains the following components: header files, functions and main functions. A simple C program that can print "HelloWorld" needs a header file containing the standard input/output function declaration and uses the printf function in the main function to print. C programs can be compiled and run by using the GCC compiler. After you master the basics, you can move on to topics such as data types, functions, arrays, and file handling to become a proficient C programmer.

See all articles