博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
lnmp部署
阅读量:2134 次
发布时间:2019-04-30

本文共 4666 字,大约阅读时间需要 15 分钟。

lnmp部署

文章目录

安装nginx

#关闭防火墙和selinx[root@localhost ~]# systemctl disable firewalld[root@localhost ~]# vim /etc/selinux/configSELINUX=disabled#创建系统用户nginx[root@localhost ~]# useradd -r -M -s /sbin/nologin nginx#安装依赖环境[root@localhost ~]# yum -y install pcre-devel openssl openssl-devel gd-devel gcc gcc-c++ make#安装过程略....[root@localhost ~]# yum -y groups mark install 'Development Tools'#创建日志存放目录[root@localhost ~]# mkdir -p /var/log/nginx[root@localhost ~]# chown -R nginx.nginx /var/log/nginx#下载nginx[root@localhost ~]# wget https://nginx.org/download/nginx-1.20.1.tar.gz[root@localhost ~]# lsanaconda-ks.cfg  nginx-1.20.1.tar.gz

编译安装

[root@localhost ~]# tar xf nginx-1.20.1.tar.gz [root@localhost ~]# lsanaconda-ks.cfg  nginx-1.20.1  nginx-1.20.1.tar.gz[root@localhost ~]# cd nginx-1.20.1[root@localhost nginx-1.20.1]# ./configure \> --prefix=/usr/local/nginx \> --user=nginx \> --group=nginx \> --with-debug \> --with-http_ssl_module \> --with-http_realip_module \> --with-http_image_filter_module \> --with-http_gunzip_module \> --with-http_gzip_static_module \> --with-http_stub_status_module \> --http-log-path=/var/log/nginx/access.log \> --error-log-path=/var/log/nginx/error.log[root@localhost nginx-1.20.1]# make[root@localhost nginx-1.20.1]# make install

nginx安装后配置

#配置环境变量[root@localhost ~]# echo 'export PATH=/usr/local/nginx/sbin:$PATH' > /etc/profile.d/nginx.sh[root@localhost ~]# source /etc/profile.d/nginx.sh//服务控制方式,使用nginx命令    -t  //检查配置文件语法    -v  //输出nginx的版本    -c  //指定配置文件的路径    -s  //发送服务控制信号,可选值有{
stop|quit|reopen|reload}#输出nginx的版本[root@localhost ~]# nginx -vnginx version: nginx/1.20.1#查看nginx有那些功能[root@localhost ~]# nginx -Vnginx version: nginx/1.20.1built by gcc 8.5.0 20210514 (Red Hat 8.5.0-2) (GCC) built with OpenSSL 1.1.1k FIPS 25 Mar 2021TLS SNI support enabledconfigure arguments: --prefix=/usr/local/nginx --user=nginx --group=nginx --with-debug --with-http_ssl_module --with-http_realip_module --with-http_image_filter_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_stub_status_module --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log#检查配置文件[root@localhost ~]# nginx -tnginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is oknginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful[root@localhost ~]# nginx [root@localhost ~]# ss -antlState Recv-Q Send-Q Local Address:Port Peer Address:Port Process LISTEN 0 128 0.0.0.0:80 0.0.0.0:* LISTEN 0 128 0.0.0.0:22 0.0.0.0:* LISTEN 0 128 [::]:22 [::]:*

在这里插入图片描述

安装mysql

安装php

运行以下命令添加并更新epel源

[root@localhost ~]# dnf -y install epel-release[root@localhost ~]# dnf update epel-release

运行以下命令删除缓存的无用软件包并更新软件源。

[root@localhost ~]# dnf clean all[root@localhost ~]# dnf makecache

启用php:7.3模块

[root@localhost ~]# dnf module enable php:7.3

运行以下命令安装PHP相应的模块

[root@localhost ~]# dnf install php php-curl php-dom php-exif php-fileinfo php-fpm php-gd php-hash php-json php-mbstring php-mysqli php-openssl php-pcre php-xml libsodium#安装过程省略#查看PHP版本[root@localhost ~]# php -vPHP 7.3.20 (cli) (built: Jul  7 2020 07:53:49) ( NTS )Copyright (c) 1997-2018 The PHP GroupZend Engine v3.3.20, Copyright (c) 1998-2018 Zend Technologies

配置Nginx

[root@localhost ~]# vi /usr/local/nginx/conf/nginx.conflocation / {
root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; #添加默认首页信息index.php。 index index.html index.htm index.php; }#去掉被注释的location ~ \.php$大括号内容前的#,并修改大括号的内容。修改完成如下所示location ~ \.php$ {
proxy_pass http://127.0.0.1; root /usr/local/nginx/html; #Nginx通过unix套接字与PHP-FPM建立联系,该配置与/etc/php-fpm.d/www.conf文件内的listen配置一致。 fastcgi_pass unix:/run/php-fpm/www.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; #Nginx调用fastcgi接口处理PHP请求。 include fastcgi_params; }[root@localhost ~]# nginx -s stop[root@localhost ~]# nginx

配置PHP

[root@localhost ~]# vim /etc/php-fpm.d/www.conf#找到user = apache和group = apache,将apache修改为nginxuser = nginx; RPM: Keep a group allowed to write in log dir.group = nginx#新建phpinfo.php文件,用于展示PHP信息[root@localhost ~]# vim /usr/local/nginx/html/phpinfo.php#输入下列内容,函数phpinfo()​会展示PHP的所有配置信息。
#运行以下命令启动PHP-FPM[root@localhost ~]# systemctl start php-fpm#运行以下命令设置PHP-FPM开机自启动[root@localhost ~]# systemctl enable php-fpm

测试访问LNMP平台

在本地物理机打开浏览器,

在地址栏输入http://<ECS实例公网IP地址>/phpinfo.php

返回结果如下图所示,表示LNMP环境部署成功。

在这里插入图片描述

转载地址:http://qvugf.baihongyu.com/

你可能感兴趣的文章
linux之CentOS下文件解压方式
查看>>
Django字段的创建并连接MYSQL
查看>>
div标签布局的使用
查看>>
HTML中表格的使用
查看>>
(模板 重要)Tarjan算法解决LCA问题(PAT 1151 LCA in a Binary Tree)
查看>>
(PAT 1154) Vertex Coloring (图的广度优先遍历)
查看>>
(PAT 1115) Counting Nodes in a BST (二叉查找树-统计指定层元素个数)
查看>>
(PAT 1143) Lowest Common Ancestor (二叉查找树的LCA)
查看>>
(PAT 1061) Dating (字符串处理)
查看>>
(PAT 1118) Birds in Forest (并查集)
查看>>
数据结构 拓扑排序
查看>>
(PAT 1040) Longest Symmetric String (DP-最长回文子串)
查看>>
(PAT 1145) Hashing - Average Search Time (哈希表冲突处理)
查看>>
(1129) Recommendation System 排序
查看>>
PAT1090 Highest Price in Supply Chain 树DFS
查看>>
(PAT 1096) Consecutive Factors (质因子分解)
查看>>
(PAT 1019) General Palindromic Number (进制转换)
查看>>
(PAT 1073) Scientific Notation (字符串模拟题)
查看>>
(PAT 1080) Graduate Admission (排序)
查看>>
Play on Words UVA - 10129 (欧拉路径)
查看>>