PHP MySQL novice to ninja 6th edition

I will try it on a live server(I believe the server is running on ubuntu

Make sure you follow my instructions above, the process is the same on both windows and Linux.

One thing I will add is if you follow the book from the start you’ll have a better understanding of how everything works and the directory structure rather than just trying to run the finished website.

2 Likes

I followed it from the start and I finished it as well, it was the same issue and that was why I downloaded the final project from github to test and see where my mistake was. But it is the same issue. Actually I tried installing Vagrant from the beginning but it did not work out due to some issues with my laptop.
I followed it and I fully understand the tutorial from A-Z…even with the problem it keeps displaying, I still continue to work on one of my personal projects just to get the full understanding of it. This is another reader who makes the same complain right here…Novice to Ninja book {error} while using XAMPP - #13 by TomB

Did you get it working? The issue in that thread was a modification to the code.

Hi, oluwa.

There is nothing at all wrong with Tom’s code (I have read the book from beginning to end and the code works fine).

What’s going wrong is that Tom has used Vagrant which is a COMPLETE environment. So its not just the code we are working with; it’s the code and how it interacts with the web server. And it’s this half we need to look at. I have not used Vagrant and I’ve had a few we server related changes I’ve had to make in order to get the code working (not the fault of the code; my fault for not using Vagrant). Here is what might be going wrong for you

You SHOULD have your index.php file inside a folder called public but then you need to set up a VirtualHost and, in your DocumentRoot setting have something like:

 DocumentRoot /var/www/www.<chosendomainname>.local/public

…see the use of public at the end.

I’ve had other changes to make as well.

Have a look at this thread and if there are still aspects you don’t understand, let me know and I’ll walk you through it:

https://www.sitepoint.com/community/t/url-rewriting-php-mysql-novice-to-ninja/290945

Ok. thank you I will

Still the same problem on live server…but am looking @mike324 explanation

@mike324 this is what I have for the virtualhost setup.


<Directory C:/alls>
	AllowOverride All
	Require all granted
</Directory>

<VirtualHost *:80>
    DocumentRoot "C:/alls/ijdb/public"
    ServerName ijdb.localhost
    SetEnv NS_ENV variable_value
</VirtualHost>

Is this how to set it up? and if yes, how do I call it on the browser url?

@tomB and @mike324 I have been able to solve the issue of undefined index and method name must be a string with the help of @mike324. But I still have a problem of Object not found which is displayed when I clicked on one of the links like joke/list but the home link is working perfectly. I have attached the screenshots of what am saying

since I have created .htaccess in the public folder, what now happened to this line.

$route = ltrim(strtok($_SERVER['REQUEST_URI'], '?'), '/'); what will it change to?

Reply to post #27,

Hi, oluwa.
OK, I can see you’re using Windows. Mmmm. I’ll try and help you but understand I would not use Windows if you paid me. My instructions are for Linux. I’ll try and talk about the concepts rather than the exact code and you’ll have to translate…

The idea of having a virtual host is that you “replicate” a public web server on your own laptop. So, in the absence of a real server, you can:

Make up a domain name, set that up as a VirtualHost “server name”, then tell your laptop to look for this on itself rather than on the internet.

So, your VirtualHost file contains a ServerName. This can be “www.ijdb.local” or something. Not finished yet…

You need also, in your VirtualHost, to tell your laptop where your web server (IIS in your case?) keeps ALL web files. So, again, in your VirtualHost, your DocumentRoot should be “where your web files are” / “server name” / “where THIS site’s index file is”. So, if you look at your DocumentRoot with that pattern in mind, you have got:

Where your web files are: “C:/alls”
ServerName: “ijdb.localhost”
Where THIS site’s index is: “public”.

So, in answer to your question about the URL you should be using to get to that: simply ServerName. So you should use “ijdb.localhost”. You don’t need ijdb.localhost/index.php. The lack of index.php is handled by your site’s routing. Just type “ijdb.localhost” (without quotes) into your browser. You could just have used “ijdb”.

However, I think your DocumentRoot is wrong as you have not used your full ServerName. It should not be:
“C:/alls/ijdb/public”

It should be C:/alls/ijdb.localhost/public

Or do it the other war around, if you want your DocRoot to be what you’ve got, change your ServerName to just “ijdb” and browse to “ijdb” in your browser.

For Linux, you also need a file to tell the browser NOT to look on the Internet for this. It’s called a “Hosts” file. In that you need:

IP Address ServerName

So, something like 127.0.0.1 ijdb.localhost

That should get you working.

To post #28.

Make the changes in my last reply. Try again and post results.

ok. I will try it out now

To #29

Your use of the .htaccess file is linked to this line but you should NOT change this line. The line takes a URL such as “ijdb.localhost/joke/list” and returns “joke/list”. This is your route which will be set up in IjdbRoutes.php.

All your .htaccess file does is say:

“Hey, the url ijdb.localhost/joke/list (i.e. a file called “list” inside a folder called “joke”, inside the root of your site) doesn’t exist, so I’m going to redirect the request to index.php”.

From there, you’ll go through IjdbRoutes.php where “joke/list” IS a route and that route will send you to the “list” action (method) in the “Joke” controller.

Sorry for the late reply…it is now working efficiently…

Oluwa,

Glad you got sorted. :slight_smile:

oluwa,

Can you tell us exactly what you found to be the problem and exactly what you changed to fix it?

What would you suggest that might help others avoid this problem?

1 Like

@oluwa, we are still waiting because am still going through the error. I was the one who started the topic you quoted and am also a Windows user…

I think am interested in debian linux…how can I go about it? At https://www.debian.org/ all I see is just the download 9.5, I didnt see anything like download GNOME. Also I heard that the 9.5 version is not good. While trying to download the version, the version is just 200+ in megabyte which I think is small for an OS