Welcome Guest, Not a member yet? Register   Sign In
Change localhost:8080 to custom domain CI4
#1

(This post was last modified: 11-27-2022, 12:52 AM by refs.)

Hi,

I'm quite new in CI4, but use CI3 for view years.

I saw a video on youtube where someone change app.php to set CI4 custom domain and remove index.php

here's the link
Code:
https://www.youtube.com/watch?v=yoKTE5J5T7g


this is how exactly i want CI4 work in my localhost (I'm using apache2)

but, since i saw documentation of CI4 where i can run

Code:
php spark serve


and my CI4 run when accesed from
Code:
localhost:8080


is there any way to change that
Code:
localhost:8080
to something like
Code:
http://localhost/mypCI4
so i can access my ci project with "php spark serve" but with my custom domain in localhost ?

im trying to add in .env something like
Code:
app.baseURL=http://localhost/mypCI4
but it's not working

Thanks in advance
Reply
#2

I recommend you set up Apache or something.

There is no way to change the path (`/mypCI4`).
Reply
#3

(11-27-2022, 01:17 AM)kenjis Wrote: I recommend you set up Apache or something.

There is no way to change the path (`/mypCI4`).

So, is it mean that CI4 domain will stay like "localhost:8080" if i use php spark serve ?

and it's also mean i can't have multiple project using CI4 in same host ?
Reply
#4

If you set up Apache (for example WAMP www.wampserver.com) you can add virtual hosts. You can do this by adding a host name to the file hosts (in windows\system32\drivers\etc), for example:
Code:
127.0.0.1 mypCI4.local
Then add a virtual host in httpd-vhosts.conf :

Code:
<VirtualHost *:80>
ServerName mypCI4.local
ServerAlias www.mypCI4.local
DocumentRoot "d:/projects/mypCI4/public"
<Directory  "d:/projects/mypCI4/public">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require local
</Directory>
</VirtualHost>
After restarting Apache you should be able to access your CI4 installation on www.mypCI4.local.
See https://noobietech.com/create-a-virtual-...p-windows/
You won't be able to use php spark serve this way, but you can setup multiple installations now.
Reply
#5

(11-27-2022, 02:03 AM)refs Wrote: So, is it mean that CI4 domain will stay like "localhost:8080" if i use php spark serve ?

"php spark serve" is a server for development.
You can change hostname (=localhost) and port number (=8080).
See "php spark help serve"

But there is no way to change the URI path.
And if you change the hostname, the hostname must be resolved.
For example, you need to add it in your hosts file.

(11-27-2022, 02:03 AM)refs Wrote: and it's also mean i can't have multiple project using CI4 in same host ?

If you mean you want to server like:
http://example.com/project1/
http://example.com/project2/
You cannot use "php spark serve" because it cannot set the URI path (/project1/).

But of course you can do it with Apache.
Reply
#6

(This post was last modified: 11-27-2022, 06:12 AM by refs.)

(11-27-2022, 02:25 AM)JustJohnQ Wrote: If you set up Apache (for example WAMP www.wampserver.com) you can add virtual hosts. You can do this by adding a host name to the file hosts (in windows\system32\drivers\etc), for example:
Code:
127.0.0.1 mypCI4.local
Then add a virtual host in httpd-vhosts.conf :

Code:
<VirtualHost *:80>
ServerName mypCI4.local
ServerAlias www.mypCI4.local
DocumentRoot "d:/projects/mypCI4/public"
<Directory  "d:/projects/mypCI4/public">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require local
</Directory>
</VirtualHost>
After restarting Apache you should be able to access your CI4 installation on www.mypCI4.local.
See https://noobietech.com/create-a-virtual-...p-windows/
You won't be able to use php spark serve this way, but you can setup multiple installations now.

hmm,,interesting, okay, will try it

(11-27-2022, 04:05 AM)kenjis Wrote:
(11-27-2022, 02:03 AM)refs Wrote: So, is it mean that CI4 domain will stay like "localhost:8080" if i use php spark serve ?

"php spark serve" is a server for development.
You can change hostname (=localhost) and port number (=8080).
See "php spark help serve"

But there is no way to change the URI path.
And if you change the hostname, the hostname must be resolved.
For example, you need to add it in your hosts file.

(11-27-2022, 02:03 AM)refs Wrote: and it's also mean i can't have multiple project using CI4 in same host ?

If you mean you want to server like:
http://example.com/project1/
http://example.com/project2/
You cannot use "php spark serve" because it cannot set the URI path (/project1/).

But of course you can do it with Apache.

okay, thanks for the information kenjis
Reply
#7

suggest using laragon (laragon.org). all out of the box (just make project under www folder, all automatic create domain each , project1.test, project2.test)
Reply
#8

laragon, looks interesting if your on windows. But for the time you invest in it to understand it ; you could put into that time into thinking of looking into using Linux as your OS. The benefit of that is that most web servers were using Linux. (Not sure how cloud factors into this now)

So if you run Linux as your OS , you have as part of the system as web server. You will learn about permissions , chmod and the rest
I use Arch Linux by the way 

CMS in Action
Reply
#9

Previously used MAMP-Pro that allows you to set hostnames from the program itself, you will have all tools at hand, Another solution would be to use Hosts file editor, easy to use and setup without any hassle on different OS. WAMP is another solution that allows you to edit virtual hosts in a simple way if you don't know how to handle this yourself.

Options:

- https://www.mamp.info/en/mamp-pro/windows/
- https://www.wampserver.com/en/
- https://hostsfileeditor.com/
Reply




Theme © iAndrew 2016 - Forum software by © MyBB