让Mac OS X中的PHP支持GD
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!
- Always back up your system before a command-line activity such as this.
- 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.
- 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.
- 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 . |
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的更多相关文章
- 在Mac OS X中配置Apache + PHP + MySQL
在Mac OS X中配置Apache + PHP + MySQL Mac OS X 内置Apache 和 PHP,使用起来非常方便.本文以Mac OS X 10.6.3和为例.主要内容包括: 启动Ap ...
- 在Mac OS X中配置Apache + PHP + MySQL 很详细
这是一篇超级详细的配置mac os下面php+mysql+apache的文章.非常详细我的大部分配置就是参考上面的内容的,比如,PHP不能连接数据库,就是改一下默认的php.ini中pdo_mysql ...
- 在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.本文以此环境为基础. 本文简介 ...
- Mac OS X 中一些常用的命令行技巧
一.网络设置相关 1.网卡的物理地址的动态重置 出于某些需求,例如网络中的 IP 地址或网络帐号与网卡物理地址绑定,使得多个设备无法切换上网,可尝试临时更改物理地址.不过,系统偏好设置是不能修改网卡物 ...
- 在Mac OS X中使用VIM开发STM32(2)
本文原创于http://www.cnblogs.com/humaoxiao,非法转载者请自重! 在我先前的博文⎣在Mac OS X中使用VIM开发STM32(1)⎤中,我们安装完成了MACVIM,这一 ...
- 在Mac OS X中使用VIM开发STM32(1)
本文原创于http://www.cnblogs.com/humaoxiao,非法转载者请自重! 在我先前的博文⎣在Mac OS X中搭建STM32开发环境⎤中,我们在Mac中DIY出了最 ...
- 【转】Mac OS X 中 Zsh 下 PATH 环境变量的正确设置
在 Mac OS X 中使用 zsh,环境变量 PATH 一不小心就会变得很紊乱,表现为自己设置的路径总是被放到系统路径之后,部分路径还会有重复.这是我们不太了解 zsh 启动时加载文件的顺序和 Ma ...
- 在 Mac OS X 中建立加密的 Zip 压缩 -- 让机密资料加上密码
在 Mac OS X 中要压缩档案的話,基本上就用滑鼠点右鍵选「压缩...」就可以制作 Zip 格式的压缩档,很方便.但如果是机密的资料要透过 Email 等管道传送时,常常会需要建立加密的 Zip ...
- 在MAC OS X中默认的Web共享目录
在Mac OS X中可以很方便的通过开启"Web共享"启用Apache服务:设置方法如下: 打开"系统设置偏好(System Preferences)" -&g ...
随机推荐
- Jasper_table_Cloud not resolve style(s)
resolve method : delete style="".
- python实现发工资脚本
好开心啊,在旁边大神的帮助下,终于实现了发工资的python脚本,之前用shell写的老出错,刚才测试,发80个人工资详情,妥妥的,代码如下: from email.mime.multipart im ...
- JS对undefined,null,NaN判断
1.判断undefined: <span style="font-size: small;">var tmp = undefined; if (typeof(tmp) ...
- cf C. Mittens
http://codeforces.com/contest/370/problem/C 题意:有n个人,m中颜色的手套,开始每个人都是两只相同颜色的手套,经过交换最多可以换出多少个人戴不同颜色的手套. ...
- JVM虚拟机栈和本地方法栈溢出测试
弄JAVA,那JVM,JAVA语法,JDK库,JAVAEE,流行框架是一个都不能少,才可以有全局感的. JVM高级特性这书,看得差不多了.慢慢实践. /** * * *VM Args: -Xms20m ...
- java中Runnable接口含义
Java中实现多线程有两种途径:继承Thread类或者实现Runnable接口. Runnable接口非常简单,就定义了一个方法run(),继承Runnable并实现这个 方法就可以实现多线程了,但是 ...
- 易pc,1G容量以上的u盘,另外还要一台装了windows系统的电脑。
一.硬件:易pc,1G容量以上的u盘,另外还要一台装了windows系统的电脑. 二.软件: 1.windows xp的安装包.考虑到易PC的硬盘容量,还是用精简版的吧,比如“Deepin XP Li ...
- 通过 iTextSharp 实现PDF 审核盖章
最近需要做一个PDF自动审核盖章的工作,其实就是读取PDF,然后再最后一页加入一个审核章印图片上去.看起来很简单,不过在开发过程中,还是遇到了一些问题,在这里记录一下. 主要遇到的问题是页面的旋转 和 ...
- 14条Yahoo(雅虎)十四条优化原则【转】
请大家都能好好学习,不要像我一样一扫而过,好好的记下来!不仅仅是晓得一些CSS xhtml就好了,深刻认识到很多的东西需要学习的.很早就用Firebug,但是却没听说过Yslow,这叫不喜欢追求.希望 ...
- JAVA面向对象总结
面向对象概述 面向对象是当前计算机界关心的重点,它是90年代软件开发方法的主流.面向对象的概念和应用已超越程序设计和软件开发,如数据库系统.交互式界面.应用结构.应用平台.分布式系统.网络 ...