前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >CentOS LNMP (Linux+Nginx+MariaDB+PHP)

CentOS LNMP (Linux+Nginx+MariaDB+PHP)

作者头像
iOSDevLog
发布2019-11-27 22:45:22
1.1K0
发布2019-11-27 22:45:22
举报
文章被收录于专栏:iOSDevLogiOSDevLog
  • Nginx( engIne x)是一个高性能的 Web 和反向代理服务器
  • NginX支持 HTTP、Https 和电子邮件代理协议
  • OpenResty 是基于 Nginx 和 Lua实现的 web 应用网关,集成了大量的第三方模块

OpenResty 的下载和安装

代码语言:javascript
复制
yum-config-manager --add-repo https://openresty.org/package/centos/openresty.repo
yum install openresty

安装目录: /usr/local/openresty/ html 目录:/usr/local/openresty/nginx/html

OpenResty 配置文件

/usr/local/openresty/nginx/conf/nginx.conf

代码语言:javascript
复制
service openresty start | stop | restart | reload

openresty.png

虚拟主机

代码语言:javascript
复制
    server {
        listen       8000;
        listen       www.servera.com;
        server_name  servera;
        
        location / {
            root   html/servera;
            index  index.html index.htm;
        }
    }

    server {
        listen       8000;
        listen       www.serverb.com;
        server_name  serverb;

        location / {
            root   html/serverb;
            index  index.html index.htm;
        }
    }
代码语言:javascript
复制
cd /usr/local/openresty/nginx/sbin/
./nginx -t # check conf
./nginx
ps -ef | grep nginx
./nginx -s stop | reload
./nginx
代码语言:javascript
复制
$ netstat -ntpl | grep nginx
tcp        0      0 0.0.0.0:8000            0.0.0.0:*               LISTEN      17601/nginx: master 
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      17601/nginx: master

vim /etc/hosts

代码语言:javascript
复制
127.0.0.1   www.servera.com www.serverb.com

test

代码语言:javascript
复制
cd /usr/local/openresty/nginx/html
mkdir servera serverb
echo servera > servera/index.html
echo serverb > serverb/index.html
curl http://www.servera.com:8000
servera
curl http://www.serverb.com:8000
servers

LAMP

MySQL安装

  • 可以使用 mariadb 替代

yum install mariadb mariadb-server

  • 修改默认编码 vim /etc/my.cnf.d/client.cnf
代码语言:javascript
复制
[client]
default-character-set=utf8

vim /etc/my.cnf

代码语言:javascript
复制
character_set_server=utf8
init_connect='SET NAMES utf8'
  • systemctl start mariadb.service

mysql

代码语言:javascript
复制
MariaDB [(none)]> show variables like '%character_set%';
+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client     | utf8                       |
| character_set_connection | utf8                       |
| character_set_database   | utf8                       |
| character_set_filesystem | binary                     |
| character_set_results    | utf8                       |
| character_set_server     | utf8                       |
| character_set_system     | utf8                       |
| character_sets_dir       | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.01 sec)

PHP 安装

yum install php php-fpm php-mysql yum install php7 php7-fpm php7-mysql

启动 php-fpm

systemctl start php-fpm.service

配置 nginx

vim /usr/local/openresty/nginx/conf/nginx.conf

代码语言:javascript
复制
        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_params;
        }

vim /usr/local/openresty/nginx/html/index.php

代码语言:javascript
复制
<?php
phpinfo();
?>
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • OpenResty 的下载和安装
  • OpenResty 配置文件
  • 虚拟主机
  • LAMP
    • MySQL安装
      • PHP 安装
      相关产品与服务
      云数据库 MySQL
      腾讯云数据库 MySQL(TencentDB for MySQL)为用户提供安全可靠,性能卓越、易于维护的企业级云数据库服务。其具备6大企业级特性,包括企业级定制内核、企业级高可用、企业级高可靠、企业级安全、企业级扩展以及企业级智能运维。通过使用腾讯云数据库 MySQL,可实现分钟级别的数据库部署、弹性扩展以及全自动化的运维管理,不仅经济实惠,而且稳定可靠,易于运维。
      领券
      问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档