基于MAC的 LNMP环境搭建, PHP5.6,PHP7.2.3 杂记

最近把自己MAC格式化了,然后重装了下LNMP 环境,遇到了各种坑,MAC升级10.13.4也有坑,不多说直接看路径,下面全部针对熟手

[php7]
sudo ./configure --prefix=/Users/heweijun/www/server/php --with-config-file-path=/Users/heweijun/www/server/php/etc --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-libdir=lib --with-iconv=/BuildRoot/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.Internal.sdk/usr --with-libxml-dir=/BuildRoot/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.Internal.sdk/usr --with-openssl=/usr/local/opt/openssl --with-kerberos=/BuildRoot/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.Internal.sdk/usr --with-zlib=/usr/local/opt/zlib --enable-bcmath --with-bz2=/BuildRoot/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.Internal.sdk/usr --enable-calendar --with-curl=/BuildRoot/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.Internal.sdk/usr --enable-exif --enable-ftp --with-gd --with-png-dir=/BuildRoot/Library/Caches/com.apple.xbs/Binaries/apache_mod_php/install/TempContent/Root/usr/local --with-jpeg-dir=/BuildRoot/Library/Caches/com.apple.xbs/Binaries/apache_mod_php/install/TempContent/Root/usr/local --with-ldap-sasl=/BuildRoot/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.Internal.sdk/usr --with-libedit=/BuildRoot/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.Internal.sdk/usr --enable-mbstring --enable-mbregex --with-mysqli=mysqlnd --without-pear --with-pear=no --with-pdo-mysql=mysqlnd --with-mysql-sock=/var/mysql/mysql.sock --disable-phpdbg --with-readline=/BuildRoot/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.Internal.sdk/usr --enable-shmop --enable-soap --enable-sockets --enable-sysvmsg --enable-wddx --with-xmlrpc --with-iconv-dir=/BuildRoot/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.Internal.sdk/usr --with-xsl=/BuildRoot/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.Internal.sdk/usr --enable-zip YACC=/BuildRoot/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/bison --enable-opcache
config.status: creating php7.spec
config.status: creating main/build-defs.h
config.status: creating scripts/phpize
config.status: creating scripts/man1/phpize.1
config.status: creating scripts/php-config
config.status: creating scripts/man1/php-config.1
config.status: creating sapi/cli/php.1
config.status: creating sapi/fpm/php-fpm.conf
config.status: creating sapi/fpm/www.conf
config.status: creating sapi/fpm/init.d.php-fpm
config.status: creating sapi/fpm/php-fpm.service
config.status: creating sapi/fpm/php-fpm.8
config.status: creating sapi/fpm/status.html
config.status: creating sapi/cgi/php-cgi.1
config.status: creating ext/phar/phar.1
config.status: creating ext/phar/phar.phar.1
config.status: creating main/php_config.h
config.status: executing default commands

--with-iconv=/usr/local/bin/libiconv
ln -s /Users/heweijun/www/server/extension/php/libiconv /usr/local/bin/libiconv

[php5]
sudo ./configure --prefix=/Users/heweijun/www/server/php5 --with-config-file-path=/Users/heweijun/www/server/php5/etc --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-zlib=/usr/local/opt/zlib --with-curl=/usr/local/opt/curl --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --enable-mbregex --enable-mbstring --enable-ftp --with-gd --enable-gd-native-ttf --with-openssl=/usr/local/opt/openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext=/usr/local/opt/gettext --disable-fileinfo --enable-opcache --enable-session --with-iconv=/usr/local/opt/libiconv --with-freetype-dir=/usr/local/opt/freetype --with-jpeg-dir=/Users/heweijun/www/server/extension/php/libjpeg --with-png-dir=/Users/heweijun/www/server/extension/php/libpng --with-libxml-dir=/Users/heweijun/www/server/extension/php/libxml2 --with-freetype-dir=/usr/local/opt/freetype --with-mcrypt --with-mhash --enable-exif --enable-sysvsem

【notice】
苹果在OS X 10.11以上中引入的SIP特性使得即使加了 sudo (也就是具有root权限)也无法修改系统级的目录,其中就包括了 /usr/bin 。要解决这个问题有两种做法:一种是比较不安全的就是关闭SIP,也就是rootless特性;另一种是将本要链接到 /usr/bin 下的改链接到 /usr/local/bin 下就好了

[创建全局执行脚本 nginx/php7/php5同理,注意修改对应路径]
ln -s /Users/heweijun/www/server/php5/bin/php /usr/local/bin/php5
ln -s /Users/heweijun/www/server/php5/bin/phpize /usr/local/bin/phpize5
ln -s /Users/heweijun/www/server/php5/sbin/php-fpm /usr/local/bin/php-fpm5

./configure --with-php-config=/Users/heweijun/www/server/php5/bin/php-config
/Users/heweijun/www/server/extension/php

--with-openssl=/usr/local/opt/openssl

