mac机上搭建php56/nginx 1.8.x/thinkphp 3.2.x/gearman扩展/seaslog扩展/redis扩展环境 - 菩提树下的杨过
php的各种扩展配置起来实在不容易,记录一下备忘:
一、php56 安装
虽然php7出来了,但是没用过,不知道有没有坑,这里仍然使用php5.6版本
1.1 安装php/php-pfm
brew update brew tap homebrew/dupes brew tap josegonzalez/homebrew-php brew install --without-apache --with-fpm --with-mysql php56
注意:记得要带上--with-mysql 否则代码无法连接mysql
1.2 添加环境变量
在~/.bash_profile(如果终端使用zsh的话,在~/.zshrc)里参考下面的内容,进行添加:
export PHP_HOME=/usr/local/opt/php56 export PATH=${PHP_HOME}/bin:${PHP_HOME}/sbin:$PATH
1.3 验证
php --version php-fpm -i lsof -i:9000
1.4 php-fpm的停止及重启
pkill php-fpm php-fpm &
二、thinkphp的下载
2.1 下载3.2.x版本(建议下载full版本)
地址:http://www.thinkphp.cn/donate/download/id/610.html
解压到某个目录:
比如:/Users/jimmy/Work/Code/php/ThinkPHP_3.2.2/
2.2 验证
如何验证后面会讲。
三、nginx安装及php转发配置
3.1 安装
brew install nginx
3.2 php的rewrite处理
在/usr/local/etc/nginx/servers下创建一个名为tp.conf的文件,内容参考以下:
server { listen 8001; server_name localhost; root /Users/jimmy/Work/Code/php/ThinkPHP_3.2.2; location / { index index.html index.shtml index.php; if (!-e $request_filename){ rewrite ^/(.*)$ /index.php/$1 last; break; } } location ~ \.php { root /Users/jimmy/Work/Code/php/ThinkPHP_3.2.2; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fastcgi.conf; set $fastcgi_script_name2 $fastcgi_script_name; if ($fastcgi_script_name ~ "^(.+\.php)(/.+)$") { set $fastcgi_script_name2 $1; set $path_info $2; } fastcgi_param PATH_INFO $path_info; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name2; fastcgi_param SCRIPT_NAME $fastcgi_script_name2; } access_log /Users/jimmy/data/log/nginx/tp_access.log; error_log /Users/jimmy/data/log/nginx/tp_error.log; }
然后
nginx -t 校验配置文件是否正确,如果没问题
nginx -s reload 重启(如果之前没有启动nginx,直接nginx即可)
启动过程中,如果出现警告worker连接数超过1024之类的(类似下面这样)
nginx: [warn] 1024 worker_connections exceed open file resource limit: 256
可运行:
ulimit 4096 调大系统连接数
然后再
nginx -s reload
如果启动成功,浏览 http://localhost:8001/home/index 应该能看到thinkpap的默认欢迎页面
四、gearman的搭建
4.1 安装
brew install gearmand
然后,在~/.zshrc中参考下面的内容修改:(目前是可直接在终端中运行gearmand命令)
export GEARMAN_HOME=/usr/local/Cellar/gearman/1.1.12 export PATH=${GEARMAN_HOME}/bin:${GEARMAN_HOME}/sbin:${PHP_HOME}/bin:${PHP_HOME}/sbin:$PATH
4.2 启动gearman
gearmand -d
五、安装Gearman扩展
5.1 安装
下载地址:http://pecl.php.net/ 上搜索gearman
wget http://pecl.php.net/get/gearman-1.1.2.tgz
(注:mac上默认没有wget命令,可先用brew install wget安装)
tar -zxvf gearman-1.1.2.tgz cd gearman-1.1.2 phpize
然后找一下php-config在本机的位置
where php-config
(注:如果不是zsh终端,可能没有where命令,改用whereis)
通常会在
/usr/local/opt/php56/bin/php-config /usr/local/bin/php-config /usr/bin/php-config
继续:
./configure --with-php-config=/usr/local/opt/php56/bin/php-config sudo make sudo make install
注:如果./configure这个命令找不到,说明本机mac上没有安装autoconf、automake,可先运行
brew install autoconf brew install automake
然后再重新运行 phpize 及 ./configure ... 之类
查看下php.ini的位置
➜ gearman-1.1.2 php --ini Configuration File (php.ini) Path: /usr/local/etc/php/5.6 Loaded Configuration File: /usr/local/etc/php/5.6/php.ini Scan for additional .ini files in: /usr/local/etc/php/5.6/conf.d Additional .ini files parsed: (none)
修改php.ini文件
vi /usr/local/etc/php/5.6/php.ini
找到; extension=msql.so的位置,添加一行内容(参考下面)
; extension=msql.so extension=gearman.so
重启php-fpm
命令行验证:
php-fpm -i |grep gearman ... gearman gearman support => enabled libgearman version => 1.1.12
如果有看到gearman support =>enabled输出,说明gearman扩展安装成功了。
5.2. php使用gearman验证
thinkphp根目录下,新建一个名为client.php的文件(相当于MQ中的消息发送方),内容参考下面:
<?php $client= new GearmanClient(); $client->addServer(); print $client->doNormal("myTask1", "111"); print "\n"; print $client->doNormal("myTask2", "222"); print "\n"; print $client->doBackground("myTask1", "AAA"); print "\n"; print $client->doBackground("myTask2", "BBB"); print "\n"; $client->doBackground("myTask1", "CCC"); $client->doBackground("myTask2", "DDD"); // while (true){ // sleep(10); // } ?>
再创建一个worker.php(相当于MQ中的消息接收方)
<?php $worker= new GearmanWorker(); $worker->addServer(); $worker->addFunction("myTask1", "myTask1_function"); $worker->addFunction("myTask2", "myTask2_function"); while ($worker->work()); function myTask1_function($job) { print($job->workload()); print "\n"; return ($job->workload())." done"; } function myTask2_function($job) { print($job->workload()); print "\n"; } ?>
验证,开二个终端窗口:
php /Users/jimmy/Work/Code/php/ThinkPHP_3.2.2/client.php php /Users/jimmy/Work/Code/php/ThinkPHP_3.2.2/worker.php
如果client及worker窗口,都能内容正常输出,表示gearman及php代码工作正常。
六、seaslog扩展
wget http://pecl.php.net/get/SeasLog-1.5.3.tgz tar -zxvf SeasLog-1.5.3.tgz cd SeasLog-1.5.3 phpize ./configure --with-php-config=/usr/local/opt/php56/bin/php-config sudo make sudo make install
然后修改php.ini,添加以下二行
extension = seaslog.so seaslog.default_basepath =/Users/jimmy/data/log/seaslog
其中seaslog.default_basepath是日志存放的目录,大家根据本机情况自行调整。
七、redis扩展
wget http://pecl.php.net/get/redis-2.2.7.tgz
剩下的跟前面这些扩展的编译、安装方法类似,只是make install成功后,在php.ini里,加一行:
extension=redis.so
最后别忘记了重启php-fpm,然后来一个终极校验大法:thinkphp根目录下,放一个info.php,里面写上:
<?php phpinfo(); ?>
然后浏览http://localhost:8001/info.php,然后用浏览器的页面查找功能,搜索gearman, redis, seaslog, mysql这些关键字,如果能跳到相关的位置,说明安装成功了,参考下图:

