• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Build your first application

#1
While following the Build the first application -> https://codeigniter.com/user_guide/tutor...pages.html --Static pages. Behavior is different then what is documented:

localhost:8080/pages  --> http://localhost/ci-news/public/

For each URL listed in Documentation, I have to specify public otherwise it doesn't work. How to remove the requirement to always put public in for the documentation to work?

**Not executing php spark serve as I am running xampp.

Files are located under /htdocs/ci-news.

Moreover, as soon as I add the routes $routes->get('(:any)', 'Pages::view/$1'); in app/Config/Routes.php it starts giving the 404 not found errors.

----Pages controller------
<?php namespace App\Controllers;

use CodeIgniter\Controller;

class Pages extends Controller
{
public function index()
{
return view('welcome_message');
}

public function view($page = 'home')
{
if ( ! is_file(APPPATH.'/Views/pages/'.$page.'.php'))
{
// Whoops, we don't have a page for that!
throw new \CodeIgniter\Exceptions\PageNotFoundException($page);
}

$data['title'] = ucfirst($page); // Capitalize the first letter

echo view('templates/header', $data);
echo view('pages/'.$page, $data);
echo view('templates/footer', $data);
}
}
-------------------
Thanks,
Reply

#2
You need to set-up something called "virtual host" to get rid of /public/ in your url.
https://www.cloudways.com/blog/configure...wordpress/

Document root in the tutorial above are your public folder.
Reply

#3
That helped a little. Changed the following as per the article:

httpd-vhosts.conf:

<VirtualHost *:80>
DocumentRoot "c:/xampp/htdocs/ci-news/public"
ServerName localhost/
<Directory "c:/xampp/htdocs/ci-news/public">
</Directory>
</VirtualHost>

and drivers/etc/hosts

127.0.0.1 localhost/ci-news

Above change helped and the localhost returns the CodeIgniter welcome page. But when accessing localhost/pages or any other linked when following --Build you first application are returning 404 file not found. Looking in to the Apache error log, it displays the following:

[Sat Aug 01 09:19:43.734667 2020] [mpm_winnt:notice] [pid 6256:tid 264] AH00354: Child: Starting 150 worker threads.
[Sat Aug 01 09:20:01.986693 2020] [authz_core:error] [pid 6256:tid 1524] [client ::1:1734] AH01630: client denied by server configuration: C:/xampp/htdocs/ci-news/app/
[Sat Aug 01 09:20:02.036693 2020] [authz_core:error] [pid 6256:tid 1524] [client ::1:1734] AH01630: client denied by server configuration: C:/xampp/htdocs/ci-news/system/
[Sat Aug 01 09:20:02.046693 2020] [authz_core:error] [pid 6256:tid 1524] [client ::1:1734] AH01630: client denied by server configuration: C:/xampp/htdocs/ci-news/writable/
[Sat Aug 01 09:21:32.715820 2020] [ssl:warn] [pid 7892:tid 252] AH01909: www.example.com:443:0 server certificate does NOT include an ID which matches the server name
[Sat Aug 01 09:21:32.745820 2020] [core:warn] [pid 7892:tid 252] AH00098: pid file C:/xampp/apache/logs/httpd.pid overwritten -- Unclean shutdown of previous Apache run?
[Sat Aug 01 09:21:32.745820 2020] [ssl:warn] [pid 7892:tid 252] AH01909: www.example.com:443:0 server certificate does NOT include an ID which matches the server name
[Sat Aug 01 09:21:32.775820 2020] [mpm_winnt:notice] [pid 7892:tid 252] AH00455: Apache/2.4.43 (Win64) OpenSSL/1.1.1g PHP/7.4.8 configured -- resuming normal operations
[Sat Aug 01 09:21:32.775820 2020] [mpm_winnt:notice] [pid 7892:tid 252] AH00456: Apache Lounge VC15 Server built: Apr 22 2020 11:11:00
[Sat Aug 01 09:21:32.775820 2020] [core:notice] [pid 7892:tid 252] AH00094: Command line: 'c:\\xampp\\apache\\bin\\httpd.exe -d C:/xampp/apache'
[Sat Aug 01 09:21:32.775820 2020] [mpm_winnt:notice] [pid 7892:tid 252] AH00418: Parent: Created child process 7916
[Sat Aug 01 09:21:33.056821 2020] [ssl:warn] [pid 7916:tid 264] AH01909: www.example.com:443:0 server certificate does NOT include an ID which matches the server name
[Sat Aug 01 09:21:33.086821 2020] [ssl:warn] [pid 7916:tid 264] AH01909: www.example.com:443:0 server certificate does NOT include an ID which matches the server name
[Sat Aug 01 09:21:33.116821 2020] [mpm_winnt:notice] [pid 7916:tid 264] AH00354: Child: Starting 150 worker threads.

