不用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/mysqlalias 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.soInclude /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将会看到

 
屏幕快照 2017-09-07 下午4.57.36.png

可以通过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 NoneAllowOverride 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

 
屏幕快照 2017-09-07 下午5.32.28.png

访问localhost:8080/info.php

 
屏幕快照 2017-09-07 下午5.36.30.png

大功告成!几乎热泪盈眶!!!

mac配置php7运行环境的更多相关文章

  1. Windows2016的 IIS中配置PHP7运行环境

    Windows2016的 IIS中配置PHP7运行环境 在Windows 的IIS(8.0)中搭建PHP运行环境: 一:安装IIS服务器 .进入控制面板>>程序和功能>>打开或 ...

  2. Mac配置java运行环境的步骤

    官网下载地址:jdk1.8版本的  http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.htm ...

  3. Windows服务器安装配置PHP7.0环境图文教程

    摘自http://www.111cn.net/phper/linux-php/109865.htm Windows服务器安装配置PHP7.0环境图文教程 www.111cn.net 更新:2016-0 ...

  4. PHP7运行环境搭建(Windows7)

    注:本文来源于<    PHP7运行环境搭建(Windows7)   > php7号称能直追facebook的HHVM,为了体验一把传说中的高性能,我特意在本地电脑上尝试着安装了php7, ...

  5. Mac配置Java开发环境

    笔者从Window上转到Mac上做开发,一切配置都要重新开始,开发环境配置介绍如下: 1. 下载JDK 从下面链接选择合适版本的安装包进行下载...笔者下载的是jdk-9.0.1 链接:http:// ...

  6. Editplus配置java运行环境

    Editplus配置java运行环境 下载及安装: editplus官网下载地址:https://www.editplus.com/ 安装方法和安装普通exe应用程序一样,选在安装路径,下一步下一步, ...

  7. 【Java SE】如何安装JDK以及配置Java运行环境

    摘要:不管是作为苦逼的Java码农,还是高端大气的Java系统架构师,如果不会安装JDK以及配置Java运行环境,那就巧妇难为无米之炊,不能进行Java后续的代码编写.当然如果你是Myeclipse编 ...

  8. Sublime Text3配置Lua运行环境

    Sublime Text3配置Lua运行环境 前言 要问现在哪个编译器最能扛得住潮流,要数Sublime Text3了,由于它的轻量,插件丰富,美观,造就了一大批粉丝(本菜鸡也是哦) 在以前的工作中使 ...

  9. PHP+FastCGI+Nginx配置PHP运行环境方法

    PHP+FastCGI+Nginx配置PHP运行环境 Nginx不支持对外部程序的调用,所以必须通过FastCGI接口实现对外部程序的调用从而实现对客户端动态页面请求的处理. CGI的英文全称为Com ...

随机推荐

  1. vscode 配置Git

    步骤: 下载Git客户端 配置环境变量 设置vscode与Git的关联 重启 步骤一: 该网址,下载即可. https://git-scm.com/downloads 步骤二: 计算机 > 属性 ...

  2. weblogic基本目录介绍,位数查看,启动与发布项目,修改JVM参数,设置项目为默认项目

    这里的基本目录%base%表示安装目录,如我的目录为:E:/weblogic就是%base% 1.weblogic目录介绍 weblogic主要的目录介绍: 1.日志目录: 每个domain(域)都有 ...

  3. SpringBoot整合日志

    Java日志 日志的接口层.抽象层 日志的实现 JCL(Jakarta Commons Logging) SLF4J(Simple Logging Facade for Java) Jboss-Log ...

  4. 笔记软件 notion

    笔记软件 notion :     https://www.notion.so 注册:zengxinle@126.com     团队:Hopesun

  5. DataTables 1.10.x与1.9.x参数名对照表

    Datatables 1.10.x在命名上与1.9.x的有区别,新版的使用的是驼峰的命名规则,而之前的是采用匈牙利命名规则 当然,这些变化都是向下兼容的,你可以继续使用旧版本的api方法的参数和名称. ...

  6. jdk8系列一、jdk8 Lamda表达式语法、接口的默认方法和静态方法、supplier用法

    一.简介 毫无疑问,Java 8是Java自Java 5(发布于2004年)之后的最重要的版本.这个版本包含语言.编译器.库.工具和JVM等方面的十多个新特性. 在本文中我们将学习这些新特性,并用实际 ...

  7. dubbo系列一、dubbo背景介绍、微服务拆分

    一.背景 随着互联网的发展,网站应用的规模不断扩大,常规的垂直应用架构已无法应对,分布式服务架构以及流动计算架构势在必行,亟需一个治理系统确保架构有条不紊的演进. 二.传统应用到分布式应用的演进过程 ...

  8. oracle instantclient_11_2插件安装

    1.安装plsql 2.instantclient_11_2下载,解压到目录 D:\DevTools\instantclient_11_2 3.打开plsql, 点击“取消” 4.选择“工具”--&g ...

  9. 转载:2.2.2 配置项的语法格式《深入理解Nginx》(陶辉)

    原文:https://book.2cto.com/201304/19627.html 从上文的示例可以看出,最基本的配置项语法格式如下: 配置项名 配置项值1 配置项值2 - ; 下面解释一下配置项的 ...

  10. sklearn.model_selection模块

    后续补代码 sklearn.model_selection模块的几个方法参数