LNMP编译安装过程

2018-11-29
  1. 安装环境

    OS:centos7 nginx:1.14 mysql:5.6 php:5.6

  2. 编译安装nginx

    1
    2
    3
    4
    5
    6
    7
    8
    yum install pcre pcre-devel openssl openssl-devel gcc gcc+ wget -y 
    wget -q <http://nginx.org/download/nginx-1.14.1.tar.gz>
    tar zxf nginx-1.14.1.tar.gz
    cd nginx-1.14.1
    ./configure --prefix=/usr/local/nginx --pid-path=/var/run/nginx/nginx.pid --lock-path=/var/lock/nginx.lock --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --with-http_gzip_static_module
    make && make install
    ln -s /usr/local/nginx/sbin/nginx /usr/bin/nginx
    nginx
  3. 编译安装mysql

    1
    2
    3
    4
    5
    6
    7
    8
    9
    yum install wget gcc gcc-c++ git ncurses-devel libaio-devel  cmake perl-Module-Install.noarch -y
    wget -q http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.34.tar.gz
    tar -xvzf mysql-5.6.34.tar.gz
    cd mysql-5.6.34
    cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DSYSCONFDIR=/etc -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DMYSQL_UNIX_ADDR=/var/run/mysql/mysqld.sock -DMYSQL_TCP_PORT=3306 -DENABLED_LOCAL_INFILE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci
    make && make install
    chown -R mysql.mysql /usr/local/mysql/
    mv /etc/my.cnf.bak /etc/my.cnf
    vi /etc/my.cnf

    配置文件见我的github config-blog/my.cnf

    1
    2
    3
    4
    5
    6
    7
    8
    9
    cd /usr/local/mysql/ 	
    ./scripts/mysql_install_db --user=mysql --datadir=/usr/local/mysql/data --no-defaults cp ./support-files/mysql.server /etc/init.d/mysql
    chmod +x /etc/init.d/mysql
    mkdir /var/log/mysql/ -p
    chown -R mysql.mysql /var/log/mysql
    mkdir /var/run/mysql
    chown mysql /var/run/mysql
    chown -R mysql.mysql /var/lib/mysql/
    /etc/init.d/mysql start
  4. 编译安装php

    1
    2
    3
    4
    5
    6
    7
    yum install -y gcc gcc-c++ make gd-devel libxml2-devel libcurl-devel libjpeg-devel libpng-devel openssl-devel
    wget http://cn2.php.net/distributions/php-5.6.38.tar.gz
    tar -xvzf php-5.6.38.tar.gz
    cd php-5.6.38
    ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql --with-mysqli --with-openssl --with-zlib --with-curl --with-gd --with-jpeg-dir --with-png-dir --with-iconv --enable-fpm --enable-zip --enable-mbstring && make -j 4 && make install
    cd /usr/local/php/etc/
    vi php-fpm.conf.default

    img

    1
    2
    3
    cd /usr/local/php
    cp etc/php-fpm.conf.default etc/php-fpm.conf
    ./sbin/php-fpm
  5. 配置nginx

1
vi /usr/local/nginx/conf/nginx.conf

拿掉下面语句的注释,修改圈出来的部分

img

1
vi /usr/local/nginx/html/test.php

见我的github config-blog/test.php

1
nginx -s reload

打开 ip/test.php

image-20181129180839744