search
HomeBackend DevelopmentPHP Tutorialmac OS X comes with a PHP environment, and there is no freetype solution


Recently, I used my computer to make something small and needed to use a verification code. I used the thinkPHP framework. The verification code for TP needs to be supported by the freetype library. OS X for MAC comes with APACHE and PHP. You can use it by configuring it directly. It is very It is convenient and has a lot of extension support, which is quite convenient, but freetype does not have it, which is a troublesome thing.
In fact, it is not troublesome at all. Just add a support. If you are in a Linux server environment, it is easy to handle, or you can compile it yourself. The environment is easy to handle, but because I use my own environment and I don’t want to change the system too much, I am afraid that there are other components in the system that need to have their own Apache or PHP support, and changing them will cause other problems, so I changed It’s a bit troublesome. Most of the answers on the Internet are about recompiling PHP and adding freetype support, but I haven’t mentioned the specifics. I just had nothing to do these two days, so I messed around and got it done.
My idea is to use PHP For related things, re-download and install them so as not to damage the original environment. At the same time, back up the file /usr/libexec/apache2/libphp5.so and rename it to libphp5-OX.so. Then in /etc/apache2/httpd.conf Add one:
#LoadModule php5_module libexec/apache2/libphp5-OX.so
This can easily switch between the built-in PHP and the newly compiled PHP
First:
Download gd:
https://github.com/libgd/ libgd/releases
libgd-2.1.1.tar.gz
Requires png and jpeg, which can be installed through brew, as well as liftoff and libvpx libraries
brew install libpng
brew install libjpeg
brew install libtiff
brew install libvpx
Compile GD (Pay attention to the corresponding library location installed by brew, png jpeg, etc.):
./configure --prefix=/usr/local/gd2 --with-zlib --with-png=/usr/local/opt/libpng --with-freetype=/usr/local/opt/freetype --with-jpeg=/usr/local/opt/jpeg/ --with-vpx=/usr/local/opt/libvpx/ --with-tiff= /usr/local/opt/libtiff/
Then download a version of PHP from the PHP official website. It can be different from the version in the system, it doesn’t matter.
It should be noted here that the MAC system has a system file protection function (SIP) Some directories will be inaccessible even to ROOT users, because we only want to replace PHP, not APACHE, so when PHP compiles and generates libphp5.so required by apache, it needs to put this file in /usr /libexec/apache2/ directory, and this directory is protected, so you need to turn off the system protection first. The shutdown steps are as follows:
1. Restart the MAC, press and hold the command+R key, and wait until you see the MAC icon Release
2. After booting into Recovery Mode, find Terminal in the tools menu and open it,
3. Use the command: csrutil disable; to close it, and then reboot.
If you want to enable it again in the future, you can use csrutil enable;.
Then
Compile PHP
./configure --prefix=/usr/local/php/ --with-config-file-path=/usr/local/php/ --with-apxs2 --enable-sockets --enable -mbstring --with-bz2=shared --with-ic --with-mysql --with-gd=/usr/local/gd2/ --with-pdo-mysql
Here we encounter another evil dependency system To deal with it, first report:
'X11/xpm.h' file not found
Follow this prompt and you need to install the libXpm package, as follows:
libXpm-3.5.5.tar.bz2
But when installing this package, it will prompt:
No package 'x11' found
No package 'xproto' found
Reinstall:
libX11-1.5.0.tar.gz
With the xproto package,
there will be a series of dependent packages when installing X11, there is no way, slow Slow installation
There is a note here
Because there are too many packages, and these packages use pkg-config to check dependencies, so pkg-config needs to be installed (this can also be installed using brew,)
and pkg -config checks the dependencies through the environment variable: PKG_CONFIG_PATH to check the pc file of the corresponding package, so my method is to install all these packages in a directory, and then configure the environment variable:
export PKG_C/local/xproto /lib/pkgconfig:/usr/lib/pkgconfig:/usr/local/lib/pkgconfig
Next, if it prompts which package is missing, go to the corresponding package, download it in tar.gz format,
then unzip it,
unify the installation path :
./configure —prefix=/usr/local/xproto
Tips: Most of the corresponding packages can be passed through
lists.freedesktop.org
and
ftp://ftp.x.org/pub/X11R7.7 /
I found

