no-framework-tutorial icon indicating copy to clipboard operation
no-framework-tutorial copied to clipboard

Couldn't get Step 06 to work

Open zethon opened this issue 6 years ago • 10 comments

Struggled with Part 6 for a while because it kept telling the class Example\Controllers\Homepage could not be found. Took me about two hours to figure out I needed to run composer update.

This is not immediately obvious and should be mentioned in the tutorial.

zethon avatar Oct 22 '19 00:10 zethon

Thanks! I was struggling with the same issue, luckily I saw your issue. After a while, I realized my problem was the working directory where I was running the server. You should use public directory to run php -S localhost:8000 instead of root directory.

ivanfranco502 avatar Jul 02 '20 18:07 ivanfranco502

At step6, when running running the site on root, e.g my example is on testsite2.loc, I get: Imgur Am I supposed to see it at this step still? I bet not, I don't know to which step go back and debug.

Wondarar avatar Nov 13 '21 20:11 Wondarar

an on /public I still get the 404....?

Imgur

Wondarar avatar Nov 13 '21 21:11 Wondarar

Need a .htaccess file in your public folder.

ellisgl avatar Nov 14 '21 02:11 ellisgl

Sorry I don'T get it. When I put the index.php in the root and echo a simple "hello world" all is fine. Why do I need the htaccess now? And what should I put into htaccess?

Wondarar avatar Nov 14 '21 09:11 Wondarar

@Wondarar you need to start your server in the public so either:

php -S localhost:8000 -t public/

from the root of your project or directly from public folder:

cd public
php -S localhost:8000

I see you created virtual host testsite2.loc so make sure it points to public folder, not the root of your project.

.htaccess is not required :)

SharakPL avatar Nov 14 '21 09:11 SharakPL

Ok, since not required I skip that. Here's the testsite2.loc.conf file and in yellow what I added today (which is obsolete then anyways).

Imgur

Where do I set the pointer to public? Is it within this conf file? Is it in line 12, adding \public ?

If I understand it correcty, $routeInfo should NOT give me an empty array? But since it keeps being empty it correctly resolves to the 404.

Imgur

And here's the Route.php

Imgur

Wondarar avatar Nov 14 '21 14:11 Wondarar

Your config is invalid. <Directory> block should be inside <VirtualHost>. Here's an example:

<VirtualHost *:80>
    # first VH is default for apache - do not change it
</VirtualHost>

<VirtualHost *:80>
	ServerName mysite.test
	DocumentRoot "/path/to/mysite/public"
	<Directory  "/path/to/mysite/public">
		Options +Indexes +Includes +FollowSymLinks +MultiViews
		AllowOverride All
		Require local
	</Directory>
</VirtualHost>

Then make sure /etc/hosts file has valid IP pointer for mysite.test. Here's well written tutorial

Leave this first <VirtualHost> untouched. It's default for the apache. Just add another below.

SharakPL avatar Nov 14 '21 15:11 SharakPL

Working now :1st_place_medal: Thank you! :)

Imgur

Wondarar avatar Nov 14 '21 15:11 Wondarar

Glad I could help :) Issue resolved so you can close it now.

SharakPL avatar Nov 14 '21 15:11 SharakPL