Outils d'IA chauds

Undresser.AI Undress
Application basée sur l'IA pour créer des photos de nu réalistes

AI Clothes Remover
Outil d'IA en ligne pour supprimer les vêtements des photos.

Undress AI Tool
Images de déshabillage gratuites

Clothoff.io
Dissolvant de vêtements AI

AI Hentai Generator
Générez AI Hentai gratuitement.

Article chaud

Outils chauds

MinGW - GNU minimaliste pour Windows
Ce projet est en cours de migration vers osdn.net/projects/mingw, vous pouvez continuer à nous suivre là-bas. MinGW : un port Windows natif de GNU Compiler Collection (GCC), des bibliothèques d'importation et des fichiers d'en-tête librement distribuables pour la création d'applications Windows natives ; inclut des extensions du runtime MSVC pour prendre en charge la fonctionnalité C99. Tous les logiciels MinGW peuvent fonctionner sur les plates-formes Windows 64 bits.

DVWA
Damn Vulnerable Web App (DVWA) est une application Web PHP/MySQL très vulnérable. Ses principaux objectifs sont d'aider les professionnels de la sécurité à tester leurs compétences et leurs outils dans un environnement juridique, d'aider les développeurs Web à mieux comprendre le processus de sécurisation des applications Web et d'aider les enseignants/étudiants à enseigner/apprendre dans un environnement de classe. Application Web sécurité. L'objectif de DVWA est de mettre en pratique certaines des vulnérabilités Web les plus courantes via une interface simple et directe, avec différents degrés de difficulté. Veuillez noter que ce logiciel

Version crackée d'EditPlus en chinois
Petite taille, coloration syntaxique, ne prend pas en charge la fonction d'invite de code

SublimeText3 Linux nouvelle version
Dernière version de SublimeText3 Linux

SublimeText3 version chinoise
Version chinoise, très simple à utiliser