1. 程式人生 > >php編譯安裝 for mac

php編譯安裝 for mac

安裝目錄

# 安裝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
完事!