I need to run CodeIgniter project from any location without the need to replace it on the directory (www) of my WAMP server. So I want to use the CLI and Composer for this.
For Composer autoloading I follow these instructions from this link.
Here is my config file:
$config['composer_autoload'] = TRUE;
And my composer.json
:
"config": {
"vendor-dir": "application/vendor"
},
After that I run composer update
to create the vendor/
folder.
However when I tried to run the project using CLI like so:
php index.php MYController_1 Methode_1
Instead of opening and running the web application through web browser, the source code of this page is printed to the console.
What is the equivalent of Laravel's php artisan serve
for CodeIgniter?
php artisan serve
is how Laravel starts a local development server:
Serving Laravel
Typically, you may use a web server such as Apache or Nginx to serve your Laravel applications. If you are on PHP 5.4+ and would like to use PHP's built-in development server, you may use the
serve
Artisan command:php artisan serve
CodeIgniter version 3 doesn't have an equivalent command to this, but you can use PHP's built-in webserver as Lázaro suggests:
php -S localhost:8000 index.php
If you are using CodeIgniter version 4 you can start its local development server with php spark serve
. The documentation gets the command name wrong, but is otherwise helpful, so I've included it here with the fixed command:
Local Development Server
PHP provides a built-in web server that is can be used locally when developing an application without the need to setup a dedicated web server like MAMP, XAMPP, etc. If you have PHP installed on your development machine, you can use the
serve
script to launch PHP’s built-in server and have it all setup to work with your CodeIgniter application. To launch the server type the following from the command line in the main directory:php spark serve
This will launch the server and you can now view your application in your browser at http://localhost:8080.
Note
The built-in development server should only be used on local development machines. It should NEVER be used on a production server.
PHP has a build in server that you can use. Just run
php -S localhost:8000 -t YOUR_PROJECT_FOLDER/
Codeigniter itself has nothing like a 'php artisan serve'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With