GD库已经是近乎于是现在主流PHP程序的标配了,所以也必须让Mac OS X中的PHP支持GD。在网上搜索了好多,最终按照这个方式成功实现,如何让Mac OS X支持PHP,请查看《让PHP跑在Mac OS X中》。

原文地址是:http://www.gigoblog.com/2008/10/08/install-gd-for-php-on-mac-os-x-105-leopard/
这里全文转载如下,以防止被GFW和谐掉。在安装配置的时候需要注意几点:
1.务必使用root用户来进行如何操作;
2.务必确认你的Mac OS X是64位还是32位,我折腾了两天就是应该按照64位的方法安装,却按照32位安装了;
3.如果提示目录不存在的错误请手动建立。

So, you need GD for your killer PHP web app, and you’re running Mac OS X 10.5? A quick look shows that GD doesn’t ship with Leopard. No worries. It’s pretty simple to install.

There are a few core requirements you must take care of before getting started. Choose to ignore these, and you’re doomed to failure!

  1. Always back up your system before a command-line activity such as this.
  2. Update your system to Mac OS 10.5.5. I could detail how to do this with prior versions, but I don’t have time.
  3. Install the latest version of Apple’s Developer Tools: XCode 3.0+ for 10.5. XCode is available on your OS X DVD, or from Apple as a free download.
  4. X11 must be installed (it is by default), as well as X11 SDK (from the Developer Tools in step 3).
DISCLAIMER: The author claims no responsibility for any damage that may occur from the use of any information found here or found on links followed from this document. If you choose to use this information, you do so at your own risk.

Get Started

To begin, open Terminal (Macintosh HD -> Applications -> Utilities ->Terminal) and invoke the superuser do command. You will need to enter your administrator password. Careful - you can now utterly destroy your machine:

sudo bash

You will need to enter your administrator password.

Determine Your Architecture

Mac OS X Leopard comes in two flavors, depending on the capabilities of your CPU — 32-bit or 64-bit. YOU MUST COMPILE FOR THE PROPER ARCHITECTURE.

Which architecture do you have? Easy enough using Terminal or the GUI. For Terminal, issue this command:

/usr/sbin/system_profiler SPHardwareDataType | grep "Processor Name:"

Or, in the GUI, choose the Apple Menu, select “About This Mac”:

Match your CPU to the table below:

Model 32-bit 64-bit
PowerPC G3 X  
PowerPC G4 X  
PowerPC G5   X
Intel Core Duo X  
Intel Core2 Duo   X
Intel Xeon   X

Make a note of whether your CPU is 32-bit or 64-bit, because you will be compiling software using vastly different settings depending on your CPU.

Install libjpeg

The free image compression library, libjpeg, is required by GD.

First, let’s create a directory for storing the source files we’ll be downloading:

mkdir -p /SourceCache
cd /SourceCache

Download the source file and unpack it:

curl -O http://www.ijg.org/files/jpegsrc.v6b.tar.gz
tar xzpf jpegsrc.v6b.tar.gz
cd /SourceCache/jpeg-6b
cp /usr/share/libtool/config.sub .
cp /usr/share/libtool/config.guess .
Mac OS X Leopard comes in two flavors, depending on the capabilities of your CPU — 32-bit or 64-bit. YOU MUST COMPILE FOR THE PROPER ARCHITECTURE.

For 32-bit only, use the following command:

./configure --enable-shared

64-bit architecture uses this command instead:

MACOSX_DEPLOYMENT_TARGET=10.5 CFLAGS="-arch ppc -arch ppc64 -arch i386 -arch x86_64 -g -Os -pipe -no-cpp-precomp" CCFLAGS="-arch ppc -arch ppc64 -arch i386 -arch x86_64 -g -Os -pipe" CXXFLAGS="-arch ppc -arch ppc64 -arch i386 -arch x86_64 -g -Os -pipe" LDFLAGS="-arch ppc -arch ppc64 -arch i386 -arch x86_64 -bind_at_load" ./configure --enable-shared

Continue on for both architectures:

make clean
make
mkdir -p /usr/local/include
mkdir -p /usr/local/bin
mkdir -p /usr/local/lib
mkdir -p /usr/local/man/man1
make install

You now have compiled libjpeg!

Download and compile the GD graphics library extension (gd.so)

