基于centos7进行yum安装lnmp(linux+nginx+php7.1+mysql5.7)的相关教程

yum的安装

 

1

yum update  //可以不执行

yum安装nginx

安装nginx最新源

yum localinstall http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

yum repolist enabled | grep "nginx*"

安装nginx

yum -y install nginx

启动nginx

systemctl start nginx.service  or  service nginx start

设置nginx服务器开机自启动

systemctl enable nginx.service

检查开机自动是否设置成功

systemctl list-dependencies | grep nginx

浏览器中输入公网ip,检测是否安装成功

http://00.00.00.00/

使用yum安装mysql5.7

安装mysql源

yum -y localinstall http://dev.mysql.com/get/mysql57-community-release-el7-7.noarch.rpm

yum repolist enabled | grep "mysql.*-community.*"

安装mysql

yum -y install mysql-community-server install mysql-community-devel

启动mysql

 systemctl start mysqld.service   or   service mysqld start

检查mysql启动是否正常

systemctl status mysqld.service  or  service mysqld status  or  ps -ef | grep mysql

设置mysqld服务开机自启动

systemctl enable mysqld.service

检查mysqld开机自启动是否设置成功

systemctl list-dependencies | grep mysqld

 

mysql5.7以后的增强了安全机制, 所以使用yum安装,启动会系统会自动生成一个随机的密码,修改mysql密码

查看mysql的随机密码

运行:grep 'temporary password' /var/log/mysqld.log

结果:2017-06-12T10:30:25.313367Z 1 [Note] A temporary password is generated for root@localhost: 7hp<_l(&jlkN(红色表示随机的密码)

使用查询得到的随机密码在终端登录(临时密码使用实例):

mysql -u root -p 更改密码(mysql文档规定,密码必须包括大小写字母数字加特殊符号>8位)

ALTER USER 'root'@'localhost' IDENTIFIED BY 'Yourpassword';

如遇如下问题:

> SET PASSWORD = PASSWORD('your new password');
以上语句如果密码简单会报如下错误:
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
需要修改validate_password_policy的值为0就可以了
> set global validate_password_policy=0;

在执行:

SET PASSWORD = PASSWORD('your new password');

flush privileges;

quit or exit;

安装php7.1

安装php源

rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

检查源是否安装成功

yum repolist enabled | grep "webtatic*"

安装PHP扩展源

yum -y install php71w php71w-fpm

yum -y install php71w-mbstring php71w-common php71w-gd php71w-mcrypt

yum -y install php71w-mysql php71w-xml php71w-cli php71w-devel

yum -y install php71w-pecl-memcached php71w-pecl-redis php71w-opcache

验证php7.1.x和扩展是否安装成功 

验证php是否安装成功

php -v

验证对应的扩展是否安装成功

php -m

设置php-fpm并检测php-fpm的运行状态

启动php-fpm
systemctl start php-fpm.service   or   service php-fpm start

检查启动是否成功

systemctl status php-fpm.service   or   service php-fpm status

设置开机自启动

systemctl enable php-fpm.service 

检查开机自启动是否设置成功

systemctl list-dependencies | grep php-fpm

ps -ef | grep php-fpm

nginx配置如下:

nginx.conf配置:

# For more information on configuration, see:
#   * Official English Documentation: http://nginx.org/en/docs/
#   * Official Russian Documentation: http://nginx.org/ru/docs/

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
}

http {
    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  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;

    server {
        listen       80 default_server;
        listen       [::]:80 default_server;
        server_name  _;
        root         /usr/share/nginx/html/;
        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        location / {
        }

        error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
    }

}

配置自己的项目文件夹(laravel或tp5)

/etc/nginx/conf.d/*.conf

server {
    listen     80;
    server_name app.ahyzyx.cn;
    root        /usr/share/nginx/html/itmanager/public;
    index       index.php; 

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    error_page  404    /404.html;
        location = /404.html {
    }

    error_page  500 502 503 504    /50x.html;
        location = /50x.html {
    }

    location ~ \.php$ {
        try_files        $uri /index.php = 404;
        fastcgi_pass     127.0.0.1:9000;
        fastcgi_index    index.php;
        fastcgi_param    SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include          fastcgi_params;
    }
}

配置自己的项目文件夹(tp5以下)

/etc/nginx/conf.d/*.conf

server {
    listen     8082;
    server_name 127.0.0.1 192.168.17.134;
    root        /usr/share/nginx/html/hanteng;
    index       index.php index.html; 

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    error_page  404    /404.html;
        location = /404.html {
    }

    error_page  500 502 503 504    /50x.html;
        location = /50x.html {
    }

    location ~ \.php/?.*$ {
        root        /usr/share/nginx/html/hanteng;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        #加载Nginx默认"服务器环境变量"配置
        include        fastcgi_params;
        
        #设置PATH_INFO并改写SCRIPT_FILENAME,SCRIPT_NAME服务器环境变量
        set $fastcgi_script_name2 $fastcgi_script_name;
        if ($fastcgi_script_name ~ "^(.+\.php)(/.+)$") {
            set $fastcgi_script_name2 $1;
            set $path_info $2;
        }
        fastcgi_param   PATH_INFO $path_info;
        fastcgi_param   SCRIPT_FILENAME   $document_root$fastcgi_script_name2;
        fastcgi_param   SCRIPT_NAME   $fastcgi_script_name2;
    }
}

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值