前言
本文主要介绍的是基于centos7进行yum安装lnmp(linux+nginx+php7.1+mysql5.7)的相关教程,文中将一步步介绍的非常详细,下面话不多说了,来一起看看详细的介绍吧。
步骤如下:

yum的安装

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

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

service mysqld start

检查mysql启动是否正常

service mysqld status 或者 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

使用查询得到的随机密码在终端登录

mysql -u root -p 更改密码(mysql文档规定,密码必须包括大小写字母数字加特殊符号>8位)
ALTER USER 'root'@'localhost' IDENTIFIED BY 'Yourpassword';

退出mysql客户端,用刚才修改的密码登录确保密码修改成功

exit;
mysql -u root -p

安装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

service php-fpm star

检查启动是否成功

service php-fpm status

设置开机自启动

systemctl enable php-fpm.service

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

systemctl list-dependencies | grep php-fpm
ps -ef | grep php-fpm

nginx 配置文件详情

#启动子进程程序默认用户
#user  nobody;
#一个主进程和多个工作进程。工作进程是单进程的,且不需要特殊授权即可运行;这里定义的是工作进程数量
worker_processes  1;

#全局错误日志的位置及日志格式
#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    #每个工作进程最大的并发数
    worker_connections  1024;
}


#http服务器设置
http {
    #设定mime类型,类型由mime.type文件定义
    include       mime.types;
    
    #
    default_type  application/octet-stream;

    #日志格式
    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';
    #$remote_addr与$http_x_forwarded_for用以记录客户端的ip地址;
    #$remote_user:用来记录客户端用户名称;
    #$time_local: 用来记录访问时间与时区;
    #$request: 用来记录请求的url与http协议;
    #$status: 用来记录请求状态;成功是200,
    #$body_bytes_sent :记录发送给客户端文件主体内容大小;
    #$http_referer:用来记录从那个页面链接访问过来的;
    #$http_user_agent:记录客户浏览器的相关信息;

    #全局访问日志路径 
    #access_log  logs/access.log  main;
    #sendfile指令指定 nginx 是否调用sendfile 函数(zero copy 方式)来输出文件,对于普通应用,必须设为on。如果用来进行下载等应用磁盘IO重负载应用,可设置为off,以平衡磁盘与网络IO处理速度,降低系统uptime。
    sendfile        on;
    
    #此选项允许或禁止使用socke的TCP_CORK的选项,此选项仅在使用sendfile的时候使用
    #tcp_nopush     on;

    #长连接超时时间
    #keepalive_timeout  0;
    keepalive_timeout  65;

    #开启压缩
    #gzip  on;

    #配置虚拟主机 一个server一个网站
    server {
        #虚拟主机使用的端口
        listen       80;
        #虚拟主机域名
        server_name  localhost;

        #虚拟主机支持的字符集
        #charset koi8-r;

        #虚拟主机的访问日志路径
        #access_log  logs/host.access.log  main;

        #定义web根路径
        location / {
            #根目录路径
            root   html;
            #索引页
            index  index.html index.htm;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #

        #根据错误码 返回对应的页面
        error_page   500 502 503 504  /50x.html;

        #定义页面路径
        location = /50x.html {
            root   html;
        }

        #定义反向代理服务器 数据服务器是lamp模型
        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}


        #定义PHP为本机服务的模型  
        # 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;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #拒绝apache DR目录及子目录下的.htaccess文件访问
        #location ~ /\.ht {
        #    deny  all;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

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


    #https的配置方案
    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

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

}

vhosts.conf
server{

listen  80;
server_name www.ixiaocui.com;
index index.html index.php;
root /home/wwwroot/blog;
#charset koi8-r;
access_log logs/ixiaocui.com.log main;
error_log  logs/ixiaocui.com.error.log;

error_page 404    /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
    root html;
}
# Rewirte
location / {
    index index.html index.php;
    if (-f $request_filename/index.html){
        rewrite (.*) $1/index.html break;
    }
    if (-f $request_filename/index.php){
        rewrite (.*) $1/index.php;
    }
    if (!-f $request_filename){
        rewrite (.*) /index.php;
    }
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
    root   /home/wwwroot/blog;
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include  fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /.ht {
    deny all;
}

}

标签: none

评论已关闭