macos编译安装php与详细配置,IMABSN.COM

其实也有不少能用的集成开发环境,但是我需要各种模块、配置,修改起来特别麻烦,于是就想自己编译安装。经过不断尝试,终于见到成果了,因为具体环境的问题复杂多变,本文操作只能当做参考,具体问题要具体对待。

注:当前我的系统是10.15。

准备macOS 10.14+

nginx-1.10.1,php-5.6.26,pcre-8.39,openssl-1.0.1等

MySQL 安装包(.dkg)

安装准备

① 将 /usr/local/ 的 owner 改为当前用户 sudo chown -R username /usr/local/

② 新建目录 etc  存放所有的配置文件 ,并将 nginx、php 的配置文件分开存放

mkdir -R /usr/local/etc/nginx

mkdir -R /usr/local/etc/php5

nginx 安装./configure --prefix=/usr/local/nginx --conf-path=/usr/local/etc/nginx/nginx.conf --with-pcre=../pcre-8.39 --with-openssl=../openssl-1.0.1u --with-http_v2_module --with-http_ssl_module --with-http_gunzip_module --with-http_gzip_static_module

中间会有提示Operating system: i686-apple-darwinDarwin Kernel Version 15.6.0: Mon Aug 29 20:21:34 PDT 2016; root:xnu-3248.60.11~1/RELEASE_X86_64

WARNING! If you wish to build 64-bit library, then you have toinvoke './Configure darwin64-x86_64-cc' *manually*.

You have about 5 seconds to press Ctrl-C to abort.

暂时可以无视,继续就行。

等待结束之后cd objs

vi Makefile

修改./config 为 ./Configure darwin64-x86_64-cc

然后就可以make && make install

至此,nginx 安装编译完成。

为方便使用,还可以这样ln -s /usr/local/nginx/sbin/nginx /usr/local/bin/

前提是 /usr/local/bin/ 已经加入环境变量里。

至于配置,待 php 安装完成后一起配置。

MySQL 安装

这个是最简单的了,直接从官网下载 dkg 双击安装即可,需要注意的是,再安装完成时,会有一个弹出窗口告诉你,root 的初始密码,而且需要修改之后才可以正常登陆。

php 安装

php 安装有两种选择,一个是编译的时候直接使用 php 默认的参数,这样的话,在使用的时候需要什么模块就需要另外再编译了,这样的好处是到时可以按需编译,需要的再添加,缺点就是麻烦,要一个一个编译,另一个就是一次性把可能需要的所有模块都编译进去。

这里选的是第二种,因为,第一种的编译很简单,只有在后期添加模块的时候才是难点。

另提供第一种的简单编译命令./configure --prefix=/usr/local/php && make && make install

下面开始第二种的详细编译过程。

①需要安装  php 所需要的依赖,视个人情况而定,需要用什么自己找。

我这里的依赖有 gettext,icu,libmcrypt,mcrypt,mhash,openssl等。

安装依赖的时候直接使用./configure && make && make install

这样可以避免很多各种各样的错误,遇到错误多百度。注:  在安装 mcrypt 时,可能报错rfc2440.c:26:10: fatal error: 'malloc.h' file not found

#include 

^

1 error generated.

make[2]: *** [rfc2440.o] Error 1

make[1]: *** [all-recursive] Error 1

make: *** [all] Error 2

只需要找到源码中的src/rfc2440.c 第26行#include 

改为

即可

依赖安装完成之后就可以编译  php5  了。

php5编译参数./configure  --prefix=/usr/local/php5 --with-config-file-path=/usr/local/etc/php5/ --with-config-file-scan-dir=/usr/local/etc/php5/php.d --with-fpm-user=lijianqiang --with-fpm-group=staff --enable-fpm --enable-opcache --disable-fileinfo --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-exif --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-ftp --enable-intl --with-xsl --with-gettext --enable-zip --enable-soap --disable-debug

随后就可以make && make install

编译  php7  的时候

php7编译参数./configure --prefix=/usr/local/php7 --with-config-file-path=/usr/local/etc/php7/ --enable-fpm --with-config-file-scan-dir=/usr/local/etc/php7/php.d --with-fpm-user=lijianqiang --with-fpm-group=staff --enable-fpm --enable-mysqlnd --with-mysqli --with-pdo-mysql --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-exif --enable-sysvsem --with-curl --enable-mbregex --enable-inline-optimization --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-ftp --enable-intl --with-xsl --with-gettext --enable-zip --enable-soap --disable-debug --with-openssl

make过程中遇到报错Undefined symbols for architecture x86_64:

"_PKCS5_PBKDF2_HMAC", referenced from:

_zif_openssl_pbkdf2 in openssl.o

"_TLSv1_1_client_method", referenced from:

_php_openssl_setup_crypto in xp_ssl.o

"_TLSv1_1_server_method", referenced from:

_php_openssl_setup_crypto in xp_ssl.o

"_TLSv1_2_client_method", referenced from:

_php_openssl_setup_crypto in xp_ssl.o

"_TLSv1_2_server_method", referenced from:

_php_openssl_setup_crypto in xp_ssl.o

ld: symbol(s) not found for architecture x86_64

clang: error: linker command failed with exit code 1 (use -v to see invocation)

make: *** [sapi/cli/php] Error 1

因为找不到openssl的动态链接库,需要ln -s /usr/local/ssl/lib/* /usr/local/lib/

复制一份配置文件cp php.ini-development /usr/local/php5/etc/php.ini

同样可以使用ln -s /usr/local/php5/bin/php /usr/local/bin/

ln -s /usr/local/php5/bin/phpize /usr/local/bin/

ln -s /usr/local/php5/sbin/php-fpm /usr/local/bin/

配置

① 配置 phpcp /usr/local/php5/etc/php-fpm.conf.default php-fpm.conf

修改 php-fpm.confuser = nobody

group = nobody

listen = 127.0.0.1:9000

listen.owner = nobody

listen.group = nobody

修改为user = lijianqiang

group = staff

listen = var/run/php-fpm.sock

listen.owner = lijianqiang

listen.group = staff

修改 /usr/local/nginx/conf/nginx.conf#user nobody;

改为user lijianqiang staff;

在 server 段添加root /Users/lijianqiang/Web;

autoindex on;

index index.html index.htm index.php

修改#location ~ \.php$ {

#    root           html;

#    fastcgi_pass   127.0.0.1:9000;

#    fastcgi_index  index.php;

#    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;

#    include        fastcgi_params;

#}

为location ~ \.php$ {

fastcgi_pass   unix:/usr/local/php5/var/run/php-fpm.sock;

fastcgi_index  index.php;

include        fastcgi.conf;

}

最后删除多余配置即可

启动&&重启sudo nginx //启动

sudo nginx -s quit //停止

sudo nginx -s reload //重启

sudo php-fpm //启动

sudo killall php-fpm && sudo php-fpm //重启

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值