Install PHP extension for XAMPP redis in MAC lion

Source: Internet
Author: User
Tags install redis

Apache comes with a few extensions under MAC lion. In addition, I tried to use PHP source code compilation but failed because I decided to use an integrated mamp, Which is XAMPP (the XAMPP development package must be installed, otherwise, PHP extensions may fail to be compiled ). There is a lot of information about installing some programs or extensions of PHP in Windows and Linux, but there is very little information about the latest Mac version 10.7.4. By the way, Mac's easy-to-use Installation tool, macport and homebrew. macport, may be blocked during installation.

Next, let's go to the topic. For example, install redis and PHP-redis first today. About redis for Mac information in https://github.com/antirez/redis, By the way let redis boot automatic operation settings: http://naleid.com/blog/2011/03/05/running-redis-as-a-user-daemon-on-osx-with-launchd/ said very clearly. I still reference it as a reference. Note that I am bold and red.

 

If you're developing on the Mac using redis and want it to start automatically on boot, you'll want to leverage the OSXlaunchdSystem to run it as a user daemon. A user daemon is a non-Gui program that runs in the background as part of the system. it isn' t associated with your user account. if you only want redis to launch when a participant user logs in, you'll want to make a user agent instead.

From the command line, create a plist file as root in/Library/LaunchDaemonsDirectory with your favorite Text Editor:

sudo vim /Library/LaunchDaemons/io.redis.redis-server.plist

Paste in the following contents and modify it to point it to wherever you 've gotredis-serverInstalled and optionally pass the location of a config file to it (Delete the redis. conf line if you're not using one):

<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"><plist version="1.0"><dict><key>Label</key><string>io.redis.redis-server</string><key>ProgramArguments</key><array><string>/usr/local/bin/redis-server</string><string>/usr/local/etc/redis.conf</string></array><key>RunAtLoad</key><true/></dict></plist>

Make sure that you actually haveredis.confFile at the location above. If you 've installed it withhomebrew that shocould be the correct location.

You'll then need to load the file(One time) Into launchdlaunchctl:

sudo launchctl load /Library/LaunchDaemons/io.redis.redis-server.plist

Redis will now automatically be started after every boot. You can manually start it without rebooting:

sudo launchctl start io.redis.redis-server

You can also shut down the server

sudo launchctl stop io.redis.redis-server

Or you cocould add these aliases to Your bash/zsh RC file:

alias redisstart='sudo launchctl start io.redis.redis-server'alias redisstop='sudo launchctl stop io.redis.redis-server'

If you're having some sort of error (or just want to watch the logs), you can just fire upConsole.appTo watch the redis logs to see what's going on.

After talking about this, you have not started to install PHP-redis. The following starts:

First, use git to download the source code from https://github.com/nicolasff/phpredis. Run the following commands in sequence:

sudo /Applications/XAMPP/xamppfiles/bin/phpize
sudo MACOSX_DEPLOYMENT_TARGET=10.7 CFLAGS="-arch i386 -arch x86_64 -g -Os -pipe -no-cpp-precomp" CCFLAGS="-arch i386 -arch x86_64 -g -Os -pipe" CXXFLAGS="-arch i386 -arch x86_64 -g -Os -pipe" LDFLAGS="-arch i386 -arch x86_64 -bind_at_load" ./configure --enable-redis --with-php-config=/Applications/XAMPP/xamppfiles/bin/php-config
sudo make && sudo make install

Modify PHP. ini (add: Extension = redis. So) and restart the XAMPP service.

 

Sample Code

 

<? PHP

Echo 'phpredis sample: <br/> ';

 

Error_reporting (e_all );

Ini_set ('display _ errors ', 'on ');

 

$ Redis = new redis ();

$ Redis-> connect ('2017. 0.0.1 ', 127 );

$ Redis-> set ('first _ key_phpredis ', 'Hello World ');

 

);

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.