1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > Mac安装Nginx Mysql PHP Redis

Mac安装Nginx Mysql PHP Redis

时间:2024-04-29 09:43:54

相关推荐

Mac安装Nginx Mysql PHP Redis

安装xcode命令行工具的命令

xcode-select --install

安装homebrew:

ruby -e "$(curl -fsSL /Homebrew/install/master/install)"

旧版本homebrew升级:

brew update

Nginx安装

brew install nginx

➜ ~ brew install nginxUpdating Homebrew...==> Installing dependencies for nginx: pcre, openssl@1.1==> Installing nginx dependency: pcre==> Downloading /bottles/pcre-8.39.sierra.bottle.tar.gz######################################################################## 100.0%==> Pouring pcre-8.39.sierra.bottle.tar.gz? /usr/local/Cellar/pcre/8.39: 203 files, 5.4M==> Installing nginx dependency: openssl@1.1==> Downloading /bottles/openssl@1.1-1.1.0c.sierra.bottle.tar.gz######################################################################## 100.0%==> Pouring openssl@1.1-1.1.0c.sierra.bottle.tar.gz==> Using the sandbox==> CaveatsA CA file has been bootstrapped using certificates from the systemkeychain. To add additional certificates, place .pem files in/usr/local/etc/openssl@1.1/certsand run/usr/local/opt/openssl@1.1/bin/c_rehashThis formula is keg-only, which means it was not symlinked into /usr/local.Apple has deprecated use of OpenSSL in favor of its own TLS and crypto librariesGenerally there are no consequences of this for you. If you build yourown software and it requires this formula, you'll need to add to yourbuild variables:LDFLAGS: -L/usr/local/opt/openssl@1.1/libCPPFLAGS: -I/usr/local/opt/openssl@1.1/include==> Summary? /usr/local/Cellar/openssl@1.1/1.1.0c: 6,225 files, 15.3M==> Installing nginx==> Downloading /bottles/nginx-1.10.2_1.sierra.bottle.1.tar.gz######################################################################## 100.0%==> Pouring nginx-1.10.2_1.sierra.bottle.1.tar.gz==> CaveatsDocroot is: /usr/local/var/wwwThe default port has been set in /usr/local/etc/nginx/nginx.conf to 8080 so thatnginx can run without sudo.nginx will load all files in /usr/local/etc/nginx/servers/.To have launchd start nginx now and restart at login:brew services start nginxOr, if you don't want/need a background service you can just run: nginx==> Summary? /usr/local/Cellar/nginx/1.10.2_1: 8 files, 979.8K

配置非管理员开机nginx自动启动的权限和分组:

sudo chown root:wheel /usr/local/Cellar/nginx/1.10.2_1/sbin/nginxsudo chmod u+s /usr/local/Cellar/nginx/1.10.2_1/sbin/nginx

nginx相关命令:

# 查看nginx版本

➜ ~ nginx -vnginx version: nginx/1.10.2

# 启动 nginx服务

sudo nginx

#测试配置是否有语法错误

➜ ~ nginx -tnginx: the configuration file /usr/local/etc/nginx/nginx.conf syntax is ok nginx: configuration file /usr/local/etc/nginx/nginx.conf test is successful

# 重新加载配置|重启|停止|退出

nginx nginx -s reload|reopen|stop|quit

浏览器中查看效果

nginx启动后,在浏览器中输入http://localhost:8080/,回车即可看到运行结果显示的是/usr/local/Cellar/nginx/1.10.2_1/html/index.html文件的内容。

开机自启动nginx服务设置:

mkdir -p ~/Library/LaunchAgents➜ ~ cp /usr/local/Cellar/nginx/1.10.2_1/homebrew.mxcl.nginx.plist ~/Library/LaunchAgents/➜ ~ cp /usr/local/Cellar/nginx/1.10.2_1/homebrew.mxcl.nginx.plist /Users/cony/Library/LaunchAgents/➜ ~ launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist➜ ~ launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist #取消开机启动

Mysql安装

brew install mysql