Looks like the permission issue or something else?

Following the article below to see if that helps in resolving:

http://httpd.apache.org/docs/2.4/upgrading.html#access
Reply

#4
This part aren't correct:

Code:
ServerName localhost/
127.0.0.1 localhost/ci-news

Should be (for example)

Code:
ServerName codeigniter.localhost
127.0.0.1 codeigniter.localhost

You can then access it with http://codeigniter.localhost

Personally using this. Depending on what kind of settings you want.

Code:
<VirtualHost *:80>
    ServerName skribbl.localhost
    DocumentRoot "c:/wamp64/www/skribbl.localhost/public"
    <Directory  "c:/wamp64/www/skribbl.localhost/public/">
        Options +Indexes +Includes +FollowSymLinks +MultiViews
        AllowOverride All
        Require local
    </Directory>
</VirtualHost>
Reply

#5
Changed as follows:
etc/hosts
127.0.0.1 codeigniter.localhost

httpd-vhost.conf
<VirtualHost *:80>
ServerName codeigniter.localhost
DocumentRoot "c:/xampp/htdocs/ci-news.localhost/public"
<Directory "c:/xampp/htdocs/ci-news.localhost/public/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require local
</Directory>
</VirtualHost>

Also now running the Xampp control panel with Admin access. Physical folder is at c:\xampp\htdocs\ci-news and undernath this folder codeigniter framework files.

Now the codeigniter.localhost returning as object not found - 404.

Thanks for keeping the patience.
Reply

#6
It needs to have correct physical path:

DocumentRoot "c:/xampp/htdocs/ci-news/public"
<Directory "c:/xampp/htdocs/ci-news/public/">
Reply

#7
Yes, corrected. Now the Welcome page is loading correctly, but the links to pages, pages/index etc is giving 404. Just like IIS failed request error logs, is there something in Apache that I can refer to as to which path it is going to when giving 404?
Reply

#8
Have you changed the applications url to match? Either in .env or app\Config\App.php
https://codeigniter.com/user_guide/insta...g.html#id2

Set it into:
Code:
http://codeigniter.localhost/

Maybe you haven't activated rewrite?
https://codeigniter.com/user_guide/insta...-in-my-url
Reply

#9
Yes to both .env. App.php modified.

Rewrite activated, yes.

Still the same issue.

Tried changing public $indexPage = 'index.php?'; instead of public $indexPage = 'index.php'; as per https://codeigniter.com/user_guide/insta...-in-my-url --Only the default page loads. That isn't helping. I will paste the structure with files info to give more insight in to the issue. Just in case if you can find it.
Reply

#10
Here is a template for creating VHOSTS using Windows and XAMPP.

Code:
#--------------------------------------------------------------
# For New VHosts
#--------------------------------------------------------------

#--------------------------------------------------------------
#
#--------------------------------------------------------------

#--------------------------------------------------------------
# HTTP:
#--------------------------------------------------------------
<VirtualHost *:80>
    DocumentRoot "C:/xampp/htdocs/project_name/public"
    ServerName server_name.local
    ServerAlias server_name.local
    <Directory "C:/xampp/htdocs/project_name/public">
        Order allow,deny
        Allow from all
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

#--------------------------------------------------------------
# HTTPS:
#--------------------------------------------------------------
<VirtualHost *:443>
    DocumentRoot "C:/xampp/htdocs/project_name/public"
    ServerName server_name.local
    ServerAlias server_name.local
    SSLEngine on
    SSLCertificateFile "conf/ssl.crt/server.crt"
    SSLCertificateKeyFile "conf/ssl.key/server.key"
    <Directory "C:/xampp/htdocs/project_name/public">
        Options All
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

#--------------------------------------------------------------
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.