I Created a CRUD Application and I Have a 404 Error

Hello,

I am trying to make an address book CRUD application. When I finished creating the Model and the CRUD application, I entered the address and I get a 404 error. (I will include and image at the end of this post in case you all need to see it.) I entered the correct information in the Model Generator and the CRUD Generator. (I will also include these images.) I am working on a localhost(XAMPP). What am I doing wrong?

Thanks in advance,

JD

7273

Screen Shot 2017-02-14 at 5.18.15 PM.png

7271

Screen Shot 2017-02-14 at 5.00.11 PM.png

7272

Screen Shot 2017-02-14 at 5.07.11 PM.png

To be able to help you, it would be great to know, which URL you entered.

Cheers

Nik

With our without pretty URLs?

The most common cause is, with pretty URLs enabled, that the web server is not set up properly.

Check that the rewrite module is installed/loaded/enabled and that the configuration for your virtual host / main site has


AllowOverride All



If the site does not have a .htaccess - assuming Apache - then you need to create one, as described in the guide:

http://www.yiiframework.com/doc-2.0/guide-start-installation.html#configuring-web-servers

I entered http://localhost/basic/web/addressBook

Would you call http://localhost/basic/web/addressBook a valid URL ?

You need to instruct your web server to serve your site from ‘basic/web’ - see the guide.

To test it out, before configuring your webserver properly, open a console in ‘basic/web’ and run


../yii serve --port=8888

Without any configuration, you should be able to run


http://localhost:8888/basic/web/index.php


http://localhost:8888/basic/web/index.php?r=addressBook

I tried that and I still got a 404 error.

Here’s what my httpd.conf looks like currently:

7274

Screen Shot 2017-02-15 at 4.05.12 PM.png

What am I doing wrong?

Put


AllowOverride All

in your configuration.

What you posted in what should go into the local .htacess file - put one in yoursite/web.

What you need to do with Apache global config is to slightly modify the default site to point to your directory, and then leave the rest as is - that is, no rewrite directives, only options, allowoverride - what the configuration was before you changed it.

Could you enable pretty URLs ?

Then you should get error 500 instead - at least until the configuration is right.

Reading the guide again makes me think that you are probably on the right track, however you should probably add one line to the configuration:


	RewriteBase /



Add it after you turn the rewrite engine on.

If that does not work, separate site config and local config (htaccess file) like I said.

Don’t forget that you need to restart your webserver each time you change the configuration?

Who knows, maybe it already works, and Apache didn’t pick it up?

I followed your instructions and I got a HTTP 500 error. The only thing is my whole web application is broke now. I will include what my http.conf and my .htaccess file looks like.

Can you post them as code ?

From the looks of it, the content is swapped.

I switched the code around, and here’s what I have currently:

httpd.conf

Alias /bitnami/ "/Applications/XAMPP/xamppfiles/apache2/htdocs/"

Alias /bitnami "/Applications/XAMPP/xamppfiles/apache2/htdocs"

RewriteEngine on

#<Directory "/Applications/XAMPP/xamppfiles/apache2/htdocs">

Options Indexes FollowSymLinks


AllowOverride All


Order allow,deny


Allow from all

</Directory>

.htaccess

Set document root to be "basic/web"

DocumentRoot "/Applications/XAMPP/xamppfiles/htdocs/basic/web"

<Directory "/Applications/XAMPP/xamppfiles/htdocs/basic/web">

# use mod_rewrite for pretty URL support


RewriteEngine on


RewriteBase /


# If a directory or a file exists, use the request directly


RewriteCond %{REQUEST_FILENAME} &#33;-f


RewriteCond %{REQUEST_FILENAME} &#33;-d


# Otherwise forward the request to index.php


RewriteRule . index.php





# ...other settings...

</Directory>

With the code setup, I get a HHTP 500 error. So do I need to run "yii serve --port=8888" now?

Try this:

httpd.conf


DocumentRoot "/Applications/XAMPP/xamppfiles/htdocs/basic/web/"


<Directory "/Applications/XAMPP/xamppfiles/htdocs/basic/web/">

    Options Indexes FollowSymLinks

    AllowOverride All

    Order allow,deny

    Allow from all

</Directory>



.htaccess


	# use mod_rewrite for pretty URL support

    RewriteEngine on

	RewriteBase /

    # If a directory or a file exists, use the request directly

    RewriteCond %{REQUEST_FILENAME} !-f

    RewriteCond %{REQUEST_FILENAME} !-d

    # Otherwise forward the request to index.php

    RewriteRule . index.php



Put .htaccess in “/Applications/XAMPP/xamppfiles/htdocs/basic/web” if it’s not already there.

Don’t forget to restart Apache!

If your web server is running: no. You don’t need to do that.

You are using the Bitnami virtual machine?

Then you probably should read

https://docs.bitnami…-a-virtual-host

because then you will be able to easily manage your Yii applications.

DigitalOcean has some nice guides as well, that seems to be a bit easier to understand:

https://www.digitalo…buntu-14-04-lts

You can use


apachectl configtest

to check if the config is valid.http://serverfault.com/questions/232145/command-to-check-validity-of-apache-server-config-files#232146

I am actually just using a MAC and running XAMPP and that’s it. I did get the HTTP 500 error resolved but I still have the 404 error on my address book. I also was able to get PrettyURLs to work properly. Do you have any other solutions to resolving my 404 error?

Apache is not easy.

Is it a permission problem in your controller?

Okay, let’s try something else:

Create a new Yii 2 application and swap it out with the one you are having problems with.

If it doesn’t work, then blame it on Apache, otherwise… blame it on your application.