https://github.com/nodejh/nodejh.github.io/issues/25
下面記錄個人採坑過程。官網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
,而後輸入剛剛重置的密碼。而後登陸成功會跳出提示信息php
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;
退出登陸。安裝完畢。html
(開始的時候想用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
node
參考博客http://www.cnblogs.com/redirect/p/6131751.html
添加brew的php擴展庫(mac上沒有php的包,須要綁定其餘人的git倉庫,命令brew tap github_user/repo),執行以下命令python
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
,而後會提示以下mysql
./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配置文件。
註釋完上面所說的兩句話後,加上以下配置nginx
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配置爲自動啓動。git
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
將會看到github
能夠經過ps -aef | grep httpd
命令查看apache服務是否啓動,若是apache正在運行會看到一些http進程。web
sudo vi /usr/local/etc/apache2/2.4/httpd.conf
sql
將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端口,若是修改的話直接改端口號便可。
找到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
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
大功告成!幾乎熱淚盈眶!!!