I’m fairly new to mac and try to learn some things by playing around.
Currently I’m trying to get an new PHP version on XAMPP running on my macbook. I've read different threads and tutorials for this (e.g. Is there way to use two PHP versions in XAMPP?) but I'm stuck. Here is what I got:
macOS Mojave with XAMPP 5.6.31-0 with PHP version 5.6.31
$ which PHP says /usr/bin/php
$ PHP -v says 7.1.19
So this means macOS has PHP7 out of the box?
So I tried to make XAMPP load PHP7 from the mac path by editing the /xamppfiles/etc/httpd.conf by:
<IfDefine JUSTTOMAKEAPXSHAPPY>
#LoadModule php4_module modules/libphp4.so
#LoadModule php5_module modules/libphp5.so
LoadModule php7_module /usr/libexec/apache2/libphp7.so
</IfDefine>
But after restarting the apache phpinfo() stays hat 5.6.31. Even if I delete the PHP 7 + 5 lines and expect PHP4 to be loaded it stays at 5.
So what am I doing wrong?
Disclaimer: I know it would be the easiest way to download a newer XAMPP version or use the build in apache from mac. But for learning reasons I would like to get this done.
The best way is install Homebrew, and then in your terminal, write this:
$ brew upgrade php // upgrade php formula
$ brew install php#7.2
$ brew link php#7.2 // create an alias to this keg-only version; see comments output during installation
$ echo 'export PATH="/usr/local/opt/php#7.2/bin:$PATH"' >> ~/.bash_profile // add the alias to your path; see comments output during installation
$ source ~/.bash_profile // reload .bash_profile to use the new settings immediately
greetings!
After a lot of research and implementation, the best one that works for me without using the homebrew command this
go to this link https://php-osx.liip.ch/#install
copy the url of the php version you want to install
paste it inside your terminal, it will require for your password, kindly provide it
After installation is complete, add the default path of php to your bash profile by doing this export PATH=/usr/local/php5/bin:$PATH you can simply copy and paste, after check your php version. i believe it will have change.
Go to your localhost PHPmyAdmin, click on "Export" and export all the databases as one.
Go to your XAMPP folder, go to the "Htdocs" folder and copy all your project files to a different folder outside the XAMPP folder.
Go to the XAMPP folder and click the uninstall icon. It will remove xampp. I noticed it leaves your database and htdocs folder intact. Steps 1 and 2 were just a precaution.
Go to and download the latest XAMPP that has the PHP version you want. You can find it at https://www.apachefriends.org/download.html
Click on the downloaded file and install it. It will complete and you will have the PHP version you want install and your Htdocs and database will be intact. In case your database and htdocs is not there, simply recopy the project files you copied and import the database you exported.
Related
My team is upgrading to PHP 7.3. Currently I am on 7.1.23. I'm having a heck of a time getting PHP to use the new version. When I log out PHP info, it's 7.1.23. I've installed the new version with this line and it says it's successful ( tried it a few times).
curl -s https://php-osx.liip.ch/install.sh | bash -s 7.3
When I do which php in the command line, it gives me /usr/bin/php. Is there something I need to do/try? My httpd.conf file seems correct as well with this line
LoadModule php7_module libexec/apache2/libphp7.so
Just been trying to figure this out all day and I can't seem to :). Thanks. Also I am running Mac OS High Sierra
When you do which php you get
/usr/bin/php
Open finder, goto the “go” tab and select the second from the bottom option which says “Go to folder”
This will open a input, type /usr/bin/php inside and you’ll be redirected to that folder. Delete all the php files manually from there.
Now in the terminal, do
$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
This just installs homebrew which will make this very very easy
Then do
$ brew install php73
EDIT: For new versions of PHP the command is
brew install php#8.0
Make sure to check which version you want to use before installing
I am working on a website that is using gettext for translation. The website is translating properly on servers of other machines but not on mine (OS X El Capitan version 10.11.6).
I have follow the following tutorial to install gettext on mac:
link to the tutorial I followed
After the installation, gettext is not still working.
Can someone help me here??
I followed pretty much the same instructions on Sierra (maybe you have messed up at some point?):
Install the latest version of Xcode Command Line Tools. (by entering the following command in the terminal: xcode-select –install)
Download the latest version of gettext and extract it to /Source or whatever you like.
In the /Source director enter in the terminal: ./Configure, make, and sudo make install
Download the PHP version that matches your system and extract it
Change in the PHP source to the directory ext/gettext and enter the following commands: phpize, ./Configure, make, and sudo make install (each on a separate line).
At this point you might get an SIP error, because the install has no access to /usr/libexec/php/extensions. However, the extension was created in the PHP source folder ext/gettext/modules
Create a local extension folder: mkdir -p /usr/local/macoperator/lib/php/extensions and copy the newly created gettext.so extension to this folder
Reference the local extension folder in your /etc/php.ini. Just add the following line at the end:
extension_dir = "/usr/local/macoperator/lib/php/extensions"
[gettext]
extension=gettext.so
Finally, make sure apache is restarted, by issuing: server-apachectl graceful
Checking phpinfo(), do you see:
GetText Support enabled
Alternatively, you could try install PHP via Homebrew.
I created a new project with Laravel, then I put it in the corresponding path for apache could execute, then I write the URL in a browser to open the project and I get the following message
Mcrypt PHP extension required.
I installed mcrypt with this command
brew install homebrew/php/php55-mcrypt
and work fine when I create a new project in laravel
I was searching and I found this tutorial but still withouth work
Open /etc/php.ini and add the line below at the end extension=mcrypt.so.
If there is no php.ini file, then you need to make one from php.ini.default in the same location like so: sudo cp /etc/php.ini.default /etc/php.ini
allow write capability sudo chmod u+w /etc/php.ini
Then add the line as above in your favourite text editor: sudo nano /etc/php.ini
add in the line: extension=mcrypt.so
Restart Apache sudo apachectl restart
but still without work, what can I do?
While it's always good to do PHP stuff on a local server, you will almost always run into the issue of getting everything set up correctly if you don't know what you're doing. My advice, use a service already provided for you.
Using Homestead (Laravel's Dev Environment) will help in getting projects setup very quickly. It'll also have all the PHP modules (e.g. mcrypt) already configured.
I'd take a look at Homestead: Laravel Homestead
Try visiting: Install mcrypt for php on Mac OSX 10.10 Yosemite
OR
Just see your phpinfo(); it will give you the status for mcrypt.
OR
Try updating your php version. Visit: Update PHP
See, if that helps you.
Is there a way to downgrade php 5.5 to 5.3 in xampp? I searched on google but every one just tell me to uninstall xampp and install an older version. Could I have php 5.5 downgrade to 5.3 without reinstall xampp?
Short answer is no.
XAMPP is normally built around a specific PHP version to ensure plugins and modules are all compatible and working correctly.
If your project specifically needs PHP 5.3 - the cleanest method is simply reinstalling an older version of XAMPP with PHP 5.3 packaged into it.
XAMPP 1.7.7 was their last update before moving off PHP 5.3.
Long answer: it is possible!
Temporarily rename existing xampp folder
Install xampp 1.7.7 into xampp folder
name
Folder containing just installed 1.7.7 distribution rename to different name and previously existing xampp folder rename back just to xampp.
In xampp folder rename php and apache folders to different names (I propose php_prev and apache_prev) so you can after switch back to them by renaming them back.
Copy apache and php folders from folder with xampp
1.7.7 into xampp directory
In xampp directory comment line apache/conf/httpd.conf:458
#Include "conf/extra/httpd-perl.conf"
In xampp directory do next replaces in files:
php/pci.bat:15
from
"C:\xampp\php\.\php.exe" -f "\xampp\php\pci" -- %*
to
set XAMPPPHPDIR=C:\xampp\php
"%XAMPPPHPDIR%\php.exe" -f "%XAMPPPHPDIR%\pci" -- %*
php/pciconf.bat:15
from
"C:\xampp\php\.\php.exe" -f "\xampp\php\pciconf" -- %*
to
set XAMPPPHPDIR=C:\xampp\php
"%XAMPPPHPDIR%\.\php.exe" -f "%XAMPPPHPDIR%\pciconf" -- %*
php/pear.bat:33
from
IF "%PHP_PEAR_PHP_BIN%"=="" SET "PHP_PEAR_PHP_BIN=C:\xampp\php\.\php.exe"
to
IF "%PHP_PEAR_PHP_BIN%"=="" SET "PHP_PEAR_PHP_BIN=C:\xampp\php\php.exe"
php/peardev.bat:33
from
IF "%PHP_PEAR_PHP_BIN%"=="" SET "PHP_PEAR_PHP_BIN=C:\xampp\php\.\php.exe"
to
IF "%PHP_PEAR_PHP_BIN%"=="" SET "PHP_PEAR_PHP_BIN=C:\xampp\php\php.exe"
php/pecl.bat:32
from
IF "%PHP_PEAR_BIN_DIR%"=="" SET "PHP_PEAR_BIN_DIR=C:\xampp\php"
IF "%PHP_PEAR_PHP_BIN%"=="" SET "PHP_PEAR_PHP_BIN=C:\xampp\php\.\php.exe"
to
IF "%PHP_PEAR_BIN_DIR%"=="" SET "PHP_PEAR_BIN_DIR=C:\xampp\php\"
IF "%PHP_PEAR_PHP_BIN%"=="" SET "PHP_PEAR_PHP_BIN=C:\xampp\php\php.exe"
php/phar.phar.bat:1
from
%~dp0php.exe %~dp0pharcommand.phar %*
to
"%~dp0php.exe" "%~dp0pharcommand.phar" %*
Enjoy new XAMPP with PHP 5.3
Checked by myself in XAMPP 5.6.31, 7.0.15 & 7.1.1 with XAMPP Control Panel v3.2.2
It is possible! Yes
In many cases, you might want to use XAMPP with a different PHP version than the one that comes preinstalled.
You might do this to get the benefits of a newer version of PHP, or to reproduce bugs using an earlier
version of PHP.
To use a different version of PHP with XAMPP, follow these steps:
Download a binary build of the PHP version that you wish to use from the PHP website, and extract the contents of the compressed
archive file to your XAMPP installation directory (usually, C:\xampp).
Ensure that you give it a different directory name to avoid
overwriting the existing PHP version. For example, in this tutorial,
we’ll call the new directory C:\xampp\php5-6-0. NOTE : Ensure that the
PHP build you download matches the Apache build (VC9 or VC11) in your
XAMPP platform.
Within the new directory, rename the php.ini-development file to php.ini. If you prefer to use production settings, you could instead
rename the php.ini-production file to php.ini.
Edit the httpd-xampp.conf file in the apache\conf\extra\ subdirectory of your XAMPP installation directory. Within this file,
search for all instances of the old PHP directory path and replace
them with the path to the new PHP directory created in Step 1. In
particular, be sure to change the lines
LoadFile "/xampp/php/php5ts.dll"
LoadFile "/xampp/php/libpq.dll"
LoadModule php5_module "/xampp/php/php5apache2_4.dll"
to
LoadFile "/xampp/php5-6-0/php5ts.dll"
LoadFile "/xampp/php5-6-0/libpq.dll"
LoadModule php5_module "/xampp/php5-6-0/php5apache2_4.dll"
NOTE : Remember to adjust the file and directory paths above to reflect
valid paths on your system.
Restart your Apache server through the XAMPP control panel for your changes to take effect. The new version of PHP should now be active.
To verify this, browse to the URL
http://localhost/xampp/phpinfo.php, which displays the output of the
phpinfo() command, and check the version number at the top of the
page.
I did this in my local environment. Wasn't difficult but obviously it was done in "unsupported" way.
To do the downgrade you need just to download php 5.3 from http://php.net/releases/ (zip archive), than go to xampp folder and copy subfolder "php" to e.g. php5.5 (just for backup). Than remove content of the folder php and unzip content of zip archive downloaded from php.net. The next step is to adjust configuration (php.ini) - you can refer to your backed-up version from php 5.5. After that just run xampp control utility - everything should work (at least worked in my local environment). I didn't found any problem with such installation, although I didn't tested this too intensively.
I just used a very simpler way for this and I just put it here if it could help anyone else.
I just had so much data on my database and I didn't want to transfer my whole Database so I just installed an older version of XAMPP with the PHP version that I required in a new directory (example:XAMPP-OLD) then I opened two control panel of 2 different version of XAMPP and start the MYSQL from the Newer version and Start Apache from the older version to use the other version of PHP.
just keep in mind to transfer files to the other XAMPP folder
I am using MAMP and would like to use mongo with PHP. I am stuck because the version of MAMP I'm using is the latest version I can find, and it's running PHP 5.2.11. The only Mongo PHP install I can find for OSX is for PHP 5.3.
Is there any way to get mongo working with PHP using MAMP?
For MAMP 2.1.2 and PHP 5.4.10
Download MongoDB php driver .
copy mongo.so to
/Applications/MAMP/bin/php/php5.4.10/lib/php/extensions/no-debug-non-zts-20100525/
and using temrinal
cd /Applications/MAMP/bin/php/php5.4.10/lib/php/extensions/no-debug-non-zts-20100525/ && wget https://github.com/downloads/stennie/mongo-php-driver/mongo.so
open
/Applications/MAMP/bin/php/php5.4.10/conf/php.ini
Find ; Extensions
add
extension=mongo.so
Restart MAMP.
Above steps will install MongoDB driver 1.2.10.
To install latest Mongodb driver using PECL
install autoconf using homebrew or Mac Ports
brew install autoconf
Download php 5.4.10 source from php.net.
rename uncompressed php source folder from php-5.4.10 to php and paste it in this folder
/Applications/MAMP/bin/php/php5.4.10/include/
using the terminal open php folder and run ./configure
cd /Applications/MAMP/bin/php/php5.4.10/include/php/ && ./configure
Add MAMP bin to your ~/.bash_profile
echo "export PATH=/Applications/MAMP/bin/php/php5.4.10/bin:$PATH" >> ~/.bash_profile
source ~/.bash_profile
install latest mongo
pecl install mongo
restart MAMP server :).
Here's a tutorial how to do it: http://www.davidgolding.net/mongodb/installing-mongodb-on-mamp-1-9-5.html
Post was removed so here's the tutorial:
Appsolute launched MAMP version 1.9.5 today, so I thought it’d be a great time to add MongoDB to it and improve my NoSQL skills.
Prepare MAMP for MongoDB files
Create a new folder at Applications/MAMP/db/mongo with three additional subfolders named bin, data, and tmp. Provide these folders with chmod 0755 access permissions. These folders will be the main runtime location for Mongo once MAMP gets it running.
Download MongoDB
Grab the latest Mac OS install package of MongoDB. My server setup called for OS X 64-bit, version 1.6.5. It’ll have a directory named bin. Drop the files from this folder into the /Applications/MAMP/db/mongo/bin folder you already created.
Download Mongo Driver for PHP
I’m running PHP 5.3 (why use MongoDB with any earlier version of PHP?), so I’ll need the mongo.so extension to get PHP and Mongo working together. This is available at the MongoDB GitHub repository, under the PHP 5.3 for Mac binary. After unpacking the downloaded file, place the mongo.so extension file in the /Applications/MAMP/bin/php5.3/lib/php/extensions folder.
Update: An alternative is to place the mongo.so file in the /Applications/MAMP/bin/php5.3/lib/php/extensions/no-debug-non-zts-20090626 folder and avoid having to edit the php.ini file. It appears that MAMP 1.9.5 already has the extension=mongo.so line in the extensions block of the php.ini file, even though version 1.9.5 doesn’t come bundled with Mongo.
4. Create Startup Routines for MAMP
Lastly, you’ll need to create the startup routines so that MAMP will launch Mongo along with MySQL and Apache. Create a new file at /Applications/MAMP/bin/startMongo.sh and place in it the following code:
# /bin/sh
/Applications/MAMP/db/mongo/bin/mongod --dbpath /Applications/MAMP/db/mongo/data --logpath /Applications/MAMP/db/mongo/mongodb.log --pidfilepath /Applications/MAMP/db/mongo/tmp/mongo.pid --fork --logappend
When called, this script will launch Mongo using the MAMP-relative paths rather than Mongo’s system defaults.
Create another file at /Applications/MAMP/bin/stopMongo.sh and place the shutdown method:
# /bin/sh
/bin/kill `cat /Applications/MAMP/db/mongo/tmp/mongo.pid`
This works like the previous script, except it kills the mongo.pid process, effectively shutting down Mongo.
To have MAMP automatically call these Mongo startup scripts, open the /Applications/MAMP/bin/start.sh and /Applications/MAMP/bin/stop.sh files, and insert the following lines above the startMysql.sh lines, respectively:
1
/Applications/MAMP/bin/startMongo.sh
1
/Applications/MAMP/bin/stopMongo.sh
Now MAMP will automatically launch Mongo upon startup.
The only thing left to do is tell PHP to run the mongo.so extension. If you’re running MAMP Pro, edit the php.ini file by selecting File > Edit Template > PHP 5.3 php.ini, otherwise you’ll need to lookup the path the php.ini file from the MAMP startup screen, under “phpInfo” and “Loaded Configuration File.”
Insert the following line in the php.ini file/template, save the file, then restart MAMP.
1
extension="/Applications/MAMP/bin/php5.3/lib/php/extensions/mongo.so"
Mongo should now run in the background on MAMP, which you can connect with from PHP using the main connection routines listed on the PHP site. Welcome to NoSQL on MAMP!
MAMP is now at version 2.2, which comes with PHP v 5.5.3. I managed to get Mongodb working had to jump through a few hoops to get there.
Start with a clean install of MAMP 2.2, make sure that's working.
1. I made this the system version of PHP, (not sure if necessary at this stage).
Find out the default version of php you are using, with the terminal command
$ which php
/usr/bin/php
Then back this up
$ sudo mv /usr/bin/php /usr/bin/php.bak
Then create a symlink to the MAMP latest version of php
$ sudo ln -s /Applications/MAMP/bin/php/php5.5.3/bin/php /usr/bin/php
Check this has been updated
$ which php
/Applications/MAMP/bin/php/php5.5.3/bin/php
2. Installing Mongo
$ cd /Applications/MAMP/db
$ curl http://downloads.mongodb.org/osx/mongodb-osx-x86_64-2.4.6.tgz > mongodb.tgz
$ tar -zxvf mongodb.tgz
$ rm mongodb.tgz
$ mv mongodb* mongo
$ mkdir mongo/data/db
Test to make sure mongo is working
$ ./mongo/bin/mongod --dbpath /Applications/MAMP/db/mongo/data/db
Should output some code, ending in 'waiting for connections on port 27017' press Ctrl + C to quit for now.
3. Now we can create a script to start/stop mongod automatically from the MAMP GUI. This inspiration came from a previous answer, by Alexandru Rada, but didn't quite work how he explained - I think this is to do with being a newer MAMP version.
In /Applications/MAMP/bin create a file called startMongo.sh and insert the following
# /bin/sh
/Applications/MAMP/db/mongo/bin/mongod --dbpath /Applications/MAMP/db/mongo/data/db --logpath /Applications/MAMP/logs/mongodb.log --pidfilepath /Applications/MAMP/tmp/mongo/mongo.pid --fork --logappend
I also created the mongo tmp folder at /Applications/MAMP/tmp/mongo
In the same bin directory create a file called stopMongo.sh and insert the following:
# /bin/sh
/bin/kill `cat /Applications/MAMP/tmp/mongo/mongo.pid`
Make these files executable
$ chmod 775 /Applications/MAMP/bin/startMongo.sh /Applications/MAMP/bin/stopMongo.sh
Now update the startApache.sh and stopApache.sh scripts to include our new files respectively.
Use the Activity Monitor in /Applications/Utilities and search for mongod. When you now start MAMP you should see the process mongod is started. When you stop or quit MAMP you should see this process is automatically killed.
4. We still need to install the mongo-php driver, which is also a pain. To do this I added the MAMP bin directory to my bash $PATH variable. To do this I had to edit the hidden file ~/.profile - but be aware that your $PATH might be loaded from somewhere else.
export PATH=$PATH:/Applications/MAMP/bin/php/php5.5.3/bin:/Applications/MAMP/db/mongo/bin
Note that each element is separated by a :. Quit terminal and re-open, then $ echo $PATH to check your new directories have been added to the path. You could also try $ which pecl or $ which mongod.
We still need some extras from PHP php.net download the same php stable version and unzip it. Create the folder 'include' at /Applications/MAMP/bin/php/php5.5.3/include . Drag the unzipped stable version of php to the include folder, and rename it to just 'php'.
$ cd /Applications/MAMP/bin/php/php5.5.3/include/php
$ ./configure
Now at last, we can hopefully run
$ sudo pecl install mongo
5. Now we just need to update our php config file to add the mongo.so extension.
Open /Applications/MAMP/bin/php/php5.5.3/conf/php.ini in a text editor, under the 'extensions' section, add in
extension=mongo.so
Quit and re-open MAMP!
Mac OS X 10.6 Snow Leopard (with the newest updates) has PHP 5.3 installed along with Apache.
You can enable the installed Apache in System Preferences, Sharing, Web Sharing (there is a help icon (?) which shows you details on using the system's web server).
See also this StackOverflow question:
Easiest way to activate PHP and MySQL on Mac OS 10.6 (Snow Leopard)?
Here's the way I did it and it was fairly simple.
First, read what Mongo says # http://www.mongodb.org/display/DOCS/PHP+Language+Center
When you run sudo pecl install mongo it's going to install it for the standard OSX PHP installation to use, so if for some reason you're using the built-in Apache installation.
Like you, I like using MAMP. I didn't want to go through figuring how to download Mongo into MAMP, so I just creating a symbolic link in the MAMP PHP Extensions folder and put the extension line in the MAMP php.ini. Restarted MAMP Apache and everything worked beautifully!
A couple things to note, after installing Mongo, note the extensions folder it installed it into then check MAMP php.ini to see where it has its extensions set to be. You'll notice the ending is very similar.
For MAMP PRO 2.0.5
You may compile your own mongo.so (http://m-schmidt.eu/2011/11/06/develop-mongodb-web-apps-with-mamp-under-mac-os-x/) or download compiled (http://www.davidgolding.net/mongodb/installing-mongodb-on-mamp-1-9-5.html).
I'd like compile.
After steps mongo.so don't include to php configuration, because in MAMP PRO php.ini placed in
/Applications/MAMP PRO/MAMP PRO.app/Contents/Resources
I using php5.3.6.ini file for my configuration.