Home >Backend Development >PHP Tutorial >Compile and install Apache server and PHP interpreter on Mac OS by yourself, _PHP tutorial
The compilation and installation process of Apache 2.2.27 and PHP 5.5.12 on Mac OS X 10.8.5:
Before starting, first upgrade the components of Xcode: preferences => Downloads => Download the Command Line Tools package
Then enter the Apache source code package. For most source code packages, you can use the following command to view the compilation options:
./configure --help
Configure compilation options:
./configure --prefix=/Users/levin/dev/apache2.2.27 --enable-modules=most --enable-mods-shared=all
Error report:
checking for APR-util... yes checking for gcc... /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.8.xctoolchain/usr/bin/cc checking whether the C compiler works... no configure: error: in `/Users/levin/Downloads/httpd-2.2.27': configure: error: C compiler cannot create executables See `config.log' for more details
The above error report refers to the path:
/Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.8.xctoolchain/usr/bin/cc
Does not exist
Solution:
cd /Applications/Xcode.app/Contents/Developer/Toolchains sudo ln -s XcodeDefault.xctoolchain OSX10.8.xctoolchain
Then compile and install:
make make install
Edit the configuration file httpd.conf, generally modify the listening port, user and group running Apache, server name, enable gzip and other configurations.
Enter the installed directory and start Apache:
./bin/apachectl start
Install PHP
For information on PHP compilation options, please refer to: PHP: List of core configure options - Manual
./configure --prefix=/Users/levin/dev/php5.5.12 --with-apxs2=/Users/levin/dev/apache2.2.27/bin/apxs --with-config-file-path=/Users/levin/dev/php5.5.12/etc --with-openssl --with-zlib --enable-bcmath --with-bz2 --with-curl --enable-ftp --with-gd --enable-gd-native-ttf --with-mhash --enable-mbstring --enable-soap --enable-zip --enable-sockets --with-mysql=/usr/local/mysql-5.6.12-osx10.7-x86_64 --with-mysqli=/usr/local/mysql-5.6.12-osx10.7-x86_64/bin/mysql_config --with-iconv --with-pear --enable-opcache make
The entire compilation process takes 5-10 minutes, depending on the hardware configuration. You can get a glass of milk first
An error occurred:
Undefined symbols for architecture x86_64: "_res_9_init", referenced from: _zif_dns_get_mx in dns.o _zif_dns_get_record in dns.o _zif_dns_check_record in dns.o "_res_9_search", referenced from: _zif_dns_get_mx in dns.o _zif_dns_get_record in dns.o _zif_dns_check_record in dns.o "_res_9_dn_skipname", referenced from: _zif_dns_get_mx in dns.o _zif_dns_get_record in dns.o "_res_9_dn_expand", referenced from: _zif_dns_get_mx in dns.o _php_parserr in dns.o ld: symbol(s) not found for architecture x86_64 collect2: ld returned 1 exit status make: *** [libs/libphp5.bundle] Error 1
Solution:
export LDFLAGS=-lresolv
Error:
dyld: Library not loaded: libmysqlclient.18.dylib Referenced from: /Users/levin/Downloads/php-5.5.12/sapi/cli/php Reason: image not found ... make: *** [ext/phar/phar.php] Error 133
Solution:
cd /usr/lib ln -s /usr/local/mysql-5.6.12-osx10.7-x86_64/lib/libmysqlclient.18.dylib libmysqlclient.18.dylib
Recompile and install:
make clean && make make install
The installation is complete. At this time, you need to copy a configuration file from the PHP source code directory to the etc folder of the installation directory and rename it to php.ini. Use this file when you need to change the PHP configuration.