brew lnmp 环境安装

1、XCode 命令行工具

如果您尚未安装XCode,则最好先安装命令行工具,因为这些将由自制软件使用:

xcode-select —install

2、安装 brew 软件管理工具

此过程严重依赖于名为Homebrew的macOS软件包管理器。 使用brew命令,您可以轻松地向Mac添加强大的功能,但是首先我们必须安装它。 这是一个简单的过程,但是您需要启动终端/Applications/Utilities/Terminal)应用程序,然后输入:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

只需按照终端提示输入,然后在需要的地方输入密码即可。 这可能需要几分钟,但是完成后,一种快速的方法来确保您正确安装了brew,只需键入:

brew --version
> Homebrew 3.4.7
Homebrew/homebrew-core (git revision 661ff0fc146; last commit 2022-04-13)

您应该可以运行以下命令,以确保所有配置正确:

brew doctor

它会指导您是否需要更正任何内容。

3、安装 Nginx

brew install nginx

如果没有选项,nginx将不需要从源代码中构建,因此安装速度非常快。完成后,您应该看到如下消息:

==> Caveats
Docroot is: /usr/local/var/www

The default port has been set in /usr/local/etc/nginx/nginx.conf to 8080 so that
nginx 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 nginx
Or, if you don't want/need a background service you can just run:
  nginx
==> Summary
🍺  /usr/local/Cellar/nginx/1.21.6: 25 files, 2.1MB
==> Caveats
文档目录是:/usr/local/var/www

默认端口已在/usr/local/etc/nginx/nginx.cinf中设置为8080,以便nginx可以在没有sudo的情况下运行。

nginx将加载/usr/local.etc/nginx/servers/中所有的文件。

要立即启动nginx并且在登录时候重新启动
  brew services start nginx
  拷贝如下文件到~/Library/LaunchAgents/
  cp /usr/local/opt/nginx/homebrew.mxcl.nginx.plist ~/Library/LaunchAgents/
或者,如果您不想/不需要后台服务,您可以运行:
  nginx
==> Summary
🍺  /usr/local/Cellar/nginx/1.21.6: 25 files, 2.1MB

4、安装 PHP

brew install php
==> Caveats
To enable PHP in Apache add the following to httpd.conf and restart Apache:
    LoadModule php_module /usr/local/opt/php/lib/httpd/modules/libphp8.so

    <FilesMatch \.php$>
        SetHandler application/x-httpd-php
    </FilesMatch>

Finally, check DirectoryIndex includes index.php
    DirectoryIndex index.php index.html

The php.ini and php-fpm.ini file can be found in:
    /usr/local/etc/php/8.1/

To have launchd start php now and restart at login:
  brew services start php
Or, if you don't want/need a background service you can just run:
  php-fpm
==> Summary
🍺  /usr/local/Cellar/php/8.1.4: 517 files, 76MB
==> Caveats
要在Apache中启用php,请讲一下内容添加到httpd.conf并新重启Apache:
    LoadModule php_module /usr/local/opt/php/lib/httpd/modules/libphp8.so

    <FilesMatch \.php$>
        SetHandler application/x-httpd-php
    </FilesMatch>
最后,检查DirectoryIndex是否包含index.php
    DirectoryIndex index.php index.html

php.ini和php-fpm.ini文件可以在这里找到:
    /usr/local/etc/php/8.1/

现在启动php并且在登录时候重新启动
  brew services start php
  拷贝如下文件到~/Library/LaunchAgents/
  cp /usr/local/opt/httpd/homebrew.mxcl.php.plist ~/Library/LaunchAgents/
或者,如果您不想/不需要后台服务,您可以运行:
  php-fpm
==> Summary
🍺  /usr/local/Cellar/php/8.1.4: 517 files, 76MB

5、安装 MySQL

brew install mysql
==> Caveats
We've installed your MySQL database without a root password. To secure it run:
    mysql_secure_installation

MySQL is configured to only allow connections from localhost by default

To connect run:
    mysql -uroot

To have launchd start mysql now and restart at login:
  brew services start mysql
Or, if you don't want/need a background service you can just run:
  mysql.server start
==> Summary
🍺  /usr/local/Cellar/mysql/8.0.28: 286 files, 289.2MB
==> Caveats
我们已经安装了没有root密码的MySQL数据库。 为了确保它运行:
    mysql_secure_installation

MySQL默认配置为仅允许来自localhost的连接

连接运行:
    mysql -uroot

