广告:宝塔Linux面板高效运维的服务器管理软件 点击【 https://www.bt.cn/p/uNLv1L 】立即购买

本篇文章给大家介绍一下MAC使用php7搭建LNMP环境的方法。有一定的参考价值,有需要的朋友可以参考一下,希望对大家有所帮助。
1、安装MySQL:查看MySQL可用版本信息:
brew info mysql登录后复制
我这边看到的版本是5.7.10:
mysql: stable 5.7.10 (bottled)登录后复制
接下来安装MySQL5.7.10:
brew install mysql登录后复制
安装完成之后按照提示将plist文件放入~/Library/LaunchAgents/中并load,设定MySQL开机启动:
ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents登录后复制
启动MySQL:
mysql.server start登录后复制
启动之后由于MySQL默认没有设置密码,所以要设置root的密码:
mysql -uroot -p登录后复制
提示输入密码的时候直接按回车就登录了,登录MySQL后提示如下:
Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 2Server version: 5.7.10 Homebrew登录后复制
接下来设置root的密码:
ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!';登录后复制
设置密码的时候最好设置一个强密码,关于强密码的规则,官方有如下说明:
NoteMySQL's validate_password plugin is installed by default. This will require that passwords contain at least one upper case letter, one lower case letter, one digit, and one special character, and that the total password length is at least 8 characters.登录后复制
为了方便使用,我们经常会创建任意连接的root用户:
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'MyNewPass4!' WITH GRANT OPTION;登录后复制
刷新权限使命令生效:
mysql: stable 5.7.10 (bottled)0登录后复制
退出MySQL:exit;ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents3 with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies复制mysql配置文件:
mysql: stable 5.7.10 (bottled)1登录后复制
在/etc/my.cnf 中的[mysqld]后添加lower_case_table_names=1,重启MYSQL服务,这时已设置成功:不区分表名的大小写;
PS.lower_case_table_names参数详解: 0:区分大小写,1:不区分大小写
2、安装php7:①、下载php7:mysql: stable 5.7.10 (bottled)2登录后复制②、构建php7:
mysql: stable 5.7.10 (bottled)3登录后复制③、编译php:
PS.编译的时候如果内存1G以下请在结尾加上:--disable-fileinfo,
安装php7时需要用安装re2c、bison、ffmpeg、mcrypt、libiconv、gd、openssl:
安装re2c:
mysql: stable 5.7.10 (bottled)4登录后复制
安装bison(3.0.4):
mysql: stable 5.7.10 (bottled)5登录后复制
安装ffmpeg:
mysql: stable 5.7.10 (bottled)6登录后复制
安装openssl:
mysql: stable 5.7.10 (bottled)7登录后复制
安装mcrypt:
mysql: stable 5.7.10 (bottled)8登录后复制
安装libiconv:
mysql: stable 5.7.10 (bottled)9登录后复制
如果想要用openssl,刚才已经安装了openssl,但是系统自带了openssl,所以要用安装的openssl替换系统自带的openssl:
brew install mysql0登录后复制
替换完成之后输入openssl version就可以看到是上面用brew安装的openssl了,因为在编译php过程中需要openssl的header,但是安装的时候都没有
编译php7:
brew install mysql1登录后复制
如果编译过程中提示:Cannot locate header file libintl.h,请执行如下操作:
①、安装gettext:
brew install mysql2登录后复制
②、修改configure文件:
brew install mysql3登录后复制
找到如下文件:
brew install mysql4登录后复制
替换为:
brew install mysql5登录后复制
如果提示openssl错误,在编译的时候设定openssl的路径,
brew install mysql6登录后复制④、执行完毕之后进行编译并安装:
brew install mysql7登录后复制
如果尝试很多办法都提示ssl出错,在编译的时候就不要加上openssl了
⑤、安装完成之后配置php7:brew install mysql8登录后复制
在安转完成之后会有提示:
brew install mysql9登录后复制
接下来编辑php.ini,
ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents0登录后复制登录后复制
找到include_path,在php.ini中加入include_path:
ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents1登录后复制
查看php版本:
ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents2登录后复制
显示结果如下:
ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents3登录后复制
更改配置,使php7支持opcache,在安装完成时会提示:
ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents4登录后复制
这个路径是扩展包路径,将路径复制下来,找到extension_dir并将刚才的路径添加到php.ini中,
ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents0登录后复制登录后复制
在php.ini中加入extension_dir的配置:
ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents6登录后复制
开启opcache扩展:
在php.ini中找到opcache,加入opcache.so
sudo mkdir -p /var/log/opcacheln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents0登录后复制
引用opcache.so:
ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents8登录后复制
并修改opcache的配置:
ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents9登录后复制
现在查看php版本信息,显示结果如下:
ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents3 with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies登录后复制
现在opcache扩展已经加入了,修改php-fpm的配置:
mysql.server start1登录后复制
修改配置:
mysql.server start2登录后复制
启动php-fpm:
mysql.server start3登录后复制
这样会提示两个警告:
mysql.server start4登录后复制
停止php-fpm的命令如下:
mysql.server start5登录后复制
重启php-fpm的命令如下:
mysql.server start6登录后复制
接下来开始安装mysql -uroot -p2:
3、安装mysql -uroot -p2:mysql.server start7登录后复制
安装完成的mysql -uroot -p2,默认的root路径如下:
mysql.server start8登录后复制
mysql -uroot -p2的配置文件目录如下:
mysql.server start9登录后复制
mysql -uroot -p2虚拟站点目录如下:
mysql -uroot -p0登录后复制
开机启动mysql -uroot -p2:
mysql -uroot -p1登录后复制
启动mysql -uroot -p2:
mysql -uroot -p2登录后复制
mysql -uroot -p2监听80端口是需要root权限的,现在mysql -uroot -p2默认监听的是8080端口:
sudo chown root:wheel /usr/local/Cellar/mysql -uroot -p2/1.8.1/bin/mysql -uroot -p2sudo chmod u+s /usr/local/Cellar/mysql -uroot -p2/1.8.1/bin/mysql -uroot -p2登录后复制
配置mysql -uroot -p2,先将mysql -uroot -p2的配置文件放至/etc下:
sudo ln -s mysql.server start9 /etcsudo ln -s /usr/local/etc/mysql -uroot -p2/servers /etc/mysql -uroot -p2servers登录后复制
修改mysql -uroot -p2监听端口:
sudo vi /etc/mysql -uroot -p2.conf登录后复制
修改配置文件如下:
#user nobody;worker_processes 4;error_log /usr/local/var/log/error.log;error_log /usr/local/var/log/error.log notice;error_log /usr/local/var/log/error.log info;pid /usr/local/var/run/mysql -uroot -p2.pid;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/var/log/access.log main; port_in_redirect off; sendfile on; tcp_nopush on; keepalive_timeout 65; gzip on; # HTTPS server # #server { # listen 443 ssl; # server_name localhost; # ssl_certificate cert.pem; # ssl_certificate_key cert.key; # ssl_session_cache shared:SSL:1m; # ssl_session_timeout 5m; # ssl_ciphers HIGH:!aNULL:!MD5; # ssl_prefer_server_ciphers on; # location / { # root html; # index index.html index.htm; # } #} include servers/*.conf;}登录后复制然后在/etc/mysql -uroot -p2servers/下创建default.conf,编辑default.conf,加入以下内容:
server { listen 80; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / { root html; index index.html index.htm; # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_intercept_errors on; include /usr/local/etc/mysql -uroot -p2/fastcgi.conf; } } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } # deny access to .htaccess files, if Apache's document root # concurs with mysql -uroot -p2's one # #location ~ /\.ht { # deny all; #} }登录后复制此时,LNMP已经搭建完毕,重启php-fpm和mysql -uroot -p2。
推荐学习:php视频教程
以上就是MAC如何使用php7搭建LNMP环境的详细内容,更多请关注9543建站博客其它相关文章!


发表评论