首先搭建 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. mac下为什么光标按方向键只能一个字一个字地蹦

    系统偏好设置-键盘 把按键重复拉到最快,重复前延迟拉到最短

  2. 【Maven学习】Maven打包生成普通jar包、可运行jar包、包含所有依赖的jar包

    http://blog.csdn.net/u013177446/article/details/54134394 ******************************************* ...

  3. 【转】VMware虚拟机中CentOS设置固定IP

    因为需要配置固定IP,在网上找了很久终于找到一个可行的例子,自己配置成功了. 1.首先获取你的GATEWAY 方便后面在cento系统配置里使用选取菜单栏:Edit->Virtual Netwo ...

  4. Android开发日记(四)

    在服务器端数据库新建一个表ad 在DataInfo.edxm模型中点击从数据库更新模型,发布. 就新建了一个实体ad 然后新建cs文件 using System; using System.Colle ...

  5. iOS调用其它App,如拨打电话、发送邮件等。UIApplication:openURL:方法是实现这一目的的

    在iOS开发中,经常需要调用其它App,如拨打电话.发送邮件等.UIApplication:openURL:方法是实现这一目的的最简单方法,该方法一般通过提供的url参数的模式来调用不同的App. 通 ...

  6. 【C#】遍历List列表的同时,移除访问到的元素

    需求:遍历List列表,当访问的元素符合某一条件时,将该元素移除出列表. 注意点:使用foreach循环遍历无法做到边读边修改,所以要使用for循环. 例子: // 倒序遍历. for (int i ...

  7. DALFactory有什么作用

    DAL是指Data Access Layer.DALFactory是用于创建数据訪问对象的工厂.本质上是採用了抽象工厂的设计模式.目的是支持多种数据訪问层,比方sql server和oracle两种实 ...

  8. MongoDB(五):MongoDB操作文档

    本篇文章中将讲解如何使用MongoDB操作文档. 文档的数据结构和JSON基本一致,所有存储在集合中的数据都是BSON格式.BSON是一种类似json格式的一种二进制形式的存储格式,简称Binary ...

  9. Hibernate- 基本查询

    01.搭建开发环境 02.基本查询 package com.gordon.test; import java.text.DecimalFormat; import java.util.Arrays; ...

  10. orcale创建用户、授权

    Oracle创建用户.角色.授权.建表 一.首先使用SYSTEM进行登录 oracle数据库的权限系统分为系统权限与对象权限.系统权限( database system privilege )可以让用 ...