➜ ~ brew install mysqlUpdating Homebrew...==> Auto-updated Homebrew!Updated 1 tap (homebrew/core).==> Updated Formulaemacvim pgbadgerproxychains-ng==> Installing dependencies for mysql: openssl==> Installing mysql dependency: openssl==> Downloading /bottles/openssl-1.0.2j.sierra.bottle.tar.gz######################################################################## 100.0%==> Pouring openssl-1.0.2j.sierra.bottle.tar.gz==> Using the sandbox==> CaveatsA CA file has been bootstrapped using certificates from the SystemRootskeychain. To add additional certificates (e.g. the certificates added inthe System keychain), place .pem files in/usr/local/etc/openssl/certsand run/usr/local/opt/openssl/bin/c_rehashThis formula is keg-only, which means it was not symlinked into /usr/local.Apple has deprecated use of OpenSSL in favor of its own TLS and crypto librariesGenerally there are no consequences of this for you. If you build yourown software and it requires this formula, you'll need to add to yourbuild variables:LDFLAGS: -L/usr/local/opt/openssl/libCPPFLAGS: -I/usr/local/opt/openssl/include==> Summary? /usr/local/Cellar/openssl/1.0.2j: 1,695 files, 12M==> Installing mysql==> Downloading /bottles/mysql-5.7.17.sierra.bottle.tar.gz######################################################################## 100.0%==> Pouring mysql-5.7.17.sierra.bottle.tar.gz==> /usr/local/Cellar/mysql/5.7.17/bin/mysqld --initialize-insecure --user=cony --basedir=/usr/local/Cellar/mysql/5.7.17 --datadir=/usr/local/var/mysql --tmpdir=/tmp==> CaveatsWe've installed your MySQL database without a root password. To secure it run: mysql_secure_installationTo connect run:mysql -urootTo have launchd start mysql now and restart at login:brew services start mysqlOr, if you don't want/need a background service you can just run: mysql.server start==> Summary? /usr/local/Cellar/mysql/5.7.17: 14,226 files, 444.4M

加入开机启动

➜ ~ cp /usr/local/opt/mysql/homebrew.mxcl.mysql.plist ~/Library/LaunchAgents/➜ ~ cp /usr/local/opt/mysql/homebrew.mxcl.mysql.plist /Users/cony/Library/LaunchAgents/➜ ~ launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist➜ ~ launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist

mysql命令:

mysql.server start # mysql 开启mysql.server stop # mysql 关闭

初始化mysql数据库:

➜ ~ cd /usr/local/Cellar/mysql/5.7.17/bin➜ ~ ./mysql_install_db

设置root账户和密码:

./mysql_secure_installation 一直跟着提示走就行

Redis安装

~ brew install redis==> Downloading /bottles/redis-3.2.6.sierra.bottle.tar.g######################################################################## 100.0%==> Pouring redis-3.2.6.sierra.bottle.tar.gz==> CaveatsTo have launchd start redis now and restart at login:brew services start redisOr, if you don't want/need a background service you can just run:redis-server /usr/local/etc/redis.conf==> Summary? /usr/local/Cellar/redis/3.2.6: 11 files, 1.7M

redis默认配置文件不允许以Deamon方式运行,因此需要先修改配置文件

~ vi /usr/local/etc/redis.conf

将daemonize修改为yes,然后载入配置文件即可实现后台进程启动

redis-server /usr/local/etc/redis.conf

加入开机启动

➜ ~ cp /usr/local/Cellar/redis/3.2.6/homebrew.mxcl.redis.plist /Users/cony/Library/LaunchAgents/

测试redis server是否启动

➜ ~ redis-cli pingPONG

php7安装

brew install php70 --without-apache --with-fpm

