本文不講述軟件安裝過程,記述本人在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
首先說一下Debian中nginx配置文件的分佈,/etc/nginx/nginx.conf中包含nginx的啓動用戶、進程ID和http等全局配置,具體server配置經過include /enc/nginx/sites-enabled/* 給出,site-enabled目錄中只包含軟連接,軟連接指向site-available目錄中相應的配置文件。site-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
二、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錯誤。
3、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';