欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

CentOS7搭建LNMP

程序员文章站 2022-12-08 19:27:49
一、安装nginx 1、yum安装nginx yum -y install nginx 2、检查nginx的状态,开启nginx和开机自启 (1)检查nginx的状态 systemctl status nginx (2)启动nginx systemctl start nginx (3)开机自启ngi ......

一、安装nginx

1、yum安装nginx

  yum -y install nginx

2、检查nginx的状态,开启nginx和开机自启

  (1)检查nginx的状态

    systemctl status nginx

  (2)启动nginx

    systemctl start nginx

  (3)开机自启nginx

    systemctl enable nginx

3、配置nginx访问日志(可不配置)

  (1)创建存放目录

    mkdir -p /www/app/nginx/log/access/

    mkdir -p /www/app/nginx/log/error/

    chmod 777 -r /www

  (2)配置nginx日志格式(找到左边的字段,修改右边信息)

    

vim /etc/nginx/nginx.conf

error_log /www/app/nginx/log/error/error.log; log_format main '"$server_name" "$server_addr:$server_port" "$remote_addr" "$time_local" "$request_method" "$request_uri" "$server_protocol" "$status" "$request_time" "$bytes_sent" "$body_bytes_sent" "$http_range" "$http_referer" "$http_user_agent" "$request_body" "$request_completion"'; access_log /www/app/nginx/log/access/access.log main;

  CentOS7搭建LNMP

 

 

  

二、安装mysql5.7

   1、下载yum repository,然后安装(大概25k左右)

    mkdir /download 

    cd /download/

    wget http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm

    yum -y install mysql57-community-release-el7-10.noarch.rpm

  2、安装mysql5.7

    yum -y install mysql-community-server

  3、启动mysql,以及开机自启

    启动

      systemctl start mysqld

    开机自启

      systemctl enable mysqld

  4、修改密码

    (1)获取初始密码

      cat /var/log/mysqld.log |grep password

      CentOS7搭建LNMP

 

 

    (2)登录(用上面的密码)

      mysql -uroot -p

    (3)修改密码

      alter user 'root'@'localhost' identified by '123456';

      CentOS7搭建LNMP

 

       密码太多简单,不符合策略,则使用复杂一点的密码

      alter user 'root'@'localhost' identified by '123456abc#';

    (4)、若是密码过于复杂,难记,则修改密码策略,再修改一个简单的密码(正式环境不建议使用)

      修改策略

        set global validate_password_length=4;

        set global validate_password_policy=0;

      查看策略

        show variables like 'validate_password%';

        CentOS7搭建LNMP

 

 

      修改密码

        alter user 'root'@'localhost' identified by '123456';

 

 

 

 

三、安装php7.2

  1、下载php7.2(19m左右)

    cd /download

    wget https://www.php.net/distributions/php-7.2.24.tar.gz

    解压

    tar zxvf php-7.2.24.tar.gz

    cd php-7.2.24

  2、安装依赖组件

    

yum -y install gcc gcc-c++ libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel ncurses curl gdbm-devel db4-devel libxpm-devel libx11-devel gd-devel gmp-devel expat-devel xmlrpc-c xmlrpc-c-devel libicu-devel libmcrypt-devel libmemcached-devel

   3、编译安装

./configure \
--prefix=/usr/local/php \
--with-config-file-path=/etc \
--enable-fpm \
--with-fpm-user=nginx  \
--with-fpm-group=nginx \
--enable-inline-optimization \
--disable-debug \
--disable-rpath \
--enable-shared  \
--enable-soap \
--with-libxml-dir \
--with-xmlrpc \
--with-openssl \
--with-mhash \
--with-pcre-regex \
--with-sqlite3 \
--with-zlib \
--enable-bcmath \
--with-iconv \
--with-bz2 \
--enable-calendar \
--with-curl \
--with-cdb \
--enable-dom \
--enable-exif \
--enable-fileinfo \
--enable-filter \
--with-pcre-dir \
--enable-ftp \
--with-gd \
--with-openssl-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib-dir  \
--with-freetype-dir \
--enable-gd-jis-conv \
--with-gettext \
--with-gmp \
--with-mhash \
--enable-json \
--enable-mbstring \
--enable-mbregex \
--enable-mbregex-backtrack \
--with-libmbfl \
--with-onig \
--enable-pdo \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-zlib-dir \
--with-pdo-sqlite \
--with-readline \
--enable-session \
--enable-shmop \
--enable-simplexml \
--enable-sockets  \
--enable-sysvmsg \
--enable-sysvsem \
--enable-sysvshm \
--enable-wddx \
--with-libxml-dir \
--with-xsl \
--enable-zip \
--enable-mysqlnd-compression-support \
--with-pear \
--enable-opcache

 

  4、make && make install

  5、拷贝php.ini

    cp /download/php-7.2.24/php.ini-development /etc/php.ini

  6、php-fpm的配置与使用

    (1)复制php-fpm.conf

      cd /usr/local/php/etc/

      cp php-fpm.conf.default php-fpm.conf

    (2)复制www.conf

      cd /usr/local/php/etc/php-fpm.d

      cp www.conf.default www.conf

    (3)php-fpm系统服务

      vi /etc/systemd/system/php-fpm.service

[unit]

description=php-fpm

after=network.target

[service]

type=forking

execstart=/usr/local/php/sbin/php-fpm

privatetmp=true

[install]

wantedby=multi-user.target

  

    (4)启动php-fpm跟开机自启

      systemctl start php-fpm

      systemctl enable php-fpm

      CentOS7搭建LNMP