We will be using Apple’s Darwin sources for PHP, which interestingly contain the GD source code. Why Apple doesn’t ship with gd.so already compiled is known only to the maker.

mkdir -p /SourceCache
cd /SourceCache
curl -O http://www.opensource.apple.com/darwinsource/10.5.5/apache_mod_php-44.1/php-5.2.6.tar.bz2
tar xjf php-5.2.6.tar.bz2
cd /SourceCache/php-5.2.6/ext/gd
phpize

Again: YOU MUST COMPILE FOR THE PROPER ARCHITECTURE.

For 32-bit use:

./configure --with-zlib-dir=/usr --with-jpeg-dir=/usr/local/lib --with-png-dir=/usr/X11R6 --with-freetype-dir=/usr/X11R6 --with-xpm-dir=/usr/X11R6

For 64-bit use:

MACOSX_DEPLOYMENT_TARGET=10.5 CFLAGS="-arch ppc -arch ppc64 -arch i386 -arch x86_64 -g -Os -pipe -no-cpp-precomp" CCFLAGS="-arch ppc -arch ppc64 -arch i386 -arch x86_64 -g -Os -pipe" CXXFLAGS="-arch ppc -arch ppc64 -arch i386 -arch x86_64 -g -Os -pipe" LDFLAGS="-arch ppc -arch ppc64 -arch i386 -arch x86_64 -bind_at_load" ./configure --with-zlib-dir=/usr --with-jpeg-dir=/usr/local/lib --with-png-dir=/usr/X11R6 --with-freetype-dir=/usr/X11R6 --with-xpm-dir=/usr/X11R6

NOTE: Check the output of the last command. If you get an error similar to this –”/usr/X11/lib/libpng.3.0.0.dylib: No such file or directory” — you should create a symbolic link with a name matching the file referred to in the error message. For example, the above error indicates that no libpng.3.0.0.dylib file exists. Simply create a link named libpng.3.0.0.dylib pointing to libpng.3.dylib:

sudo ln -s /usr/X11/lib/libpng.3.dylib /usr/X11/lib/libpng.3.0.0.dylib

Likewise, if your error refers to libpng12.0.##.#, you should create a symbolic link to libpng12.0.dylib.

Then, recompile GD.

Continue on for both architectures:

make clean
make
make install

Add gd.so to PHP

PHP needs to be configured to load the

gd.so

shared object extension that you just compiled. You will tell PHP to load it by adding a directive in your

/etc/php.ini

file.

First, let me give you a couple of pointers about this file. It *probably* exists on your machine. If not, you should just create it as a simple text file. Directives in the file can be commented out by placing a semi-colon in front of the directive.

Open the

/etc/php.ini

file in a text editor, and search for the section on Dynamic Extensions. Mine looks like this:

;;;;;;;;;;;;;;;;;;;;;;
; Dynamic Extensions ;
;;;;;;;;;;;;;;;;;;;;;;

Simply add the following line, which loads your newly compiled GD shared object:

extension=gd.so

Search your

/etc/php.ini

file for the

extension_dir=

directive, and either comment it out (by inserting a semi-colon in front of it) or ensure it is pointing to the directory where your new GD shared object is stored:

extension_dir=/usr/lib/php/extensions/no-debug-non-zts-20060613

Confirm gd.so is loading

Restart Apache to force the reloading of the PHP configuration file.

apachectl graceful

Confirm that PHP is loading the

gd.so

extension by running the following command, and looking for the line “GD Support => enabled” in the resulting output:

/usr/bin/php -i|grep -i gd

Alternatively, you can create a file called

phpinfo.php

in your web server document directory (

/Library/WebServer/Documents/

) with the following contents:

<?php
phpinfo();
?>

Point your web browser to http://localhost/phpinfo.php, and you should see a GD block verifying installation, as shown below:

