版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/zhazhaji/article/details/80969970
安装目录
# 安装brew工具
# 安装mysql
# 安装nginx
# 安装php
步骤
1. 安装brew工具
# sudo chown -R $(whoami) /usr/local/Cellar
# /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
# brew install ncurses [mysql依赖库
2. 安装mysql 并且设置mysql密码
# sudo chown -R 'mac' /usr/local 这里的mac指的是当前登录的用户名,划分权限
# brew install mysql
# brew link —overwrite mysql
# mysql.server start
# mysql --version 查看mysql版本
---------mysql8.0版本以上都需要做的--------------
# mysql.server stop
# which mysql
/usr/local/bin/mysql
# /usr/local/bin/mysql --verbose --help | grep -A 1 'Default options'
目前提示我的my.conf在/usr/local/etc/my.conf
# vi /usr/local/etc/my.conf
# 添加配置 default_authentication_plugin=mysql_native_password
# mysql.server start
--------mysql8.0版本以上都需要做的-------------------
# sudo su
# mysql 进入命令行设置密码
----------mysql8.0版本以下-----------
# set global validate_password_length=4;
# ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
---------mysql8.0版本以上------------
# ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';
3. 安装nginx 并且 配置nginx
nginx依赖如下:
pcre
zlib
openssl #注意,该依赖只有 config文件,并没有configure文件
# cd /usr/local/src
# su mac #切换登录用户
# brew install wget
# wget 三个依赖的网址下来
# tar zxvf 三个依赖压缩包
# cd pcre
# ./configure --prefix=/usr/local/pcre #以pcre举例子
# make && make install
# mkdir -p /usr/local/extension/php
**********
安装openssl的时候,指定--prefx=/usr/local/extension/php/openssl
执行 # echo 'export PATH=$PATH:/usr/local/extension/php/openssl/bin'>>/etc/profile
*************
# cd /usr/local/src/nginx
./configure --prefix=/usr/local/nginx --with-http_ssl_module \
--with-http_gzip_static_module \
--with-openssl=/usr/local/src/openssl-1.0.2o \
--with-zlib=/usr/local/src/zlib-1.2.11 \
--with-pcre=/usr/local/src/pcre-8.00
# make && make install
nginx报错解决方案:点击查看
# cd /usr/local/nginx
# cp sbin/nginx /usr/bin
# nginx
浏览器浏览 localhost 会看到nginx的界面已经成功了。下面先配置下nginx-php
# vi conf/nginx.conf
我的nginx.conf配置如下,php的项目在/Users/mac/code/www/
#user nobody;
worker_processes 1;
error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.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 logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
gzip on;
server {
listen 80;
server_name localhost;
#charset koi8-r;
access_log logs/host.access.log main;
location / {
root /Users/mac/code/www/;
index index.php index.html index.htm;
}
#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;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root /Users/mac/code/www/;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /Users/mac/code/www$fastcgi_script_name;
include fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# 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;
# }
#}
}
4. 安装php
$ cd /usr/local/src
下载以下php的扩展库
libpng
libjpeg
libiconv
libmhash
libmcrypt 注意不是mcrypt
libxml2
freetype
curl
所有扩展安装方法如下,以libpng为例子
$ tar zxvf libpng.tar.gz
$ cd libpng
$ mkdir -p /usr/local/extension/php
$ ./configure --prefix=/usr/local/extension/php/libpng #libpng代替扩展名即可
$ make && make install
***************
其中curl库需注意
./configure —prefix=/usr/local/extension/php/curl —with-ssl=//usr/local/extension/php/openssl
***************
$ cd /usr/local/src
下载php7以及解压
$ cd php7
$ ./configure \
--prefix=/usr/local/php7.0 \
--with-config-file-path=/usr/local/php7.0 \
--enable-pdo \
--with-pdo-mysql \
--with-mysql-sock=/tmp/mysql.sock \
--enable-opcache \
--enable-cgi \
--enable-fpm \
--enable-sockets \
--enable-mbstring \
--enable-mbregex \
--enable-bcmath \
--enable-session \
--enable-xml \
--enable-zip \
--with-zlib \
--with-gd \
--with-freetype-dir=/usr/local/extension/php/freetype \
--with-png-dir=/usr/local/extension/php/libpng \
--with-jpeg-dir=/usr/local/extension/php/libjpeg \
--with-curl=/usr/local/extension/php/curl \
--with-mhash=/usr/local/extension/php/libmhash \
--with-mcrypt=/usr/local/extension/php/libmcrypt \
--with-iconv=/usr/local/extension/php/libiconv
注意上面的有路径,就是指上上面安装库的路径
下面配置php
$ cd /usr/local/php7.0/etc
$ cp php-fpm.conf.default php-fpm.conf
$ cd php-fpm.d
$ cp www.conf.default www.conf
$ vi www.conf
配置文件把其中的group user两个 改为你机子的用户以及组名
$ cd /usr/local/php7.0
$ cp /usr/local/src/phpxxxx/php.ini.development /usr/local/php7.0/lib/php.ini
$ 启动php-fpm
$ /usr/local/php7.0/sbin/php-fpm -c /usr/local/php7.0/lib/php.ini
nginx mysql php都安装好了,最后测试下
$ nginx 开启nginx
$ /usr/local/php7.0/sbin/php-fpm -c /usr/local/php7.0/lib/php.ini 开启php
我的nginx.conf配置如下,php的项目在/Users/mac/code/www/
$ vi /Users/mac/code/www/index.php
phpinfo();
浏览器打开 localhost
完事!