Debian中CodeIgniter+nginx+MariaDB+phpMyAdmin配置

  本文不讲述软件安装过程,记述本人在Debia配置CodeIgniter时遇到的问题及解决方法,但愿可以为有须要的人提供帮助php

1、Debian版本及所需的软件html

  Debian 9.8 stretchnginx

  PHP 7.0.3php7

  Nginx 1.10.3-1socket

  Php7.0-fpmcodeigniter

  phpMyAdmin 4.8.5php-fpm

  MariaDB 10.1.37网站

  CodeIgniter 3.1.10url

2、nginx虚拟主机配置spa

  首先说一下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

  二、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错误。

3、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';

相关文章
相关标签/搜索