首先搭建 LNMP 的服务器环境
  • 安装 Nginx, MySQL 和 PHP 软件包,执行以下命令

yum install -y nginx mariadb-server mariadb php php-fpm php-mysql

启动并检查 Nginx 和 PHP 的安装情况

修改 /etc/nginx/nginx.conf,可参考下面的配置示例:
nginx.conf 
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid; include /usr/share/nginx/modules/*.conf; events {
worker_connections 1024;
} http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048; include /etc/nginx/mime.types;
default_type application/octet-stream; server {
listen 80 default_server;
#listen [::]:80 default_server;
server_name _;
root /var/www/html; # Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf; location / { } location ~ .php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
} error_page 404 /404.html;
location = /40x.html {
} error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
}

启动nginx服务器

检查php环境搭建,phpinfo();

启动 PHP-FPM 进程:

service php-fpm start

启动之后,可以使用下面的命令查看 PHP-FPM 进程监听哪个端口
netstat -nlpt | grep php-fpm
chkconfig php-fpm on

启动并配置 MySQL
systemctl start mariadb
配置密码, 这里默认使用密码 QcloudLabPASSWORD
mysqladmin -u root password 'QcloudLabPASSWORD'
登录 MySQL
mysql -u root -pQcloudLabPASSWORD
创建数据库 CI
create database CI;
退出 MySQL, 回到 Bash shell 下载 CI 框架
     执行以下命令, 将 CI 框架下载到 家目录 下
      wget https://mc.qcloudimg.com/static/archive/282f387cae30259401a8800e8d17e60b/CodeIgniter-3.1.4.zip -O ~/CodeIgniter.zip
 
安装 CI 框架

将CodeIgniter.zip 解压到 /var/www/html 目录下
unzip ~/CodeIgniter.zip && mv ~/CodeIgniter-3.1.4/* /var/www/html
 

实践 CI 框架

  • 知识准备
    这里将会演示如何通过 CI 框架, 使得访问 http://123.207.8.59/index.php/firstrun/hello 返回 "Hello, World"
    在 CI 的路由规则中, 路由的匹配规则:
    1. 用户访问的 URL 为 http://123.207.8.59/index.php/firstrun/hello
    2. 此时 CI 会查找 application/controller 目录下名为 Firstrun.php 的 PHP 文件 
       
    3. 该 PHP 文件有个叫 Firstrun 的 class
    4. 该 class 有一个叫 hello 的方法, 该方法处理对此 URL 地址的请求并作出响应
     

编写调用代码

在 /var/www/html/application/controllers 目录下新建一个叫 Firstrun.php 的文件, 代码如下:
Firstrun.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed'); class Firstrun extends CI_Controller { public function hello() {
echo 'Hello World';
}
}

  修改nginx配置并重启

修改 /etc/nginx/nginx.conf,可参考下面的配置示例:
nginx.conf
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid; include /usr/share/nginx/modules/*.conf; events {
worker_connections 1024;
} http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048; include /etc/nginx/mime.types;
default_type application/octet-stream; server {
listen 80 default_server;
#listen [::]:80 default_server;
server_name _;
root /var/www/html; # Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf; location / {
# 这里使用try_files进行url重写,不用rewrite了。
try_files $uri $uri/ /index.php?$query_string;
} location ~ .php($|/) {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^(.+.php)(.*)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
} error_page 404 /404.html;
location = /40x.html {
} error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
}

  重启 Nginx

大功告成

搭建LNMP+CI环境的更多相关文章

  1. 图文详解如何快捷搭建LNMP服务环境

    上一篇与大家一起学习了下如何搭建LAMP环境的知识,今天小编再和大家分享下如何快捷地搭建LNMP环境,并搭建起一个网站.Nginx是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/S ...

  2. 使用Docker搭建LNMP开发环境

    1.什么是Docker Docker 使用 Google 公司推出的 Go 语言 进行开发实现,基于 Linux 内核的 cgroup,namespace,以及 AUFS 类的 Union FS 等技 ...

  3. Mac OS上搭建LNMP开发环境

    1. 概述 LNMP代表的就是:Linux系统下Nginx+MySQL+PHP这种网站服务器架构.Linux是一类Unix计算机操作系统的统称,是目前最流行的免费操作系统.代表版本有:debian.c ...

  4. Vmware搭建LNMP环境(Centos7+Nginx+Mysql+PHP7.1.8)

    参考:1.Linux学习之CentOS(一)----在VMware虚拟机中安装CentOS 7(图文教程) 2.Centos7搭建LNMP环境 3.MySQL5.7修改默认root密码 4.CentO ...

  5. Mac OSX 下配置 LNMP开发环境

    不久前负责了一个项目需要配置PHP7的开发环境,因为之前所有的项目用的是PHP5的,所以研究了这些东西,但是很遗憾,电脑出了问题,不得已重装了系统,然后你懂得...什么都没有了,要重新来过.. 虽然本 ...

  6. 五分钟用Docker快速搭建Go开发环境

    挺早以前在我写过一篇用 `Docker`搭建LNMP开发环境的文章:[用Docker搭建Laravel开发环境](http://mp.weixin.qq.com/s?__biz=MzUzNTY5MzU ...

  7. CentOS6.6搭建LNMP环境

    CentOS6.6搭建LNMP环境 1.设置yum源,本地安装依赖包 1 yum -y install gcc gcc-c++ automake autoconf libtool make 2.下载依 ...

  8. CentOS下Web服务器环境搭建LNMP一键安装包

    CentOS下Web服务器环境搭建LNMP一键安装包 时间:2014-09-04 00:50来源:osyunwei.com 作者:osyunwei.com 举报 点击:3797次 最新版本:lnmp- ...

  9. Jenkins+Maven+Git CI环境搭建手册

    Jenkins+Maven+Git CI环境搭建手册 环境: OS:Linux version 2.6.32-220.23.2.ali878.el6.x86_64 (ads@kbuild) (gcc ...

随机推荐

  1. Interception c# code

    http://www.codetails.com/2012/12/02/intercepting-method-calls-using-il/20121202/ http://blogs.msdn.c ...

  2. JQuery中eq()和get()的区别

    众所周知,eq()方法返回的是一个JQuery对象,也就是[object Object]; get()方法返回的是DOM对象组成的数组,也就是[object HTMLLIElement]; 我们用一个 ...

  3. 如何保证RabbitMQ的消息不丢失及其背后的原理

    一.消息为什么丢失 RabbitMQ默认情况下的交换机和队列以及消息是非持久化的,也就是说在服务器重启或者宕机恢复后,之前创建的交换机和队列都将不复存在,之前未消费的消息也就消失不见了.原因在于每个队 ...

  4. asp.net 获取客户端IP

    一.名词 首先说一下接下来要讲到的一些名词. 在Web开发中,我们大多都习惯使用HTTP请求头中的某些属性来获取客户端的IP地址,常见的属性是REMOTE_ADDR.HTTP_VIA和HTTP_X_F ...

  5. RTX——第14章 信号量

    以下内容转载自安富莱电子: http://forum.armfly.com/forum.php 本章节开始讲解 RTX 的另一个重要的任务间的同步和资源共享机制,信号量. 信号量有3种用途: 1) 表 ...

  6. Excel VBA 操作 Word(入门篇)

    原文地址 本文的对象是:有一定Excel VBA基础,对Word VBA还没有什么认识,想在Excel中通过VBA操作Word还有困难的人.   一.新建Word引用 需要首先创建一个对 Word A ...

  7. iOS UIWebView与WKWebView使用详解

    一.整体介绍 UIWebView自iOS2就有,WKWebView从iOS8才有,毫无疑问WKWebView将逐步取代笨重的UIWebView.通过简单的测试即可发现UIWebView占用过多内存,且 ...

  8. IOS之TableViewCell重用机制避免重复显示问题

    常规配置如下 当超过tableView显示的范围的时候 后面显示的内容将会和前面重复. 1 // 这样配置的话超过页面显示的内容会重复出现 2 - (UITableViewCell *)tableVi ...

  9. 汇编入门学习笔记 (九)—— call和ret

    疯狂的暑假学习之  汇编入门学习笔记 (九)--  call和ret 參考: <汇编语言> 王爽 第10章 call和ret都是转移指令. 1. ret和retf ret指令:用栈中的数据 ...

  10. Python高级编程之生成器(Generator)与coroutine(四):一个简单的多任务系统

    啊,终于要把这一个系列写完整了,好高兴啊 在前面的三篇文章中介绍了Python的Python的Generator和coroutine(协程)相关的编程技术,接下来这篇文章会用Python的corout ...