在Mac OS下搭建LNMP开发环境的步骤详解

2019-05-01 22:56:22王冬梅

然后可以设置php-fpm的开机自启动:

mkdir -p ~/Library/LaunchAgents
ln -sfv /usr/local/opt/php56/homebrew.mxcl.php56.plist ~/Library/LaunchAgents/
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.php56.plist

使用以下命令监测php-fpm是否启动成功:

lsof -Pni4 | grep LISTEN | grep php

如果启动成功应当有以下类似输出:

php-fpm 27578 wenzhiquan 9u IPv4 0xf29f8b26c08fc27  0t0 TCP 127.0.0.1:9000 (LISTEN)
php-fpm 27628 wenzhiquan 0u IPv4 0xf29f8b26c08fc27  0t0 TCP 127.0.0.1:9000 (LISTEN)
php-fpm 27629 wenzhiquan 0u IPv4 0xf29f8b26c08fc27  0t0 TCP 127.0.0.1:9000 (LISTEN)
php-fpm 27630 wenzhiquan 0u IPv4 0xf29f8b26c08fc27  0t0 TCP 127.0.0.1:9000 (LISTEN)

五、安装MySQL

MySQL也可以使用brew命令直接进行安装:

brew install mysql

同样,可以设置MySQL的开机自启动:

ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist

然后进行MySQL的安全安装,使用以下命令,可以更改root密码、删除匿名用户、关闭远程连接等:

mysql_secure_installation

然后会输出以下内容:

> Enter current password for root (enter for none):  //默认没有密码,直接回车即可
> Change the root password? [Y/n]      //是否更改root密码,选择是,然后输入并确认密码
> Remove anonymous users? [Y/n]       //是否删除匿名用户,选择是
> Disallow root login remotely? [Y/n]     //是否禁止远程登录,选择是
> Remove test database and access to it? [Y/n]   //是否删除test数据库,选择是
> Reload privilege tables now? [Y/n]     //是否重载表格数据,选择是

测试数据库是否安装成功:

mysql -u root -p

然后输入刚才设置的root密码,将会输出以下内容:

Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.

mysql> exit   //输入exit退出数据库

六、配置nginx

首先,为我们的配置文件创建一些文件夹,这些是仿照ubuntu的nginx结构进行建立的目录:

mkdir -p /usr/local/etc/nginx/logs
mkdir -p /usr/local/etc/nginx/sites-available
mkdir -p /usr/local/etc/nginx/sites-enabled
mkdir -p /usr/local/etc/nginx/conf.d
mkdir -p /usr/local/etc/nginx/ssl

sudo mkdir -p /var/www
sudo chown :staff /var/www
sudo chmod 775 /var/www

然后修改nginx配置文件:

vim /usr/local/etc/nginx/nginx.conf

将内容替换为:

worker_processes 1;

error_log /usr/local/etc/nginx/logs/error.log debug;

events {
 worker_connections 1024;
}

http {
 include    mime.types;
 default_type  application/octet-stream;

 log_format main '$remote_addr - $remote_user [$time_local] "$request" '
      '$status $body_bytes_sent "$http_referer" '
      '"$http_user_agent" "$http_x_forwarded_for"';

 access_log /usr/local/etc/nginx/logs/access.log main;

 sendfile   on;

 keepalive_timeout 65;

 index index.html index.php;

 include /usr/local/etc/nginx/sites-enabled/*;
}								 
			 
相关文章 大家在看