要启动,请立即启动mysql并在登录时重新启动:
  brew services start mysql
  拷贝如下文件到~/Library/LaunchAgents/
  cp /usr/local/opt/mysql/homebrew.mxcl.mysql.plist ~/Library/LaunchAgents/
或者,如果您不需要/需要后台服务,则可以运行:
  mysql.server start
==> Summary
🍺  /usr/local/Cellar/mysql/8.0.28: 286 files, 289.2MB

6、安装 Redis

brew install redis
==> Caveats
To have launchd start redis now and restart at login:
  brew services start redis
Or, 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/6.2.6: 13 files, 3.7MB
==> Caveats
要启动,请立即启动Redis,并在登录时重新启动:
  brew services start redis
  拷贝如下文件到~/Library/LaunchAgents/
  cp /usr/local/opt/redis/homebrew.mxcl.redis.plist ~/Library/LaunchAgents/
或者,如果您不需要/需要后台服务,则可以运行:
  redis-server /usr/local/etc/redis.conf
==> Summary
🍺  /usr/local/Cellar/redis/6.0.1: 13 files, 3.7MB

7、安装 phpredis

7.1 克隆(下载) phpredis

git clone https://github.com/phpredis/phpredis

7.2 进入 phpredis

cd phpredis

7.3 切换版本

git checkout 5.3.7

7.4 生产 configure

/usr/local/Cellar/php/8.1.4/bin/phpize

7.4 源码安装phpredis

./configure --with-php-config=/usr/local/Cellar/php/8.1.4/bin/php-config

make && make install
当编译成功后,我们会得到一个提示,在 /usr/local/Cellar/php/8.1.4/pecl/20210902/ 目录下有一个文件 redis.so

7.5 修改php.ini文件

修改php.ini文件,让其加载redis.so文件,这样我们就可以操作redis,php.ini文件在 /usr/local/etc/php/8.1/php.ini

vim /usr/local/etc/php/8.1/php.ini
extension=/usr/local/Cellar/php/8.1.4/pecl/20210902/redis.so

7.6 重启Nginx和PHP

重启nginx 和 php 后 访问index.php, 查看redis模块是否加载

8、安装 Memcached

brew install memcached
==> Caveats
To have launchd start memcached now and restart at login:
  brew services start memcached
Or, if you don't want/need a background service you can just run:
  /usr/local/opt/memcached/bin/memcached
==> Summary
🍺  /usr/local/Cellar/memcached/1.6.5: 11 files, 267.5KB
==> Caveats
要启动,请立即启动memcached并在登录时重新启动:
  brew services start memcached
  拷贝如下文件到~/Library/LaunchAgents/
  cp /usr/local/opt/memcached/homebrew.mxcl.memcached.plist ~/Library/LaunchAgents/
或者,如果您不需要/需要后台服务,则可以运行:
  /usr/local/opt/memcached/bin/memcached
==> Summary
🍺  /usr/local/Cellar/memcached/1.6.5: 11 files, 267.5KB

9、安装 Node

brew install node
==> Caveats
Bash completion has been installed to:
  /usr/local/etc/bash_completion.d
==> Summary
🍺  /usr/local/Cellar/node/14.1.0: 4,659 files, 60.8MB
==> Caveats
Bash完成已安装到:
  /usr/local/etc/bash_completion.d
==> Summary
🍺  /usr/local/Cellar/node/14.1.0: 4,659 files, 60.8MB
node -v

v17.9.0
npm -v

8.5.5

10、安装 Yarn

brew install yarn
🍺  /usr/local/Cellar/yarn/1.22.18: 14 files, 5MB, built in 73 minutes 8 seconds
yarn -v

1.22.18

11、安装 Composer

brew install composer
🍺  /usr/local/Cellar/composer/2.3.4: 3 files, 1.9MB, built in 2 minutes 7 seconds
composer -V

Composer version 2.3.4 2022-04-07 21:16:35
本作品采用《CC 协议》,转载必须注明作者和本文链接
KunHong
《L01 基础入门》
我们将带你从零开发一个项目并部署到线上,本课程教授 Web 开发中专业、实用的技能,如 Git 工作流、Laravel Mix 前端工作流等。
《G01 Go 实战入门》
从零开始带你一步步开发一个 Go 博客项目,让你在最短的时间内学会使用 Go 进行编码。项目结构很大程度上参考了 Laravel。
讨论数量: 0
(= ̄ω ̄=)··· 暂无内容!

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!