Run the app in CodeIgniter 4 in a browser

- Andrés Cruz

En español
Run the app in CodeIgniter 4 in a browser

We have several ways to work with CodeIgniter 4, the most common is to run it directly from the server in Apache:

Laragon

If you use Windows and Laragon, you will have noticed that Laragon automatically generates a clean url for us through the virtual host to access the application:

<VirtualHost *:80> 
    DocumentRoot "C:/laragon/www/peliculas/public"
    ServerName peliculas.test
    ServerAlias *.peliculas.test
    <Directory "C:/laragon/www/peliculas/public">
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

This is a virtual host that Laragon auto-generates for us and since they are auto-generated they are managed internally but you can see which ones you have created from the Laragon application at:

Menú - Apache - site enabled

Of course, if you use Apache on another operating system like Linux or MacOS, or just on Windows you use another server, you can create your virtual host.

Another option, which is the one we are going to use because it is the most direct, is to directly use the spark server that we have in CodeIgniter 4 when installing the framework:

$ php spark serve

We have to execute this command from the root of the project; that is, if our project is called as movies; then we have to place ourselves from our terminal in:

C:\laragon\www\peliculas

It is important to note that if you use spark you do not need Apache, and for the purposes of following this book, you will only need PHP and MySQL.

Also remember to restart your server for Laragon to detect the new project and create the virtual host.

From localhost, if you use Apache

The last one would be to access the entire route from Apache:

http://localhost/peliculas/public/

Which is not highly recommended, since it can bring you complications with the handling of the routes and referencing the base URL and it is a bit tedious to work with these types of URLs.

Optional, if you use Apache

You can create your virtual host in the httpd.conf file; for more information, you can see this link:

https://www.desarrollolibre.net/blog/apache/que-son-y-como-emplear-los-virtualhost-en-apache

Andrés Cruz

Desarrollo con Laravel, Django, Flask, CodeIgniter, HTML5, CSS3, MySQL, JavaScript, Vue, Android, iOS, Flutter

Andrés Cruz en Udemy

Acepto recibir anuncios de interes sobre este Blog.