in these two. I don’t want to bother to find it. I packaged the packages I downloaded during the installation process and put them up for everyone to download. The address is as follows:

http://download.csdn.net/detail /sdomain/9432886

After all packages are installed, finally install

libXpm-3.5.5.tar.bz2
,

finally compile PHP and add the xpm extension.

./configure --prefix=/usr/local/php/ --with-config-file-path=/usr/local/php/ --with-apxs2 --enable-sockets --enable-mbstring -- with-bz2=shared --with-ic --with-mysql --with-gd=/usr/local/gd2/ --with-pdo-mysql --with-xpm-dir=/usr/local/xproto

There is no problem with configure, but when making, it prompts that the gd.c file cannot find the header file X11/xpm.h. It is very strange. I clearly specified —with-xpm-path=/usr/local/xproto, but There is the file xpm.h under include/X11/ in this path,

After changing --with-xpm-path=/usr/local/xproto/include like this, configure failed.
Changing the include path in gd.c to include/X11/xpm.h also didn’t work.
Finally I changed / Copy the X11 folder under usr/local/xproto/include to the ext/gd/ folder under the PHP source code. There is no problem with compilation, and there is no problem with make install.
I guess it is a problem with the path environment variable. If you change $ It is probably possible to add /usr/local/xproto/include to PATH. If you are interested, you can try it.

The above introduces the PHP environment that comes with mac OS X. There is no freetype solution, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement
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
PHP and Python: Different Paradigms ExplainedPHP and Python: Different Paradigms ExplainedApr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP and Python: A Deep Dive into Their HistoryPHP and Python: A Deep Dive into Their HistoryApr 18, 2025 am 12:25 AM

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

Choosing Between PHP and Python: A GuideChoosing Between PHP and Python: A GuideApr 18, 2025 am 12:24 AM

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP and Frameworks: Modernizing the LanguagePHP and Frameworks: Modernizing the LanguageApr 18, 2025 am 12:14 AM

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHP's Impact: Web Development and BeyondPHP's Impact: Web Development and BeyondApr 18, 2025 am 12:10 AM

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

How does PHP type hinting work, including scalar types, return types, union types, and nullable types?How does PHP type hinting work, including scalar types, return types, union types, and nullable types?Apr 17, 2025 am 12:25 AM

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values ​​and handle functions that may return null values.

How does PHP handle object cloning (clone keyword) and the __clone magic method?How does PHP handle object cloning (clone keyword) and the __clone magic method?Apr 17, 2025 am 12:24 AM

In PHP, use the clone keyword to create a copy of the object and customize the cloning behavior through the \_\_clone magic method. 1. Use the clone keyword to make a shallow copy, cloning the object's properties but not the object's properties. 2. The \_\_clone method can deeply copy nested objects to avoid shallow copying problems. 3. Pay attention to avoid circular references and performance problems in cloning, and optimize cloning operations to improve efficiency.

PHP vs. Python: Use Cases and ApplicationsPHP vs. Python: Use Cases and ApplicationsApr 17, 2025 am 12:23 AM

PHP is suitable for web development and content management systems, and Python is suitable for data science, machine learning and automation scripts. 1.PHP performs well in building fast and scalable websites and applications and is commonly used in CMS such as WordPress. 2. Python has performed outstandingly in the fields of data science and machine learning, with rich libraries such as NumPy and TensorFlow.

See all articles

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)
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Will R.E.P.O. Have Crossplay?
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Atom editor mac version download

Atom editor mac version download

The most popular open source editor