LNMP环境搭建

作者: e20d9310ced3 | 来源:发表于2018-04-11 08:48 被阅读0次

    操作系统:CentOS 7

    YUM安装Mysql

    1. 添加mysql YUM源

    # wget https://repo.mysql.com//mysql57-community-release-el7-10.noarch.rpm
    # rpm -Uvh mysql57-community-release-el7-10.noarch.rpm

    1. 安装mysql

    # yum -y install mysql-community-server

    1. 启动mysql并添加开机启动

    # systemctl start mysqld
    # systemctl enable mysqld

    1. 登录mysql并修改密码
      默认设置了‘root'@'localhost'的登录密码,把它找出来

    # grep 'temporary password' /var/log/mysqld.log

    2017-04-25T12:43:52.287512Z 1 [Note] A temporary password is generated for root@localhost: J:!kujwh1o9y
    所以默认的临时密码为J:!kujwh1o9y

    > mysql -uroot -p
    > ALTER USER 'root'@'localhost' IDENTIFIED BY 'XXXX';

    安装Nginx

    1.先安装pcre

    # wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.41.tar.gz
    # tar -zxf pcre-8.41.tar.gz && cd pcre-8.41 && ./configure --prefix=/usr/local/pcre && make && make install

    1. 创建用户www

    # groupadd www
    # useradd -g www www -s /sbin/nologin -M

    1. 下载nginx安装包

    # wget http://nginx.org/download/nginx-1.12.2.tar.gz

    1. 解压并安装

    # tar -zxf nginx-1.12.2.tar.gz && cd nginx-1.12.2
    # ./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_ssl_module --with-http_stub_status_module --with-file-aio --with-http_dav_module --with-pcre=/root/pcre-8.41
    # make && make install

    PS:这里的--with-pcre是pcre源码的目录,不是安装目录
    4.启动nginx

    # ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/nginx
    # nginx

    安装php

    1.安装依赖包
    依赖包列表
    mysql-devel
    openssl-devel
    swig
    libjpeg-turbo
    libjpeg-turbo-devel
    libpng
    libpng-devel
    freetype
    freetype-devel
    libxml2
    libxml2-devel
    zlib
    zlib-devel
    libcurl
    libcurl-devel
    m4
    autoconf
    openldap
    openldap-devel

    # yum -y install mysql-devel openssl-devel swig libjpeg-turbo libjpeg-turbo-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel libcurl libcurl-devel m4 autoconf openldap openldap-devel

    1. 下载并安装

    # wget http://cn2.php.net/distributions/php-5.6.35.tar.gz && tar -zxf php-5.6.35.tar.gz && cd php-5.6.35
    # ./configure --prefix=/usr/local/php-fastcgi --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-mysql=mysqlnd --with-jpeg-dir --with-png-dir --with-zlib --enable-xml --with-libxml-dir --with-curl --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --enable-mbregex --with-openssl --enable-mbstring --with-gd --enable-gd-native-ttf --with-freetype-dir=/usr/lib64 --with-gettext=/usr/lib64 --enable-sockets --with-xmlrpc --enable-zip --enable-soap --disable-debug --enable-opcache --with-config-file-path=/usr/local/php-fastcgi/etc --enable-fpm --with-fpm-user=www --with-fpm-group=www
    # make && make install

    1. 安装pdo-plugin

    # cd ./ext/pdo_mysql
    # /usr/local/php-fastcgi/bin/phpize
    # ./configure --with-php-config=/usr/local/php-fastcgi/bin/php-config && make && make install

    1. 拷贝php.ini文件

    # cp /root/php-5.6.35/php.ini-production /usr/local/php-fastcgi/etc/php.ini

    1. 拷贝php-fpm文件

    # cp /usr/local/php-fastcgi/etc/php-fpm.conf.default /usr/local/php-fastcgi/etc/php-fpm.conf

    1. 把php-fpm做成服务,并开机启动

    # cp /root/php-5.6.35/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
    # chmod +x /etc/init.d/php-fpm
    # systemctl enable php-fpm

    1. 启动php

    # /etc/init.d/php-fpm start

    修改nginx.conf

    在index中加入index.php

            location / {
                root   html;
                index  index.html index.htm index.php;
            }
    

    去掉php-fastcgi这部分注释,并将/scriptsfastcgi_script_name修改成document_root$fastcgi_script_name

            # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
            #
            location ~ \.php$ {
                root           html;
                fastcgi_pass   127.0.0.1:9000;
                fastcgi_index  index.php;
                #fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
                fastcgi_param  SCRIPT_FILENAME   $document_root$fastcgi_script_name;
                include        fastcgi_params;
            }
    

    重启nginx
    到此LNMP环境搭建成功
    测试
    在/usr/local/nginx/html下新建文件phpinfo.php
    vim phpinfo.php

    <?php
        phpinfo();
    ?>
    

    在浏览器中打开IP/phpinfo.php

    相关文章

      网友评论

        本文标题:LNMP环境搭建

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