我開始用mac環境時,感覺很無助,因為之前都是用Windows,我只會一些Mac的簡單指令,進入公司的第一天就要設定Mac環境,我上網查了很多Mac安裝環境的文章,但是沒有安裝成功,可能那些對小白來說寫的不夠全面。下面我整理了一份安裝PHP環境的筆記供小白參考,如果小白不知道怎麼安裝的,就照我筆記的步驟一步一步操作就好。
一、安裝必要的軟體
1. 安裝MacPorts需要先安裝X11和Xcode,(Lion系統已經預設安裝好了X11),在Appstore安裝Xcode即可。
下載完Xcode之後,一般路徑在/Application下,可以先將其拷出來,以備後續使用:
$ cp -a /Application/Xcode.app ~/soft2.
二、安裝MacPort
1.下載網址:https://distfiles.macports.org/MacPorts/
MacPort手動下載網址: https://www.macports.org/install.php
##可以直接下載Lion下的最新版本:https://distfiles.macports.org/MacPorts/MacPorts-2.4.2-10.12-Sierra.pkg
#如果MacPort出現新版本,可以直接透過以下指令進行更新:$ sudo port -v selfupdate
新增MacPort到環境變數sudo vim /etc/profile
export PATH=/opt/local/bin:$PATH export PATH=/opt/local/sbin:$PATH
2. 錯誤解決方法, 1)設定xcode-select的路徑,2)安裝命令列工具:
$ sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer
三、Apache安裝設定
1.port 安裝apache:
$ sudo port install apache2 cd /opt/local/etc/apache2/ sudo vim httpd.conf LoadModule rewrite_module lib/apache2/modules/mod_rewrite.so
四、PHP安裝設定
1. port 安裝PHP環境,我安裝PHP 5.6.40的版本
$ sudo port install php56-apache2handler
cd /opt/local/lib/apache2/modules sudo /opt/local/bin/apxs -a -e -n php5 mod_php56.so
$ cd /opt/local/lib/apache2/modules $ sudo /opt/local/bin/apxs -a -e -n php5 mod_php56.so
LoadModule php5_module lib/apache2/modules/mod_php56.so #注释打开
$ sudo port install php56-mbstring $ sudo port install php56-ftp $ sudo port install php56-iconv $ sudo port install php56-openssl $ sudo port install php56-mcrypt $ sudo port install php56-soap $ sudo port install php56-sqlite $ sudo port install php56-xsl $ sudo port install php56-zip $ sudo port install php56-xdebug $ sudo port install php56-mongo $ sudo port install php56-mysql $ sudo port install php56-oracle $ sudo port install php56-postgresql (php56-mbstring,php56-ftp,php56-iconv,php56-openssl,php56-mcrypt ,php56-soap ,php56-sqlite, php56-xsl ,php56-zip,php56-xdebug,php56-mongo,php56-mysql,php56-oracle,php56-postgresql)
/opt/local/var/macports/distfiles/oracle-instantclient
https://www.oracle.com/technetwork/topics/intel-macsoft-096467.html
instantclient-basic-macos.x64-11.2.0.4.0.zip instantclient-sdk-macos.x64-11.2.0.4.0.zip
cp instantclient-sdk-macos.x64-11.2.0.4.0.zip /opt/local/var/macports/distfiles/oracle-instantclient
#
$ sudo vim /opt/local/etc/apache2/httpd.conf
AddType application/x-httpd-php .php AddType application/x-httpd-php-source .phps
<FilesMatch .php$> SetHandler application/x-httpd-php </FilesMatch>
sudo vim /opt/local/etc/apache2/httpd.conf Include conf/extra/httpd-vhosts.conf #把这个注释去掉
<Directory /> Options FollowSymLinks AllowOverride none Order deny,allow Allow from all Satisfy all #Require all denied </Directory> AllowOverride All Options None Options FollowSymLinks Require all granted
ServerName www.localhost.com:80這行程式碼改成
ServerName localhost:80
cd /opt/local/etc/php56 sudo cp php.ini-production php.ini
以上是MAC環境安裝php、apache、MacPorts等環境配置的詳細內容。更多資訊請關注PHP中文網其他相關文章!