美文网首页
MAC环境搭建Nginx+MariaDB+PHP(编译安装)

MAC环境搭建Nginx+MariaDB+PHP(编译安装)

作者: Haivin | 来源:发表于2018-07-01 01:14 被阅读0次

    通过源代码编译安装Nginx,MariaDB和PHP。

    安装MariaDB

    下载地址:MariaDB下载
    本次安装的是MariaDB 10.3.7 版本

    安装工具和依赖

    安装cmake
    https://cmake.org/download/ 下载cmake并安装,因为只是工具直接下载安装包安装即可。

    编译安装

    cmake . -DCMAKE_INSTALL_PREFIX=/data/server/mariadb \
    -DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
    -DMYSQL_DATADIR=/data/server/mariadb/data \
    -DMYSQL_USER=_mysql \
    -DMYSQL_TCP_PORT=3306 \
    -DWITH_PCRE=bundled \
    -DWITH_SSL=yes \
    -DDEFAULT_CHARSET=utf8mb4 \
    -DDEFAULT_COLLATION=utf8mb4_general_ci \
    -DPLUGIN_TOKUDB=NO  \   //mac系统不支持TOKUDB,必须设置为NO
    -DWITH_READLINE=yes 
    
    make -j 4
    make install
    

    初始化配置

    //启动mysql 
    cd /data/server/mariadb
    ./support-files/mysql.server start
    //初始化数据库表
    ./scripts/mysql_install_db
    //初始化配置,输入命令后根据提示操作即可
    ./bin/mysql_secure_installation
    

    PHP编译安装

    安装依赖

    使用brew安装

    brew install mhash libmcrypt mcrypt openssl gettext
    

    或者编译安装

    //安装mhash
    ./configure --prefix=/data/program/mhash
    make && make install
    //安装libmcrypt
    ./configure --prefix=/data/program/libmcrypt
    make && make install
    //添加环境变量
    export LD_LIBRARY_PATH="/data/program/mhash/lib/:/data/program/libmcrypt/lib"
    export CFLAGS="-I/data/program/mhash/include/"
    export LDFLAGS="-L/data/program/mhash/lib/ -I/data/program/mhash/include/"
    export PATH="/usr/local/opt/gettext/bin:$PATH"
    //安装mcrypt
    ./configure --prefix=/data/program/mcrypt --with-libmcrypt-prefix=/data/program/libmcrypt
    make && make install
    

    安装PHP

    //下面的配置中填写了绝对路径,如果使用brew安装不需要填写
    ./configure  --enable-fpm  \
    --with-fpm-user=www  \
     --with-fpm-group=www   \
    --prefix=/data/server/php-5.6.35   \
    --enable-soap   \
    --enable-mbstring   \
    --enable-shmop   \
    --enable-wddx   \
    --with-mysql \
    --with-mysqli \
    --with-openssl=/usr/local/Cellar/openssl/1.0.2o_2  \
    --with-iconv   \
    --with-zlib   \
    --with-jpeg-dir   \
    --with-gd   \
    --enable-gd-native-ttf   \
    --enable-ftp   \
    --enable-inline-optimization   \
    --enable-exif  \
    --enable-sockets   \
    --enable-sysvsem   \
    --enable-sysvshm   \
    --enable-bcmath   \
    --enable-calendar   \
    --enable-mbregex   \
    --with-curl   \
    --with-png-dir   \
    --with-freetype-dir   \
    --with-mcrypt=/data/program/libmcrypt   \
    --with-mhash=/data/program/mhash   \
    --with-gettext=/data/program/gettext   \
    --with-config-file-path=/data/server/php-5.6.35/etc   \
    --enable-opcache   \
    --enable-maintainer-zts   \
    CFLAGS=-I/data/program/mhash/include/ 'LDFLAGS=-L/data/program/mhash/lib/ -I/data/program/mhash/include/'
    
    make && make install
    

    修改配置

    修改php-fpm文件

    [www]
    user = _www
    group = _www
    listen = 127.0.0.1:9000
    pm = dynamic
    pm.max_children = 10
    pm.start_servers = 2
    pm.min_spare_servers = 2
    pm.max_spare_servers = 5
    

    Nginx编译安装

    安装依赖

    下载openssl:https://www.openssl.org/source/old/1.1.0/openssl-1.1.0g.tar.gz
    下载pcre:https://ftp.pcre.org/pub/pcre/pcre-8.42.tar.gz
    下载zlib:http://www.zlib.net/zlib-1.2.11.tar.gz

    安装Nginx

    下载地址:http://nginx.org/download/nginx-1.15.0.tar.gz
    下载后解压,本机的解压跟目录为/data/workshop/,安装目录为/data/server/,然后执行如下命令

    cd /data/workshop/nginx-1.15.0
    
    ./configure --prefix=/data/server/nginx  \
    --with-select_module  \
    --with-poll_module  \
    --with-threads  \
    --with-ipv6  \
    --with-http_ssl_module  \
    --with-http_v2_module  \
    --with-http_realip_module  \
    --with-http_addition_module  \
    --with-http_xslt_module  \
    --with-http_image_filter_module  \
    --with-http_geoip_module  \
    --with-http_sub_module  \
    --with-http_dav_module  \
    --with-http_flv_module  \
    --with-http_mp4_module  \
    --with-http_gunzip_module  \
    --with-http_gzip_static_module  \
    --with-http_auth_request_module  \
    --with-http_random_index_module  \
    --with-http_secure_link_module  \
    --with-http_degradation_module  \
    --with-http_slice_module  \
    --with-http_stub_status_module  \
    --with-openssl=/data/workshop/openssl-1.1.0g  \
    --with-pcre=/data/workshop/pcre-8.42 \
    --with-zlib=/data/workshop/zlib-1.2.11 \
    //--with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie' \
    //--add-module=/data/workshop/lua-nginx-module-0.10.13 \
    //--add-module=/data/workshop/ngx_devel_kit-0.3.1rc1
    
    make && sudo make install
    

    安装完成后进行测试:
    执行如下命令后访问 http://localhost

    /data/server/nginx/sbin/nginx
    

    常用命令:

    nginx -t               //修改配置文件后测试配置
    nginx -s reload        //修改配置文件后重新加载
    nginx -s stop          //停止nginx
    nginx -c nginx.conf    //启动并指定配置文件
    

    fastcgi简单配置

    server {
        listen 80;
        server_name localhost;
        root /data/webroot/;
        location / {
            root /data/webroot/;
        }
        location ~ .*\.php$ {
            root /data/webroot/;
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_index index.php;
            try_files $uri $uri/ /index.php?$query_string;
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            include fastcgi_params;
            fastcgi_param CI_ENV 'production';
            fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
            #如下为跨域设置
            if ($request_method = 'OPTIONS') {
                add_header 'Access-Control-Allow-Origin' '*';
                add_header 'Access-Control-Allow-Credentials' 'true';
                add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, PUT, DELETE';
                add_header 'Access-Control-Allow-Headers' 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,x-ecapi-sign,x-ecapi-udid,x-ecapi-useragent,x-ecapi-ver,x-ecapi-new-authorization,X-ECAPI-Ver,X-ECAPI-Sign,X-ECAPI-UDID,X-ECAPI-UserAgent,X-ECAPI-ErrorCode,X-ECAPI-ErrorDesc,X-ECAPI-Authorization';
            }
        }
    }
    

    相关文章

      网友评论

          本文标题:MAC环境搭建Nginx+MariaDB+PHP(编译安装)

          本文链接:https://www.haomeiwen.com/subject/frctuftx.html