温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

怎么搭建和部署LNMP平台环境

发布时间:2021-11-15 11:59:36 来源:亿速云 阅读:172 作者:iii 栏目:大数据

这篇文章主要讲解了“怎么搭建和部署LNMP平台环境”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“怎么搭建和部署LNMP平台环境”吧!

一、什么是LNMP

LNMP是指一组通常一起使用来运行动态网站或者服务器的自由软件名称首字母缩写。L指Linux,N指Nginx,M一般指MySQL,也可以指MariaDB,P一般指PHP,也可以指Perl或Python。

LNMP代表的就是:Linux系统下Nginx+MySQL+PHP这种网站服务器架构。

Linux是一类Unix计算机操作系统的统称,是目前最流行的免费操作系统。代表版本有:debian、centos、ubuntu、fedora、gentoo等;

Nginx是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP代理服务器;

Mysql是一个小型关系型数据库管理系统。在Linux上为MariaDB;

PHP是一种在服务器端执行的嵌入HTML文档的脚本语言;

这四种软件均为免费开源软件,组合到一起,成为一个免费、高效、扩展性强的网站服务系统。

二、部署LNMP环境

总体流程

1.安装部署Nginx、MariaDB、PHP、PHP-FPM;

2.启动Nginx、MariaDB、FPM服务;

3.测试LNMP是否工作正常工作。

所需软件包

1.Nginx:nginx-1.17.4

2.MySQL:mariadb、mariadb-server、mariadb-devel

3.PHP:php、php-fpm、php-mysql

说明:mariadb(数据库客户端软件)、mariadb-server(数据库服务器软件)、mariadb-devel(其他客户端软件的依赖包)、php(解释器)、php-fpm(进程管理器服务)、php-mysql(PHP的数据库扩展包)

使用yum的方式安装所有需要的软件包,Nginx我们采用编译安装

[root@centos7~]# yum -y install php php-mysql php-fpm

[root@centos7~]# system restart php-fpm

[root@centos7~]# system enable php-fpm

[root@centos7~]# yum -y install mariadb mariadb-server mariadb-devel

[root@centos7~]#systemctl restart mariadb

[root@centos7~]#systemctl enable mariadb

[root@centos7~]#wget http://nginx.org/download/nginx-1.17.4.tar.gz

[root@centos7~]# useradd -s /sbin/nologin nginx

[root@centos7~]# tar -xvf nginx-1.17.4.tar.gz

[root@centos7~]# cd nginx-1.17.4

[root@centos7 nginx-1.17.4]# ./configure  --user=nginx --group=nginx --with-http_ssl_module    //编译安装包

[root@centos7~]# make && make install

[root@centos7~]#/usr/local/nginx/sbin/nginx

[root@centos7~]#ln -s /usr/local/nginx/sbin/nginx

[root@centos7~]#nginx -s reload

[root@centos7~]#yum -y install php php-mysql php-fpm    //安装PHP-FPM

[root@centos7~]# system restart php-fpm

[root@centos7~]#system enable php-fpm

[root@centos7~]#yum -y install mariadb mariadb-server mariadb-devel    //安装MySQL

[root@centos7~]#systemctl restart mariadb 

[root@centos7~]#systemctl enable mariadb

#########至此,所有的软件包全部安装完毕###########

三、平台的搭建和配置

1.配置PHP

怎么搭建和部署LNMP平台环境

配置Fast-CGI支持PHP网页,测试PHP连接数据库是否成功

root@centos7 ~]# vim /usr/local/nginx/html/test.php

<?php $i="hello"; echo $i; ?>

2.修改Nginx配置文件并启动服务

[root@centos7 ~]# vim /usr/local/nginx/conf/nginx.conf    //这里只保留使用的部分配置

user  nginx nginx;
worker_processes  1;

error_log  logs/error.log;
error_log  logs/error.log  notice;

pid        logs/nginx.pid;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;
    access_log  logs/access.log  main;
    sendfile        on;
    keepalive_timeout  65;

    server {
        listen       80;
        server_name  www.cc.com;
        
        location / {
            root   html;
            index  index.php index.html index.htm;
        }
        return      301 https://$server_name$request_uri;    //设置强制跳转HTTPS方式访问
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
        
    }
    # HTTPS server        //开启https服务

    server {
        listen       443 ssl;
        server_name  www.cc.com;

        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;
        }

#配置php
         location ~ \.php$ {            
            root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include        fastcgi.conf;
        }

    }

}

[root@centos7 ~]# nginx -s reload    //重启一下nginx

本地绑定hosts文件访问测试php页面

怎么搭建和部署LNMP平台环境

感谢各位的阅读,以上就是“怎么搭建和部署LNMP平台环境”的内容了,经过本文的学习后,相信大家对怎么搭建和部署LNMP平台环境这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是亿速云,小编将为大家推送更多相关知识点的文章,欢迎关注!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI