LNMP环境部署

简介:

1 安装nginx

1.1 安装nginx相关包

1
2
yum  install  -y http: //nginx .org /packages/centos/7/noarch/RPMS/nginx-release-centos-7-0 .el7.ngx.noarch.rpm
yum  install  -y nginx

1.2 创建项目目录

1
mkdir  -p  /var/www/www .cmdschool.org

1.3 配置http和https服务

http config:

1
2
cp  /etc/nginx/conf .d /default .conf  /etc/nginx/conf .d /www .cmdschool.org_80.conf
vim  /etc/nginx/conf .d /www .cmdschool.org_80.conf

保留以下内容:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
server {
     listen       80;
     server_name  www.cmdschool.org;
 
     location / {
         root    /var/www/www .cmdschool.org;
         index  index.html index.htm  index.php;
     }
 
     error_page   500 502 503 504   /50x .html;
     location =  /50x .html {
         root    /usr/share/nginx/html ;
     }
}

https config:

1
2
cp  /etc/nginx/conf .d /default .conf  /etc/nginx/conf .d /www .cmdschool.org_443.conf
vim  /etc/nginx/conf .d /www .cmdschool.org_443.conf

确认存在如下内容:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
server {
     listen       443;
     server_name  www.cmdschool.org;
     ssl on;
     ssl_certificate 1_www.cmdschool.org_bundle.crt;
     ssl_certificate_key 2_www.cmdschool.org.key;
     ssl_session_timeout 5m;
     ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
     ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
     ssl_prefer_server_ciphers on;
 
     location / {
         root    /var/www/www .cmdschool.org;
         index  index.html index.htm  index.php;
     }
 
     error_page   500 502 503 504   /50x .html;
     location =  /50x .html {
         root    /usr/share/nginx/html ;
     }
}

添加静态测试页面:

1
2
mkdir  -p  /var/www/www .cmdschool.org
echo  www.cmdschool.org >  /var/www/www .cmdschool.org /index .html

1.4 配置nginx服务

1
2
systemctl  enable  nginx
systemctl restart nginx

1.5 配置防火墙

1
2
3
4
firewall-cmd --permanent --add-service http
firewall-cmd --permanent --add-service https
firewall-cmd --reload
firewall-cmd --list-all

1.6 关闭selinux

1
2
sed  -i  's/SELINUX=enforcing/SELINUX=disabled/g'  /etc/selinux/config
setenforce 0

2 集成PHP fastCGI

2.1 安装基础软件包

1
yum  install  -y php-fpm php

2.2 启动并配置服务自启动

1
2
systemctl  enable  php-fpm.service
systemctl start php-fpm.service

2.3 配置集成php fastCGI

1
vim  /etc/nginx/conf .d /www .cmdschool.org_80.conf

或

1
vim  /etc/nginx/conf .d /www .cmdschool.org_443.conf

增加如下代码

1
2
3
4
5
6
7
8
9
10
server {
     [...]
     location ~ \.php$ {
         root            /var/www/www .cmdschool.org;
         fastcgi_pass   127.0.0.1:9000;
         fastcgi_index  index.php;
         fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
         include         /etc/nginx/fastcgi_params ;
     }
}

重启nginx服务

1
systemctl restart nginx

2.4 测试php fastCGI

添加调试代码

1
echo  '<?php phpinfo(); ?>'  >  /var/www/www .cmdschool.org /index .php

访问以下链接测试fastCGI

1
2
http: //www .cmdschool.org /index .php
https: //www .cmdschool.org /index .php

2.5 如下日志可以协助你排错

1
2
tail  -f  /var/log/nginx/error .log
tail  -f  /var/log/php-fpm/error .log

2.6 安装辅助工具包

1
yum  install  -y unzip

3 配置MariaDB数据库

3.1 安装MariaDB相关包

1
yum  install  -y mariadb-server mariadb-devel mariadb

3.2 启动MariaDB服务并配置自启动

1
2
systemctl start mariadb.service
systemctl  enable  mariadb.service

3.3 初始化MariaDB

1
mysql_secure_installation

向导如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
[...]
Set root password? [Y /n ] y
New password:
Re-enter new password:
[...]
Remove anonymous  users ? [Y /n ] y
[...]
Disallow root login remotely? [Y /n ] y
[...]
Remove  test  database and access to it? [Y /n ] y
[...]
Reload privilege tables now? [Y /n ] y
[...]









本文转自 tanzhenchao 51CTO博客,原文链接:http://blog.51cto.com/cmdschool/1962061,如需转载请自行联系原作者
目录
相关文章
|
关系型数据库 MySQL 应用服务中间件
LNMP详解(四)——LNMP原理与简单部署
LNMP详解(四)——LNMP原理与简单部署
614 2
|
关系型数据库 应用服务中间件 nginx
基于Docker的LNMP环境微服务搭建
基于Docker的LNMP环境微服务搭建
基于Docker的LNMP环境微服务搭建
|
关系型数据库 MySQL 应用服务中间件
Linux 手动安装快速部署 LNMP 环境实战
本文详细记录了在阿里云ECS上手动搭建LNMP环境的过程,系统选用Ubuntu 24.04。主要内容包括:1) 使用`apt`安装Nginx和MySQL,并更新软件源;2) 编译安装PHP 8.4.5,配置PHP-FPM及环境路径;3) 配置MySQL root用户密码;4) 调整Nginx支持PHP解析并测试整体环境。通过此过程,重现手动配置服务器的细节,帮助熟悉各组件的安装与协同工作。
1316 23
|
关系型数据库 应用服务中间件 Linux
Linux云服务器如何搭建LNMP环境
LNMP环境是Linux系统中常用的Web服务架构,由Linux、Nginx、MySQL/MariaDB和PHP组成,适用于高效托管动态网站。本文以CentOS 7为例,详细介绍了LNMP环境的搭建步骤,包括Nginx、MariaDB和PHP的安装与配置,以及最终通过创建`index.php`文件验证环境是否成功部署。具体操作涵盖配置YUM仓库、安装服务、编辑配置文件、启动服务等关键步骤,确保用户能够顺利搭建并运行LNMP环境。
657 1
Linux云服务器如何搭建LNMP环境
|
关系型数据库 MySQL 应用服务中间件
Nginx__高级进阶篇之LNMP动态网站环境部署
Nginx__高级进阶篇之LNMP动态网站环境部署
683 0
|
弹性计算 关系型数据库 MySQL
一键部署LNMP(源码安装版本)
【4月更文挑战第29天】
429 2
|
弹性计算 关系型数据库 Shell
一键部署LNMP(RPM 包版本)
【4月更文挑战第29天】
427 0
|
API PHP 数据库
Docker六脉神剑(四) 使用Docker-Compose进行服务编排搭建lnmp环境
Docker六脉神剑(四) 使用Docker-Compose进行服务编排搭建lnmp环境
293 0
|
关系型数据库 MySQL 应用服务中间件
小白带你部署LNMP分布式部署
小白带你部署LNMP分布式部署
692 0
|
关系型数据库 MySQL Linux
Linux环境下LNMP架构实战案例
Linux环境下LNMP架构实战案例
368 0