Password:
Installing shared extensions: /Users/heweijun/www/server/php5/lib/php/extensions/no-debug-non-zts-20131226/
Installing PHP CLI binary: /Users/heweijun/www/server/php5/bin/
Installing PHP CLI man page: /Users/heweijun/www/server/php5/php/man/man1/
Installing PHP FPM binary: /Users/heweijun/www/server/php5/sbin/
Installing PHP FPM config: /Users/heweijun/www/server/php5/etc/
Installing PHP FPM man page: /Users/heweijun/www/server/php5/php/man/man8/
Installing PHP FPM status page: /Users/heweijun/www/server/php5/php/php/fpm/
Installing PHP CGI binary: /Users/heweijun/www/server/php5/bin/
Installing PHP CGI man page: /Users/heweijun/www/server/php5/php/man/man1/
Installing build environment: /Users/heweijun/www/server/php5/lib/php/build/
Installing header files: /Users/heweijun/www/server/php5/include/php/
Installing helper programs: /Users/heweijun/www/server/php5/bin/
program: phpize
program: php-config
Installing man pages: /Users/heweijun/www/server/php5/php/man/man1/
page: phpize.1
page: php-config.1
/Users/heweijun/www/php7/php-5.6.34/build/shtool install -c ext/phar/phar.phar /Users/heweijun/www/server/php5/bin
ln -s -f phar.phar /Users/heweijun/www/server/php5/bin/phar
Installing PDO headers: /Users/heweijun/www/server/php5/include/php/ext/pdo/

[php7 做默认启动设置的软连接]
ln -s /Users/heweijun/www/server/php/bin/php /usr/local/bin/php
ln -s /Users/heweijun/www/server/php/bin/phpize /usr/local/bin/phpize
ln -s /Users/heweijun/www/server/php/sbin/php-fpm /usr/local/bin/php-fpm

[PHP 扩展安装]
/usr/local/bin/phpize5
./configure --with-php-config=/Users/heweijun/www/server/php5/bin/php-config
sudo make
sudo make install
mkdir -p /Users/heweijun/www/server/php/etc

cp php.ini.product /Users/heweijun/www/server/php/etc/php.ini

sudo ./configure --user=www --group=www --prefix=/Users/heweijun/www/server/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-pcre --with-openssl=/usr/local/opt/openssl --with-http_sub_module --with-http_secure_link_module --with-http_v2_module
--with-http_v2_module [开启NGINX 最新 的 GRPC模块]

/Users/heweijun/www/server/nginx_log [log path]

[nginx 进程查杀]
    sudo ps -ef|grep nginx|awk '{print $2}'|xargs kill -9
    sudo ln -s /Users/heweijun/www/server/nginx/sbin/nginx /usr/local/bin/nginx
// 通过 killall 命令
killall nginx
// 通过 pkill 命令,类似于 pgrep + kill
pkill nginx
// 通过先查找再 kill 的方式
ps -ef | grep nginx | grep -v grep | awk '{print $2}' | xargs kill -9
// 用 cut -c 来截取指定位置的字符串
ps -ef | grep nginx | grep -v grep | cut -c 11-15 | xargs kill -9
// 通过 pgrep 指令,根据名字找出所有包含该名字的进程号
pgrep nginx | xargs kill -9

// 通过 pidof 指令,根据进程全名找出进程号
pidof nginx | kill -9

// 除了管道符的方式,也可以用命令替换,这样就不用通过 xargs 转换参数了
kill -9 `pgrep nginx`

nginx path prefix: "/Users/heweijun/www/server/nginx"
nginx binary file: "/Users/heweijun/www/server/nginx/sbin/nginx"
nginx modules path: "/Users/heweijun/www/server/nginx/modules"
nginx configuration prefix: "/Users/heweijun/www/server/nginx/conf"
nginx configuration file: "/Users/heweijun/www/server/nginx/conf/nginx.conf"
nginx pid file: "/Users/heweijun/www/server/nginx/logs/nginx.pid"
nginx error log file: "/Users/heweijun/www/server/nginx/logs/error.log"
nginx http access log file: "/Users/heweijun/www/server/nginx/logs/access.log"
nginx http client request body temporary files: "client_body_temp"
nginx http proxy temporary files: "proxy_temp"
nginx http fastcgi temporary files: "fastcgi_temp"
nginx http uwsgi temporary files: "uwsgi_temp"
nginx http scgi temporary files: "scgi_temp"

ln -s /Users/heweijun/www/server/nginx /usr/bin/local/nginx


------
/bin/sh: line 2: ./config: No such file or directory
make[1]: *** [/usr/local/ssl/.openssl/include/openssl/ssl.h] Error 127
make[1]: Leaving directory `/usr/local/src/nginx- 1.13.10 '
make: *** [build] Error 2
需要说明的是,我这里编译所使用的Nginx源码是 1.13.10 的。根据报错信息我们知道,出错是因为Nginx在编译时并不能在/usr/local/ssl/.openssl/ 这个目录找到对应的文件,其实我们打开/usr/local/ssl/这个目录可以发现这个目录下是没有.openssl目录的,因此我们修改Nginx编译时对openssl的路径选择就可以解决这个问题了
解决方案:
打开nginx源文件下的/usr/local/src/nginx- 1.13.10 /auto/lib/openssl/conf文件:
找到这么一段代码:
CORE_INCS="$CORE_INCS $OPENSSL/.openssl/include"
CORE_DEPS="$CORE_DEPS $OPENSSL/.openssl/include/openssl/ssl.h"
CORE_LIBS="$CORE_LIBS $OPENSSL/.openssl/lib/libssl.a"
CORE_LIBS="$CORE_LIBS $OPENSSL/.openssl/lib/libcrypto.a"
CORE_LIBS="$CORE_LIBS $NGX_LIBDL"
修改成以下代码:
CORE_INCS="$CORE_INCS $OPENSSL/include"
CORE_DEPS="$CORE_DEPS $OPENSSL/include/openssl/ssl.h"
CORE_LIBS="$CORE_LIBS $OPENSSL/lib/libssl.a"
CORE_LIBS="$CORE_LIBS $OPENSSL/lib/libcrypto.a"
CORE_LIBS="$CORE_LIBS $NGX_LIBDL"

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值