➜ ~ brew install php70 --without-apache --with-fpmUpdating Homebrew...==> Auto-updated Homebrew!Updated 1 tap (homebrew/core).No changes to formulae.==> Installing php70 from homebrew/php==> Installing dependencies for homebrew/php/php70: gettext, icu4c, jpeg, libxml2, unixodbc, readline==> Installing homebrew/php/php70 dependency: gettext==> Downloading /bottles/gettext-0.19.8.1.sierra.bottle.tar.gz######################################################################## 100.0%==> Pouring gettext-0.19.8.1.sierra.bottle.tar.gz==> CaveatsThis formula is keg-only, which means it was not symlinked into /usr/local.macOS provides the BSD gettext library and some software gets confused if both are in the library path.Generally there are no consequences of this for you. If you build yourown software and it requires this formula, you'll need to add to yourbuild variables:LDFLAGS: -L/usr/local/opt/gettext/libCPPFLAGS: -I/usr/local/opt/gettext/include==> Summary? /usr/local/Cellar/gettext/0.19.8.1: 1,934 files, 16.9M==> Installing homebrew/php/php70 dependency: icu4c==> Downloading /bottles/icu4c-58.2.sierra.bottle.tar.gz######################################################################## 100.0%==> Pouring icu4c-58.2.sierra.bottle.tar.gz==> CaveatsThis formula is keg-only, which means it was not symlinked into /usr/local.macOS provides libicucore.dylib (but nothing else).Generally there are no consequences of this for you. If you build yourown software and it requires this formula, you'll need to add to yourbuild variables:LDFLAGS: -L/usr/local/opt/icu4c/libCPPFLAGS: -I/usr/local/opt/icu4c/include==> Summary? /usr/local/Cellar/icu4c/58.2: 242 files, 65M==> Installing homebrew/php/php70 dependency: jpeg==> Downloading /bottles/jpeg-8d.sierra.bottle.2.tar.gz######################################################################## 100.0%==> Pouring jpeg-8d.sierra.bottle.2.tar.gz? /usr/local/Cellar/jpeg/8d: 19 files, 708.3K==> Installing homebrew/php/php70 dependency: libxml2==> Downloading /bottles/libxml2-2.9.4_2.sierra.bottle.tar.gz######################################################################## 100.0%==> Pouring libxml2-2.9.4_2.sierra.bottle.tar.gz==> CaveatsThis formula is keg-only, which means it was not symlinked into /usr/local.macOS already provides this software and installing another version inparallel can cause all kinds of trouble.Generally there are no consequences of this for you. If you build yourown software and it requires this formula, you'll need to add to yourbuild variables:LDFLAGS: -L/usr/local/opt/libxml2/libCPPFLAGS: -I/usr/local/opt/libxml2/include==> Summary? /usr/local/Cellar/libxml2/2.9.4_2: 277 files, 9.8M==> Installing homebrew/php/php70 dependency: unixodbc==> Downloading /bottles/unixodbc-2.3.4.sierra.bottle.tar.gz######################################################################## 100.0%==> Pouring unixodbc-2.3.4.sierra.bottle.tar.gz? /usr/local/Cellar/unixodbc/2.3.4: 39 files, 952.5K==> Installing homebrew/php/php70 dependency: readline==> Downloading /bottles/readline-7.0.1.sierra.bottle.tar.gz######################################################################## 100.0%==> Pouring readline-7.0.1.sierra.bottle.tar.gz==> CaveatsThis formula is keg-only, which means it was not symlinked into /usr/local.macOS provides the BSD libedit library, which shadows libreadline.In order to prevent conflicts when programs look for libreadline we aredefaulting this GNU Readline installation to keg-only.Generally there are no consequences of this for you. If you build yourown software and it requires this formula, you'll need to add to yourbuild variables:LDFLAGS: -L/usr/local/opt/readline/libCPPFLAGS: -I/usr/local/opt/readline/include==> Summary? /usr/local/Cellar/readline/7.0.1: 46 files, 2MWarning: homebrew/php/php70: this formula has no --with-fpm option so it will be ignored!Warning: homebrew/php/php70: this formula has no --without-apache option so it will be ignored!==> Installing homebrew/php/php70==> Downloading /bottles-php/php70-7.0.14_7.sierra.bottle.tar.gz######################################################################## 100.0%==> Pouring php70-7.0.14_7.sierra.bottle.tar.gz==> CaveatsThe php.ini file can be found in:/usr/local/etc/php/7.0/php.ini✩✩✩✩ Extensions ✩✩✩✩If you are having issues with custom extension compiling, ensure thatyou are using the brew version, by placing /usr/local/bin before /usr/sbin in your PATH:PATH="/usr/local/bin:$PATH"PHP70 Extensions will always be compiled against this PHP. Please install themusing --without-homebrew-php to enable compiling against system PHP.✩✩✩✩ PHP CLI ✩✩✩✩If you wish to swap the PHP you use on the command line, you should add the following to ~/.bashrc,~/.zshrc, ~/.profile or your shell's equivalent configuration file:export PATH="$(brew --prefix homebrew/php/php70)/bin:$PATH"✩✩✩✩ FPM ✩✩✩✩To launch php-fpm on startup:mkdir -p ~/Library/LaunchAgentscp /usr/local/opt/php70/homebrew.mxcl.php70.plist ~/Library/LaunchAgents/launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.php70.plistThe control script is located at /usr/local/opt/php70/sbin/php70-fpmOS X 10.8 and newer come with php-fpm pre-installed, to ensure you are using the brew version you need to make sure /usr/local/sbin is before /usr/sbin in your PATH:PATH="/usr/local/sbin:$PATH"You may also need to edit the plist to use the correct "UserName".Please note that the plist was called 'homebrew-php.josegonzalez.php70.plist' in old versionsof this formula.With the release of macOS Sierra the Apache module is now not built by default. If you want to build it on your systemyou have to install php with the --with-httpd24 option. See brew options php70 for more details.To have launchd start homebrew/php/php70 now and restart at login:brew services start homebrew/php/php70==> Summary? /usr/local/Cellar/php70/7.0.14_7: 332 files, 38.8M

