本文不讲述软件安装过程,记述本人在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 虚拟主机配置
首先说一下Debian 中nginx 配置文件的分布,/etc/nginx/nginx.conf 中包含nginx 的启动用户、进程ID 和http 等全局配置,具体server 配置通过include /enc/nginx/sites-enabled/* 给出,site-enabled 目录中只包含软链接,软链接指向site-available 目录中相应的配置文件。s ite-available 中有一个默认server 配置,下面是我的site-enabled 目录情况:
下面是codeigniter 和php_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;
}
}
注意:以上两个文件有以下两处不同
1 、root
2、server_name
这样配置完成后,重新启动nginx 会报错,因为两个server_name 还没有设置,这个需要修改/etc/hosts 文件,添加下面两行:
127.0.0.1 www.ci.com
127.0.0.1 www.pma.com
其中www.ci.com 和www.pma.com 是codeigniter 和php_my_admin 中server_name 对应,这个两个可以根据自己的喜好设置,重启电脑就可以正常运行nginx 了,可以通过www.ci.com 和www.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 省略时,这个要有,因为CodeIgniter 中site_url 会包含$config[‘base_url’]和$config[‘index_page’]两部分。
$config[‘uri_protocol’] = ‘PATH_INFO’;
Original: https://www.cnblogs.com/lameisoft/p/10555881.html
Author: 腊梅软件
Title: Debian中CodeIgniter+nginx+MariaDB+phpMyAdmin配置
原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/606518/
转载文章受原作者版权保护。转载请注明原作者出处!