I have installed XAMPP on Mac OSX running Yosemite I have created the .bash_profile file like this:
export XAMPP_HOME=/Applications/XAMPP/xamppfiles
export PATH=${XAMPP_HOME}/bin/php:${PATH}
export PATH
When I type echo $PATH in terminal, I get correct XAMPP path But when I type "which php" it shows /usr/bin/php
How can I make my XAMPP use the correct php instead of default php that came with mac?
asked Nov 19, 2014 at 8:15
1
To use the XAMPP PHP and other binaries found in /Applications/XAMPP/bin/ by default this is the correct entry for ~/.bash_profile
export XAMPP_HOME=/Applications/XAMPP
export PATH=${XAMPP_HOME}/bin:${PATH}
export PATH
Load the changes with this [won't be needed next time you open a shell session]:
source ~/.bash_profile
Confirm:
$ which php
/Applications/XAMPP/bin/php
answered Oct 2, 2015 at 18:04
BlueCBlueC
1,2679 silver badges12 bronze badges
9
In My case I did the following
I created my bash profile.
sudo nano ~/.bash_profile
And then added the following to it
export PATH=/Applications/XAMPP/xamppfiles/bin:$PATH
export PATH
And then refreshed my path source ~/.bash_profile
Or if that doesn't work you can close the terminal completely and start a new session.
Enter which php
And you would see your new php path, in my case /Applications/XAMPP/xamppfiles/bin
If you know what php version you installed, you can also check by entering php -v
in my case it output the following.
PHP 5.6.14 [cli] [built: Nov 19 2015 20:37:15]
Copyright [c] 1997-2015 The PHP Group
Zend Engine v2.6.0, Copyright [c] 1998-2015 Zend Technologies.
Amir
8,6717 gold badges44 silver badges47 bronze badges
answered Jan 28, 2016 at 13:12
Daniel BardeDaniel Barde
2,4134 gold badges29 silver badges39 bronze badges
1
Finally I Solve the Problem. I set the Following Config in my "~/.bash_profile"
If u have a bash_profile U need to Edit otherWise create bash_profile. Then Add these lines 1st
export PATH=/Applications/XAMPP/xamppfiles/bin:$PATH
export PATH
Above is the Xampp path. Next Add The Composer Path[IF U ADD THE COMPOSER PATH 1st IT WON'T WORK]
export PATH="~/.composer/vendor/bin:$PATH"
Finally Working Fine for Me.
which php
/Applications/XAMPP/xamppfiles/bin/php
answered Sep 18, 2019 at 7:23
2
I managed to solve the problem. On the Mac, the XAMPP bin folder and the php file had the wrong permission, hence it was not working. Secondly, I also had to profile the full path
/bin/php-5.5.15:${PATH}
Thanks
answered Nov 19, 2014 at 18:55
ssdesignssdesign
2,6436 gold badges32 silver badges50 bronze badges
1
Not the answer you're looking for? Browse other questions tagged php macos xampp or ask your own question.
Open Terminal
Type sudo nano ~/.bash_profile and press Enter
Paste the following:
export PATH=/Applications/XAMPP/xamppfiles/bin:$PATH
export PATH
Exit nano
Type source ~/.bash_profile
Close and reopen Terminal
Thực sự thì việc phát triển web trên môi trường Mac OS X khá là tuyệt vời. Việc setup môi trường để phát triển PHP có khá nhiều lựa chọn, trong đó có thể kể đến 1 phần mềm khá là thông dụng - MAMP Pro. MAMP Pro cung cấp một giao diện thân thiện cho việc quản lý Apache, PHP và MySQL. Tuy nhiên, việc tuỳ biến sẽ trở lên khó khăn hơn do MAMP Pro sử dụng những configuration template riêng. Và đôi khi, MAMP Pro còn bị chậm mà không rõ nguyên nhân !!!
Đó là lý do mà chúng ta sẽ thực hiện theo cách khác, cài đặt và thiết lập mọi thứ qua terminal. Thực sự thì việc sử dụng mọi thứ qua terminal khá là thú vị. Nó có thể hơi khó 1 chút đối với người mới [do type nhiều] nhưng khi đã làm quen rồi thì rất thích thú [vẫn là do được type nhiều]
Apache
OSX 10.10 Yosemite được cài đặt sẵn Apache 2.4. Để khởi động web server, các bạn chỉ việc mở Terminal [/Applications/Utilities/Terminal] và gõ:
sudo apachectl start
Quá dễ đoán đối với việc stop và restart đúng không?
sudo apachectl stop
sudo apachectl restart
OK rồi, hãy start apache ngay đi và mở trình duyệt lên và gõ thử localhost xem có hiện ra It works! hay không nào.
Chú ý
: Nếu bạn không thể truy cập được //localhost thì bạn sẽ cần thêm alias vào file /etc/hosts
: 127.0.0.1 localhost
. Mặc định thì nó đã có sẵn.
Document Root
Điều đầu tiên chúng ta muốn làm sẽ là thay đổi Document Root cho Apache. Đây là folder mà Apache sẽ tìm kiếm file để phục vụ. Mặc định thì Document Root được thiết lập ở /Library/WebServer/Documents
. Thiết lập này thường được dùng cho các máy có nhu cầu làm máy chủ [web server]. Chúng ta sẽ thay đổi nó về thư mục home - thư mục user của bạn. Để thực hiện điều này, chúng ta cần thay đổi file /etc/apache2/httpd.conf
. Do đây là file được sở hữu bởi root
nên bạn sẽ cần thêm
sudo
để có thể thay đổi được file. Ở đây mình dùng vim, bạn có thể dùng các editor khác như sublime text hay nano nếu thích.
sudo vi /etc/apache2/httpd.conf
Tìm từ DocumentRoot
, bạn sẽ thấy dòng sau:
DocumentRoot "/Library/WebServer/Documents"
Thay đổi đường dẫn thành folder dưới user của bạn. Ở đây tôi dùng thư mục Sites
DocumentRoot "/Users/your_user/Sites"
Bạn cũng cần thay đổi đường dẫn ở trong thẻ
Ở ngay trong block
của bạn sẽ thấy
AllowOverride
, hãy thay đổi nó thành như sau:
AllowOverride All
User & Group
Bây giờ Apache đã được thiết lập để trỏ tới thư mục Sites
trong thư mục home của bạn. Tuy nhiên chúng ta vẫn có một vấn đề, đó là mặc định apache sẽ chạy dưới user _www
và group _www
. Điều này sẽ dẫn tới các vấn đề liên quan tới permisssion khi truy cập các file trong thư mục
home. Chúng ta sẽ cần thay đổi chúng thành user mà bạn đang dùng và group staff
. Vẫn ở trong file httpd.conf
, bạn tìm 2 thiết lập User
và Group
và thay đổi chúng:
User your_user
Group staff
Đến đây chúng ta có thể save lại file httpd.conf
. Nếu bạn vẫn dùng vim thì type :wq
và enter
Tạo thư mục Sites
Sau khi chỉnh sửa file httpd.conf
thì tất nhiên bạn sẽ cần restart lại apache để cập nhật các thiết lập mới:
sudo apachectl restart
Bây giờ bạn cần tạo thư mục Sites
ở trong thư
mục home [your_user] của bạn. Ở trong thư mục Sites
, chúng ta sẽ tạo thêm 1 file index.html
với nội dung đơn giản:
. Bạn có thể làm việc này bằng Terminal hay Finder tuỳ bạn, ở đây tôi dùng terminal luôn:Day la thu muc goc cua web server
mkdir ~/Sites
echo "Day la thu muc goc cua web server
" > ~/Sites/index.html
Bây giờ hãy mở //localhost
bằng trình duyệt để kiểm tra xem nội dung chúng ta vừa viết có hiện ra không nhé. Nếu và nó nên hiện ra nội dung như thế, chúng ta có thể đến bước tiếp theo
Homebrew
Việc cài đặt và cả quá trình sử dụng của chúng ta sẽ phụ thuộc rất nhiều vào một package manager trên OS X được gọi là Homebrew. Để cài đặt được Homebrew thì Xcode 6.1 [hoặc hơn] và Command Line Tools là yêu cầu bắt buộc. Hãy chắc chắn rằng bạn cài đặt Xcode trước. Sau khi cài đặt thành công, mở Xcode, đồng ý với Terms and Conditions, sau đó cài đặt Command Line Tools bằng câu lệnh sau:
xcode-select --install
Installation
Cài đặt Homebrew bằng câu lệnh sau:
ruby -e "$[curl -fsSL //raw.githubusercontent.com/Homebrew/install/master/install]"
Hãy nhập password khi được yêu cầu. Quá trình này có thể sẽ mất vài phút. Sau khi hoàn thành, bạn có thẻ kiểm tra việc cài đặt brew có thực sự hoàn tất hay không bằng câu lệnh:
brew --version
Verificaton
Để chắc chắn rằng mọi thứ ổn và được update mới nhất, hãy chạy 2 lệnh sau:
brew doctor
brew update
Install PHP 5.4, 5.5, 5.6
Việc cài đặt các phiên bản PHP khi đã có brew khá là đơn giản. Hãy chạy các câu lệnh sau để cài đặt PHP 5.4, 5.5 và 5.6
brew tap homebrew/dupes
brew tap homebrew/versions
brew tap homebrew/homebrew-php
brew install php54
brew install php55
brew install php56
Quá trình này sẽ mất thời gian một chút. Sau khi hoàn thành, nếu bạn muốn thay đổi một số thiét lập cho mỗi bản php thì có thể tìm file php.ini
của mỗi version trong các đường dẫn sau:
/usr/local/etc/php/5.4/php.ini
/usr/local/etc/php/5.5/php.ini
/usr/local/etc/php/5.6/php.ini
Thiết lập Apache
Bạn đã cài đặt nhièu phiên bản php, nhưng chúng ta cần phải thiết lập Apache để sử dụng chúng. Để làm được điều này, chúng ta sẽ lại phải thay đổi file /etc/apache2/httpd.conf
. Hãy tìm #LoadModule php5_module
và thêm vào bên dưới:
# Brew PHP LoadModule
LoadModule php5_module /usr/local/opt/php54/libexec/apache2/libphp5.so
Ở đây
chúng ta thiết lập để apache sử dụng php 5.4. Chúng ta sẽ thêm việc chuyển đổi phiên bản php sau. Bạn cũng nên bỏ comment module mod_rewrite.so
LoadModule rewrite_module libexec/apache2/mod_rewrite.so
Lưu lại thay đổi và restart Apache:
sudo apachectl restart
Validating PHP Installation
Cách tốt nhất để kiểm tra php version cũng như các module mà apache đang sử dụng là tạo 1 file info.php
ở thư mục Sites
sử dụng hàm phpinfo[]
:
echo "