设置php的全局变量

➜ ~ vi ~/.zshrcexport LOCALBIN=/usr/local/binexport SBIN=/usr/sbinexport PATH=$LOCALBIN:$SBIN:$PATHexport PHPBIN=$(brew --prefix homebrew/php/php70)/binexport PATH=$PHPBIN:$PATH➜ ~ source ~/.zshrc # 即时生效

安装需要的php扩展

➜ ~ brew install homebrew/php/php70-gearman homebrew/php/php70-mongodb homebrew/php/php70-phalcon homebrew/php/php70-redisUpdating Homebrew...==> Auto-updated Homebrew!Updated 1 tap (homebrew/core).==> New Formulaenativefier spdlog==> Updated Formulaearangodbnghttp2 passenger==> Installing php70-gearman from homebrew/php==> Installing dependencies for homebrew/php/php70-gearman: boost, libevent, gearman==> Installing homebrew/php/php70-gearman dependency: boost==> Downloading /bottles/boost-1.63.0.sierra.bottle.tar.gz######################################################################## 100.0%==> Pouring boost-1.63.0.sierra.bottle.tar.gz? /usr/local/Cellar/boost/1.63.0: 12,491 files, 397.1M==> Installing homebrew/php/php70-gearman dependency: libevent==> Downloading /bottles/libevent-2.0.22.sierra.bottle.1.tar.gz######################################################################## 100.0%==> Pouring libevent-2.0.22.sierra.bottle.1.tar.gz? /usr/local/Cellar/libevent/2.0.22: 734 files, 2.0M==> Installing homebrew/php/php70-gearman dependency: gearman==> Downloading /bottles/gearman-1.1.14.sierra.bottle.tar.gz######################################################################## 100.0%==> Pouring gearman-1.1.14.sierra.bottle.tar.gz==> CaveatsTo have launchd start gearman now and restart at login:brew services start gearmanOr, if you don't want/need a background service you can just run:gearmand -d==> Summary? /usr/local/Cellar/gearman/1.1.14: 211 files, 1.7M==> Installing homebrew/php/php70-gearman==> Downloading /wcgallego/pecl-gearman/archive/gearman-2.0.1.tar.gz==> Downloading from /wcgallego/pecl-gearman/tar.gz/gearman-2.0.1######################################################################## 100.0%==> /usr/local/opt/php70/bin/phpize==> ./configure --prefix=/usr/local/Cellar/php70-gearman/2.0.1 --with-php-config=/usr/local/opt/php70/bin/php-config --with-gearman=/usr/local/opt/gearman==> make==> CaveatsTo finish installing gearman for PHP 7.0:* /usr/local/etc/php/7.0/conf.d/ext-gearman.ini was created,do not forget to remove it upon extension removal.* Validate installation via one of the following methods:** Using PHP from a webserver:* - Restart your webserver.* - Write a PHP page that calls "phpinfo();"* - Load it in a browser and look for the info on the gearman module.* - If you see it, you have been successful!** Using PHP from the command line:* - Run `php -i "(command-line 'phpinfo()')"`* - Look for the info on the gearman module.* - If you see it, you have been successful!==> Summary? /usr/local/Cellar/php70-gearman/2.0.1: 7 files, 102.9K, built in 22 seconds==> Installing php70-mongodb from homebrew/php==> Downloading /bottles-php/php70-mongodb-1.2.2_1.sierra.bottle.tar.gz######################################################################## 100.0%==> Pouring php70-mongodb-1.2.2_1.sierra.bottle.tar.gz==> CaveatsTo finish installing mongodb for PHP 7.0:* /usr/local/etc/php/7.0/conf.d/ext-mongodb.ini was created,do not forget to remove it upon extension removal.* Validate installation via one of the following methods:** Using PHP from a webserver:* - Restart your webserver.* - Write a PHP page that calls "phpinfo();"* - Load it in a browser and look for the info on the mongodb module.* - If you see it, you have been successful!** Using PHP from the command line:* - Run `php -i "(command-line 'phpinfo()')"`* - Look for the info on the mongodb module.* - If you see it, you have been successful!==> Summary? /usr/local/Cellar/php70-mongodb/1.2.2_1: 3 files, 655.2K==> Installing php70-phalcon from homebrew/php==> Downloading /bottles-php/php70-phalcon-3.0.2.sierra.bottle.tar.gz######################################################################## 100.0%==> Pouring php70-phalcon-3.0.2.sierra.bottle.tar.gz==> CaveatsTo finish installing phalcon for PHP 7.0:* /usr/local/etc/php/7.0/conf.d/ext-phalcon.ini was created,do not forget to remove it upon extension removal.* Validate installation via one of the following methods:** Using PHP from a webserver:* - Restart your webserver.* - Write a PHP page that calls "phpinfo();"* - Load it in a browser and look for the info on the phalcon module.* - If you see it, you have been successful!** Using PHP from the command line:* - Run `php -i "(command-line 'phpinfo()')"`* - Look for the info on the phalcon module.* - If you see it, you have been successful!==> Summary? /usr/local/Cellar/php70-phalcon/3.0.2: 5 files, 3.5M==> Installing php70-redis from homebrew/php==> Downloading /phpredis/phpredis/archive/3.0.0.tar.gz==> Downloading from /phpredis/phpredis/tar.gz/3.0.0######################################################################## 100.0%==> /usr/local/opt/php70/bin/phpize==> ./configure --prefix=/usr/local/Cellar/php70-redis/3.0.0 --with-php-config=/usr/local/opt/php70/bin/php-config==> make==> CaveatsTo finish installing redis for PHP 7.0:* /usr/local/etc/php/7.0/conf.d/ext-redis.ini was created,do not forget to remove it upon extension removal.* Validate installation via one of the following methods:** Using PHP from a webserver:* - Restart your webserver.* - Write a PHP page that calls "phpinfo();"* - Load it in a browser and look for the info on the redis module.* - If you see it, you have been successful!** Using PHP from the command line:* - Run `php -i "(command-line 'phpinfo()')"`* - Look for the info on the redis module.* - If you see it, you have been successful!==> Summary? /usr/local/Cellar/php70-redis/3.0.0: 5 files, 405.3K, built in 20 seconds

