Debian中CodeIgniter+nginx+MariaDB+phpMyAdmin配置

  本文不讲述软件安装过程,记述本人在Debia配置CodeIgniter时遇到的问题及解决方法,希望能够为有需要的人提供帮助

一、Debian版本及所需的软件

  Debian 9.8 stretch

  PHP 7.0.3

  Nginx 1.10.3-1

  Php7.0-fpm

  phpMyAdmin 4.8.5

  MariaDB 10.1.37

  CodeIgniter 3.1.10

二、nginx虚拟主机配置

  首先说一下Debiannginx配置文件的分布,/etc/nginx/nginx.conf中包含nginx的启动用户、进程IDhttp等全局配置,具体server配置通过include /enc/nginx/sites-enabled/* 给出site-enabled目录中只包含软链接,软链接指向site-available目录中相应的配置文件。site-available中有一个默认server配置,下面是我的site-enabled目录情况:

 

  下面是codeigniterphp_my_admin两个文件(在sites-available目录中)的内容

codeigniter:

# Server configuration for CodeIgniter
server {

    listen 80 default_server;
    listen [::]:80 default_server;

    root /var/www/html/CodeIgniter-3.1.10;
 
    # Add index.php to the list if you are using PHP
    index index.php index.html index.htm index.nginx-debian.html; 

    server_name www.ci.com;

    location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
        try_files $uri $uri/ =404;

    }

    # pass PHP scripts to FastCGI server

    location ~ \.php($|/) {

        include snippets/fastcgi-php.conf;

        # With php-fpm (or other unix sockets):
        fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
    }
}    

 

php_my_amdin:

# Server configuration for phpMyAdmin

server {

    listen 80;

    root /var/www/html/phpMyAdmin;

    # Add index.php to the list if you are using PHP
    index index.php index.html index.htm index.nginx-debian.html;

    server_name www.pma.com;

    location / {

        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
        try_files $uri $uri/ =404;
    }

    # pass PHP scripts to FastCGI server

    location ~ \.php($|/) {

        include snippets/fastcgi-php.conf;

        # With php-fpm (or other unix sockets):
        fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
    }
}

注意:以上两个文件有以下两处不同
  1root

  2、server_name

 

  这样配置完成后,重新启动nginx会报错,因为两个server_name还没有设置,这个需要修改/etc/hosts文件,添加下面两行:

  127.0.0.1 www.ci.com

  127.0.0.1 www.pma.com

  其中www.ci.comwww.pma.comcodeigniterphp_my_adminserver_name对应,这个两个可以根据自己的喜好设置,重启电脑就可以正常运行nginx了,可以通过www.ci.comwww.pma.com来访问相应的网站了。

注:在配置以上两个server时注意location ~ \.php($|/),默认只有$要加上|/,否则可能会出现只能访问CI配置路由的页面,访问其他页面会出现404错误。

三、Codeigniter配置

  配置文件config.php

  $config['base_url'] = 'http://www.ci.com/';

  这一句http://这个要有,不能少

  $config['index_page'] = 'index.php';

  在没有配置index.php省略时,这个要有,因为CodeIgnitersite_url会包含$config['base_url']$config['index_page']两部分。

  $config['uri_protocol'] = 'PATH_INFO';

转载于:https://www.cnblogs.com/lameisoft/p/10555881.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值