用Codeigniter4做轻量级管理系统

Codeigniter4的快速入门笔记 01

2023-10-13  本文已影响0人  Unc1eY11

简单来说,Codeigniter4在使用前的配置就三步:

  1. 弄好php的扩展、根目录
  2. 弄好Codeigniter4的首页地址
  3. 弄好Codeigniter4的.htaccess文件

0. 参考链接

1. 配置环境

1.1 配置扩展 - php.ini

右上角的PHPInfo

打开 php.ini,设置php扩展:

;extension=intl //起到掐面,去掉前面的;

1.2 配置环境 - httpd.conf

1.2.1 关于目录

通过xampp的控制面板打开 httpd.conf ,不同人有不同的习惯,有些人喜欢把所有程序都放在 htdocs 下面,有些人就喜欢指定程序目录 htdocs/my_project ,而我就喜欢在 htdocs 的平行目录下创建程序文件夹 htdocs_ci4,便于模拟日后在虚拟主机上同样的使用体验。

httpd.conf
# 搜索“root”,修改根目录
# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
#
DocumentRoot "/xampp/htdocs_ci4"
<Directory "/xampp/htdocs_ci4">

1.2.2 关于端口

# 搜索“listen”,修改端口为80,或者需要的端口
# Listen: Allows you to bind Apache to specific IP addresses and/or
# ports, instead of the default. See also the <VirtualHost>
# directive.
#
# Change this to Listen on specific IP addresses as shown below to 
# prevent Apache from glomming onto all bound IP addresses.
#
#Listen 12.34.56.78:80
Listen 80

如果报错,可以通过右上角的「Netstat」检查哪些程序占用端口

2. 修改程序设置

下载 Codeigniter4 ,这篇文章用的是 v4.4.1。解压到 htdocs_ci4 ,然后做两个动作:

2.1 修改首页地址

app/config/app.php 里面修改首页地址,不需要端口。

/**
 * --------------------------------------------------------------------------
 * Base Site URL
 * --------------------------------------------------------------------------
 *
 * URL to your CodeIgniter root. Typically, this will be your base URL,
 * WITH a trailing slash:
 *
 *    http://example.com/
 */
public string $baseURL = 'http://localhost:8080/';

改为:

public string $baseURL = 'http://localhost/';

2.2 .htaccess

实现自动跳转 public 文件夹,这段代码在手册中复制过来。创建一个 .htaccess 文件,将代码复制到里面,保存。放在htdocs_ci4 根目录下。

https://codeigniter4.github.io/userguide/installation/running.html#adding-htaccess

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteRule ^(.*)$ public/$1 [L]
</IfModule>

<FilesMatch "^\.">
    Require all denied
    Satisfy All
</FilesMatch>

3 启动 xampp

xampp

(完)

上一篇 下一篇

猜你喜欢

热点阅读