直接运行,有报错找不到配置文件。

$ php-fpm

[11-Jan- 16:03:03] ERROR: failed to open configuration file '/private/etc/php-fpm.conf': No such file or directory (2)[11-Jan- 16:03:03] ERROR: failed to load configuration file '/private/etc/php-fpm.conf'[11-Jan- 16:03:03] ERROR: FPM initialization failed

可以在/private/etc/ 目录下生成配置文件,需要root权限(sudo)

或者在普通用户有权限的目录里放置配置文件,通过--fpm-config参数指定配置文件的位置,如下:

# cp /private/etc/php-fpm.conf.default /usr/local/etc/php-fpm.conf

$ php-fpm --fpm-config /usr/local/etc/php-fpm.conf

[11-Jan- 16:10:49] ERROR: failed to open error_log (/usr/var/log/php-fpm.log): No such file or directory (2)[11-Jan- 16:10:49] ERROR: failed to post process the configuration[11-Jan- 16:10:49] ERROR: FPM initialization failed

错误信息显示:不能正确的打开”日志“文件,原因是默认在/usr/var目录下工作,可以修改配置文件指定正确的日志文件路径

$ vim /usr/local/etc/php-fpm.conf

修改php-fpm.conf文件中的error_log项,默认前缀是/usr/var ,但并没有这个路径

