Setup CodeIgniter4
Setup CodeIgniter4
This example installs a current CodeIgniter 4 application with Composer from inside the Devilbox PHP container and serves it through the standard htdocs virtual host layout.
Overview
| Project name | Container path | Database | TLD_SUFFIX | Project URL |
|---|---|---|---|---|
my-ci | /shared/httpd/my-ci | my_ci | lvh.me | http://my-ci.lvh.me / https://my-ci.lvh.me |
Inside the container, projects live in /shared/httpd/. On the host, the files are in ./data/www/ below the Devilbox checkout.
Prerequisites
- Devilbox with PHP 8.3 or PHP 8.4 available from
env-example. - MySQL and HTTPD containers enabled.
- Docker Compose v2 and
./dvl.sh.
Start the stack:
./dvl.sh up php httpd mysql bindWalk through
It will be ready in eight steps:
- Enter the PHP container.
- Create a new virtual host directory.
- Install CodeIgniter 4.
- Link
public/tohtdocs. - Add a MySQL database.
- Configure the database connection.
- Verify DNS.
- Open the project in a browser.
1. Enter the PHP container
./dvl.sh shell php832. Create the vhost directory
mkdir -p /shared/httpd/my-cicd /shared/httpd/my-ci3. Install CodeIgniter 4
composer create-project codeigniter4/appstarter ci4appExpected structure:
tree -L 1.└── ci4app4. Link the webroot
ln -s ci4app/public htdocsExpected structure:
tree -L 1.├── ci4app└── htdocs -> ci4app/public5. Add the MySQL database
mysql -u root -h 127.0.0.1 -p -e 'CREATE DATABASE my_ci CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;'6. Configure the database connection
Copy the environment template and edit it:
cd ci4appcp env .envvi .envSet the database values:
database.default.hostname = 127.0.0.1database.default.database = my_cidatabase.default.username = rootdatabase.default.password =database.default.DBDriver = MySQLidatabase.default.port = 33067. Verify DNS
With TLD_SUFFIX=lvh.me, my-ci.lvh.me resolves automatically. For another suffix, add a hosts entry for your chosen name.
8. Open your browser
Visit http://my-ci.lvh.me or https://my-ci.lvh.me.
Next steps
- Use
./dvl.sh exec "php spark"from the project directory for non-interactive Spark commands. - Use the Devilbox intranet database tools to inspect
my_ci. - Add HTTPS trust and Xdebug once the application responds.