mac配置php7运行环境
不用mac自带的apache和php,安装自己想要的版本。配置过程一直采坑,需要有闲时间和好的心理素质才行,哈哈,因为网上很教程都有纰漏之处,所以先把采坑无数后发现的个人认为最好的一个教程链接放在这里
https://github.com/nodejh/nodejh.github.io/issues/25
下面记录我的采坑过程。
安装mysql
官网https://www.mysql.com/downloads/
下载mysql,有问题百度。下载后安装,安装过程中会有一个临时密码的提示,要注意保存一下,后面会用到。安装完毕进入系统偏好设置
在最下面找到mysql图标并打开,点击Start MySQL Server
启动mysql。命令行cd到/usr/local/mysql/bin
,分别执行alias mysql=/usr/local/mysql/bin/mysql
和alias mysqladmin=/usr/local/mysql/bin/mysqladmin
,这两条命令是为了方便直接打开 iTerm 就可以运行mysql命令,而不是必须进入mysql安装目录才能运行。接下来,重置密码。执行命令mysqladmin -u root -p password ***
***是你的新密码。回车后提示输入密码,此时数次刚刚保存的临时密码,我的是)6m1d/m<joVi。
此时提示mysqladmin: [Warning] Using a password on the command line interface can be insecure.Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.
说明已经重置密码成功。我在这里浪费了很多时间,以为这是错误提示,其实已经ok了。
登录mysql。命令mysql -u root -p
,然后输入刚刚重置的密码。然后登录成功会跳出提示信息
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1032
Server version: 5.7.19 MySQL Community Server (GPL)
Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
大意是说sql命令以;结尾,当前mysql版本是5.7.19。另外我们也可以通过sql命令select version();
来查看版本。用exit;
退出登录。安装完毕。
apache使用mac自带的
(开始的时候想用mac自带apache来着,后来和配置php7时候各种问题,放弃了使用mac自带apache)
基本用法的命令如下:apachectl -v
查看版本,提示Server version: Apache/2.4.25 (Unix)
sudo apachectl start
启动sudo spachectl stop
停止sudo apachectl restart
重启
相关目录:
apache日志/private/var/log/apache2/error_log
apache配置主文件/etc/apache2/httpd.conf
apache的vhost配置/etc/apache2/extra/httpd-vhost.conf
安装php7.0
参考博客http://www.cnblogs.com/redirect/p/6131751.html
添加brew的php扩展库(mac上没有php的包,需要绑定其他人的git仓库,命令brew tap github_user/repo),执行如下命令
brew update
brew tap homebrew/dupes
brew tap homebrew/php
可以使用brew options php70
来查看安装php的选项。注意如果使用apache作为web server,安装php命令要加--with-apache
选项,如果使用nginx作为web server,安装php命令要加--with-fpm
选项,我的安装命令和选项brew install php70 --with-apache --width-apxs2 --with-gmp --with-imap --with-tidy --with-debug
,然后我按照教程http://www.cnblogs.com/redirect/p/6131751.html
上执行brew link php70
开启php7.0的进程,但是查看php -v
提示版本还是php5.6,执行brew unlink php56
来关闭php5.6的进程但是报错提示Error: No such keg: /usr/local/Cellar/php56
,反复试了很多次耽误了时间,然后我查其他资料,执行brew install php-version
安装了php-version
来切换php版本,php-version是一个帮助管理从brew安装的php版本切换的工具。安装完执行php-veision 7.0.22
切换版本,然后php -v
版本果然切换到php7.0.22了。
下面开始修改apache配置文件。又遇见很耗时的一个坑。
按照上面的教程,打开apache配置文件sudo vi /etc/apache2/httpd.conf
,不加sudo
权限不够没办法修改,注释(前面加#)掉LoadModule php5_module libexec/apache2/libphp5.so
和Include /private/etc/apache2/other/*.conf
两句,然后加上LoadModule php7_module /usr/local/opt/php70/libexec/apache2/libphp7.so
这句,注意,libphp7.so的地址是对应自己电脑文件所在的地址,于是我去检查下我的libphp7.so文件是不是上面命令中的地址。结果发现/usr/local/opt/php70/
下并没有libphp7
目录,搞了半天不知道怎么整,于是brew uninstall php7.0.22
卸载php7.0,卸载后/usr/local/opt/
下面没有了php70
文件夹,然后重新安装php7.0,并且又加了一个选项--httpd24
,因为看其他教程里有加。brew install php70 --with-apxs2 --with-apache --with-gmp --with-imap --with-tidy --with-debug --with-httpd24
,然后会提示如下
./configure --prefix=/usr/local/Cellar/php70/7.0.22_14 --localstatedir=/usr/local/var --sysconfdir=/usr/local/etc/php/7.0 --with-config-file-path=/usr/local/etc/php/7.0 --with-config-file-scan-dir=/us
Last 15 lines from /Users/yanhaoqi/Library/Logs/Homebrew/php70/01.configure:
checking for Kerberos support... /usr
checking whether to use system default cipher list instead of hardcoded value... no
checking for krb5-config... /usr/bin/krb5-config
checking for RAND_egd... no
checking for pkg-config... no
checking for OpenSSL version... >= 0.9.8
checking for CRYPTO_free in -lcrypto... yes
checking for SSL_CTX_set_ssl_version in -lssl... yes
checking for PCRE library to use... bundled
checking whether to enable PCRE JIT functionality... yes
checking whether to enable the SQLite3 extension... yes
checking bundled sqlite3 library... yes
checking for ZLIB support... yes
checking if the location of ZLIB install directory is defined... no
configure: error: Cannot find libz
其实前面最开始安装php7的时候记得也有这个提示,当时也没有在意。这时候执行php -v
提示版本是php5.6
,执行php-version
提示Sorry, but you do not seem to have any PHP versions installed.
,折腾半天后来查到资料,需要执行xcode-select --install
,然后按照提示去安装,安装完毕后再重新装php7.0,brew install php70 --with-apxs2 --with-apache --with-gmp --with-imap --with-tidy --with-debug --with-httpd24
,这次没有提示configure: error: Cannot find libz
,然后查看版本是7.0,php-version
也提示7.0.22
,并且找到了/usr/local/opt/php70/libexec/apache2/libphp7.so
文件。
ok,继续apache配置文件。
注释完上面所说的两句话后,加上如下配置
LoadModule php7_module /usr/local/opt/php70/libexec/apache2/libphp7.so
<FilesMatch .php$>
SetHandler application/x-httpd-php
</FilesMatch>
<IfModule php7_module>
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
<IfModule dir_module>
DirectoryIndex index.html index.php
</IfModule>
</IfModule>
在#ServerName www.example.com:80
后面加上ServerName localhost:80
,否则下面重启apache的时候回报错提示AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using ::1. Set the 'ServerName' directive globally to suppress this message
这是个更大的坑。我卡在这里将近两天,各种博客资料查询各种尝试。曲折过程已经忘记,现在只记录下结果。
我在上面写apache用mac自带的,版本是Apache/2.4.25 (Unix)
,但是后面经过我安装php7的各种折腾后,记不清在什么时候我通过brew安装了Apache/2.4.27
我想执行brew uninstall httpd24
卸载掉但是提示Refusing to uninstall /usr/local/Cellar/httpd24/2.4.27 because it is required by php70 7.0.22_14, which is currently installed.
,php7引用了Apache/2.4.27。而且,brew安装的Apache/2.4.27,配置文件所在目录/usr/local/etc/apache2/2.4/httpd.conf
,其编译安装的目录/usr/local/Cellar/httpd24/2.4.27
。oh my god!!!上面修改apache配置弄了这么长时间,配置的文件根本就不是正确的文件!
apache配置的正确姿势
执行命令使用管理员权限为通过brew安装的apache配置为自动启动。
sudo cp -v /usr/local/Cellar/httpd24/2.4.27/homebrew.mxcl.httpd24.plist /Library/LaunchDaemons
sudo chown -v root:wheel /Library/LaunchDaemons/homebrew.mxcl.httpd24.plist
sudo chmod -v 644 /Library/LaunchDaemons/homebrew.mxcl.httpd24.plist
sudo launchctl load /Library/LaunchDaemons/homebrew.mxcl.httpd24.plist
我的apache编译安装路径是/usr/local/Cellar/httpd24/2.4.27
,如果你的路径不是这个,自行替换就好了。
此时浏览器访问localhost
将会看到

可以通过ps -aef | grep httpd
命令查看apache服务是否启动,如果apache正在运行会看到一些http进程。
sudo vi /usr/local/etc/apache2/2.4/httpd.conf
修改php模块配置及apache端口
将LoadModule php7_module /usr/local/Cellar/php70/7.0.22_14/libexec/apache2/libphp7.so
替换为LoadModule php7_module /usr/local/Cellar/php70/7.0.22_14/libexec/apache2/libphp7.so
找到代码块
<IfModule dir_module>
DirectoryIndex index.html
</IfModule>
替换为
<IfModule dir_module>
DirectoryIndex index.php index.html
</IfModule>
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>
修改ServerName为ServerName localhost:8080
Listen:8080
apache监听了8080端口,如果修改的话直接改端口号即可。
修改web服务的根目录在自己用户主目录下方便开发
找到DocumentRoot "/usr/local/var/www/htdocs"
修改为DocumentRoot "/Users/yanhaoqi/sites"
修改下面的<Directory>
为<Directory "/Users/yanhaoqi/sites">
修改AllowOverride None
为AllowOverride All
取消注释,使用mod_rewrite
模块 LoadModule rewrite_module libexec/mod_rewrite.so
修改用户和用户组
修改User和Group如下
User yanhaoqi
Group staff
用户主目录下新建sites目录
cd /Users/yanhaoqi
mkdir sites
sudo vi sites/index.html
sudo vi sites/info.php
在新建的index.html中编辑<h1>yanhaoqi web root</h1>
在新建的info.php中编辑
<?php
phpinfo();
?>
保存退出后重启apachesudo apachectl restart
访问localhost:8080

访问localhost:8080/info.php

大功告成!几乎热泪盈眶!!!
mac配置php7运行环境的更多相关文章
- Windows2016的 IIS中配置PHP7运行环境
Windows2016的 IIS中配置PHP7运行环境 在Windows 的IIS(8.0)中搭建PHP运行环境: 一:安装IIS服务器 .进入控制面板>>程序和功能>>打开或 ...
- Mac配置java运行环境的步骤
官网下载地址:jdk1.8版本的 http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.htm ...
- Windows服务器安装配置PHP7.0环境图文教程
摘自http://www.111cn.net/phper/linux-php/109865.htm Windows服务器安装配置PHP7.0环境图文教程 www.111cn.net 更新:2016-0 ...
- PHP7运行环境搭建(Windows7)
注:本文来源于< PHP7运行环境搭建(Windows7) > php7号称能直追facebook的HHVM,为了体验一把传说中的高性能,我特意在本地电脑上尝试着安装了php7, ...
- Mac配置Java开发环境
笔者从Window上转到Mac上做开发,一切配置都要重新开始,开发环境配置介绍如下: 1. 下载JDK 从下面链接选择合适版本的安装包进行下载...笔者下载的是jdk-9.0.1 链接:http:// ...
- Editplus配置java运行环境
Editplus配置java运行环境 下载及安装: editplus官网下载地址:https://www.editplus.com/ 安装方法和安装普通exe应用程序一样,选在安装路径,下一步下一步, ...
- 【Java SE】如何安装JDK以及配置Java运行环境
摘要:不管是作为苦逼的Java码农,还是高端大气的Java系统架构师,如果不会安装JDK以及配置Java运行环境,那就巧妇难为无米之炊,不能进行Java后续的代码编写.当然如果你是Myeclipse编 ...
- Sublime Text3配置Lua运行环境
Sublime Text3配置Lua运行环境 前言 要问现在哪个编译器最能扛得住潮流,要数Sublime Text3了,由于它的轻量,插件丰富,美观,造就了一大批粉丝(本菜鸡也是哦) 在以前的工作中使 ...
- PHP+FastCGI+Nginx配置PHP运行环境方法
PHP+FastCGI+Nginx配置PHP运行环境 Nginx不支持对外部程序的调用,所以必须通过FastCGI接口实现对外部程序的调用从而实现对客户端动态页面请求的处理. CGI的英文全称为Com ...
随机推荐
- js 获取当前日期或者前、后N天yyyy-MM-dd的方法
//js获取当前日期.当前日期前.后N天的标准年月日 //day=0为当前天,day=7为前7天,day=-7为当前日期的后7天 function getstartdate(day) { ...
- ichartjs一分钟快速入门教程
1.构建项目环境 由于ichartjs是一个js库,所以只要将ichart.js加入你页面的head中就完成了ichartjs的运行环境.代码如下: <script type="tex ...
- Mybatis进阶学习笔记——输入映射
1.输入映射 输入映射支持的类型: 1) 基本的类型,int,String,double 等(*)2) JavaBean 类型(*)3) 包装JavaBean 类型(对象里面包含另一个对象) 1.1基 ...
- pl/sql Devloper 关键字转为大写
英文版: peferences-editor-keyword case -uppercase 中文版:
- Python 对图片进行人脸识别
import cv2 def detect(path): img = cv2.imread(path) cascade = cv2.CascadeClassifier("/vagrant/d ...
- js代码解析原则
js引擎在读取js代码时会进行两个步骤,第一个步骤是解释,第二个步骤是执行. 解释就是先通篇扫描所有的Js代码,然后把所有声明提升到顶端,第二步是执行,执行就是执行代码的操作. 例: 例子1: < ...
- malloc()函数(Linux程序员手册)及函数的正确使用【转】
转自:https://blog.csdn.net/david_xtd/article/details/7311204 名称 malloc,free,calloc,realloc--分配和释放动态内存 ...
- git命令行工作环境配置【转】
转自:http://www.cocoachina.com/ios/20171115/21163.html 本文为CocoaChina网友whf5566投稿 前言 笔者一直使用git的图形化工具sour ...
- zabbix通过简单shell命令监控elasticsearch集群状态
简单命令监控elasticsearch集群状态 原理: 使用curl命令模拟访问任意一个es节点可以反馈的集群状态,集群的状态需要为green curl -sXGET http://serverip: ...
- Centos6安装FreeSWITCH 1.5时./configure问题解决记录
系统:Centos 6.4 64位: FreeSWITCH版本:1.5 具体的安装过程参考FreeSWITCH 官网wiki (也可以参考我的博客<Centos6安装FreeSWITCH> ...