error_log = /usr/local/var/log/php-fpm.logpid = /usr/local/var/run/php-fpm.pid

或者不修改配置文件中配置项的路径,在php-fpm的运行参数中(-p)指定放置运行时文件的相对路径前缀

$ php-fpm --fpm-config /usr/local/etc/php-fpm.conf --prefix /usr/local/var

到此,php-fpm守护进程已经基本可以正确的启动了。

下面我们看下php.ini配置文件及扩展的安装。

首先看下编译参数,有些值是编译进执行程序的,无法更改。

$ php -i|grep config

找到配置文件(php.ini)、目录的位置,下面两项的值指定

'--with-config-file-path=/etc'

'--with-config-file-scan-dir=/Library/Server/Web/Config/php'

所以我们需要在/etc目录下创建php.ini,Mac在/private/etc,/etc下均提供了样例文件php.ini.default,通过查验,两个文件完全相同,所以复制哪一个都无所谓,Mac有提供md5而不是Linux下的md5sum:

$ md5 /private/etc/php.ini.default /etc/php.ini.default

MD5 (/private/etc/php.ini.default) = 1c47241665ea5efdc55fd5809f675449

MD5 (/etc/php.ini.default) = 1c47241665ea5efdc55fd5809f675449

/etc目录权限root:wheel,需要root权限或使用sudo,关于如何设置Mac的sudo命令需要的密码,请查看

/kb/HT4103?viewlocale=zh_CN&locale=zh_CN

/kb/PH6515?viewlocale=zh_CN

# cp /etc/php.ini.default /etc/php.ini

变更own,以后修改不用老是切换root,生产环境最好不要改

# chown <你的用户名> /etc/php.ini# chmod u+w /etc/php.ini

php扩展介绍

php70-amqp 高级消息队列协议php70-ast 抽象语法树php70-blitz 用C语言开发的快速的PHP模板引擎php70-couchbase 新兴的NOSQL数据库php70-gearman 异步任务分发处理利器php70-geoip 根据IP获取地理位置及计算距离的方法,包括获取目标IP所在的国家地区等信息php70-gmagick 图像生成和处理php70-gmp 是一个开源的数学运算库,它可以用于任意精度的数学运算php70-hprose 高性能远程对象服务引擎php70-ioncubeloader 加密PHP的工具...

加入开机自启

➜ ~ cp /usr/local/opt/php70/homebrew.mxcl.php70.plist ~/Library/LaunchAgents/➜ ~ cp /usr/local/opt/php70/homebrew.mxcl.php70.plist /Users/cony/Library/LaunchAgents/➜ ~ launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.php70.plist➜ ~ launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.php70.plist

配置nginx

➜ ~ vi /usr/local/etc/nginx/servers/.confserver {listen 80;server_name ;root /Users/cony/Work/php/test;location / {index index.html index.htm index.php;}location ~ \.php$ {fastcgi_pass 127.0.0.1:9000;fastcgi_index index.php;fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;include fastcgi_params;}}➜ ~ sudo nginx -s reload➜ ~ sudo vi /etc/hosts # 添加 127.0.0.1

链接:/p/ae3f88d52e21

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。