让Mac OS X中的PHP支持GD的更多相关文章

  1. 在Mac OS X中配置Apache + PHP + MySQL

    在Mac OS X中配置Apache + PHP + MySQL Mac OS X 内置Apache 和 PHP,使用起来非常方便.本文以Mac OS X 10.6.3和为例.主要内容包括: 启动Ap ...

  2. 在Mac OS X中配置Apache + PHP + MySQL 很详细

    这是一篇超级详细的配置mac os下面php+mysql+apache的文章.非常详细我的大部分配置就是参考上面的内容的,比如,PHP不能连接数据库,就是改一下默认的php.ini中pdo_mysql ...

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

    本文环境: Mac OS X 10.8.5 Xcode 5.0 Mac OS X升级到10.8.5之后,内置的Apache升级到2.2.24,PHP升级到了5.3.26.本文以此环境为基础. 本文简介 ...

  4. Mac OS X 中一些常用的命令行技巧

    一.网络设置相关 1.网卡的物理地址的动态重置 出于某些需求,例如网络中的 IP 地址或网络帐号与网卡物理地址绑定,使得多个设备无法切换上网,可尝试临时更改物理地址.不过,系统偏好设置是不能修改网卡物 ...

  5. 在Mac OS X中使用VIM开发STM32(2)

    本文原创于http://www.cnblogs.com/humaoxiao,非法转载者请自重! 在我先前的博文⎣在Mac OS X中使用VIM开发STM32(1)⎤中,我们安装完成了MACVIM,这一 ...

  6. 在Mac OS X中使用VIM开发STM32(1)

       本文原创于http://www.cnblogs.com/humaoxiao,非法转载者请自重!     在我先前的博文⎣在Mac OS X中搭建STM32开发环境⎤中,我们在Mac中DIY出了最 ...

  7. 【转】Mac OS X 中 Zsh 下 PATH 环境变量的正确设置

    在 Mac OS X 中使用 zsh,环境变量 PATH 一不小心就会变得很紊乱,表现为自己设置的路径总是被放到系统路径之后,部分路径还会有重复.这是我们不太了解 zsh 启动时加载文件的顺序和 Ma ...

  8. 在 Mac OS X 中建立加密的 Zip 压缩 -- 让机密资料加上密码

    在 Mac OS X 中要压缩档案的話,基本上就用滑鼠点右鍵选「压缩...」就可以制作 Zip 格式的压缩档,很方便.但如果是机密的资料要透过 Email 等管道传送时,常常会需要建立加密的 Zip ...

  9. 在MAC OS X中默认的Web共享目录

    在Mac OS X中可以很方便的通过开启"Web共享"启用Apache服务:设置方法如下: 打开"系统设置偏好(System Preferences)" -&g ...

随机推荐

  1. Nmap Snote

    Title:Nmap Snote --2011-11-15 21:28 用Nmap上瘾了,怕以后忘记,也就记一下. Nmap -v -sS -n -p1-65535 IP Nmap -v -sS -p ...

  2. iOS 9之Safari广告拦截器(Content Blocker)

    金田( github 示例源码) 相对于谷歌对广告拦截的禁止,苹果与之态度截然相反,继Mac版Safari加入广告拦截工具之后,即将到来的iOS9对Safari也引入了内容拦截插件-Content B ...

  3. 【转】Thunderbird on Ubuntu 12.04 – 调整邮件列表行间距

    原文网址:http://www.xuebuyuan.com/414703.html markz@markz-hp6200:~$ cd .thunderbird/ markz@markz-hp6200: ...

  4. bzoj4096 [Usaco2013 dec]Milk Scheduling

    Description Farmer John has N cows that need to be milked (1 <= N <= 10,000), each of which ta ...

  5. 测试Remoting三种信道Http,Tcp,Ipc和Web Service的访问速度 (转)

    Remoting和Web Service是.net中的重要技术,都可用来实现分布式系统开发,如果是不同的平台就只能选择Web Service,但如果是同一平台,就都可以选择了.到底选择那种,当然还有访 ...

  6. FZU2176---easy problem (树链剖分)

    http://acm.fzu.edu.cn/problem.php?pid=2176 Problem 2176 easy problem Accept: 9    Submit: 32Time Lim ...

  7. enable ide

    http://pve.proxmox.com/wiki/Migration_of_servers_to_Proxmox_VE The vmware system consists of two dis ...

  8. error C2143: 语法错误 : 缺少“;”(在“using”的前面)

    class JJMenuScene : public cocos2d::CCLayer { public: // Here's a difference. Method 'init' in cocos ...

  9. 苹果的HomeKit协议

    苹果的HomeKit协议非常底层,其作用仅限于让iOS平台和家居设备能够相互“握手”,但“认识”之后,想要继续控制灯.空调等设备,仍然需要家电厂商在HomeKit的基础上进行二次开发.

  10. 模拟jquery封装选择器

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...