# Problem with tutorial first app exaple

**URL:** <https://discourse.slimframework.com/t/problem-with-tutorial-first-app-exaple/1317>\
**Category:** Questions\
**Created:** [March 24, 2017, 4:43pm UTC](https://discourse.slimframework.com/t/problem-with-tutorial-first-app-exaple/1317 "2017-03-24T16:43:29Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![mangel](https://avatars.discourse-cdn.com/v4/letter/m/a698b9/32.png) [@mangel](https://discourse.slimframework.com/u/mangel)\
**Post date:** [March 24, 2017, 4:43pm UTC](https://discourse.slimframework.com/t/problem-with-tutorial-first-app-exaple/1317/1 "2017-03-24T16:43:29Z")

</div>

Hello everyone, i try to explain my problem.  
I’m new with slim and i started to follow the tutorial , but it doesn’t work.  
Oh better it’s work if i don’t use the request e response.  
I started with the code of tutorial and that doesn’t work i have that result

at this url : mylocalhost/hello/someone  
_Not Found_  
_The requested URL /mylocalhost/hello/someone was not found on this server._  
_Apache/2.4.18 (Ubuntu) Server at mylocalhost Port 80_

**i tested my virtual host and it work, infact with this code it’s work:**

require ‘vendor/autoload.php’;  
$app = new \Slim\App;  
**$app-\>get(’/’, function ()** {  
echo “Hello”;  
});  
$app-\>run();  
at url  
mylocalhost/  
**it’s work i can see hello in my screen!**

**but if i try to put a root like:**  
$app-\>get(’/hello’, function () {

and i put this url on browser o try with postman  
**mylocalhost/hello**  
**it’s dosn’t work and i have**  
_Not Found_  
_The requested URL /mylocalhost/hello/someone was not found on this server._  
_Apache/2.4.18 (Ubuntu) Server at mylocalhost Port 80_

if i try mylocalhost/ i have  
_Page Not Found_  
_The page you are looking for could not be found. Check the address bar to ensure your URL is spelled correctly. If all else fails, you can visit our home page at the link below._  
_Visit the Home Page_

i had .htacces like this  
RewriteEngine on  
RewriteCond %{REQUEST\_FILENAME} !-d  
RewriteCond %{REQUEST\_FILENAME} !-f  
RewriteRule . index.php [L]

where i make mistake? plese help me !  
thank

---

<div class="post-metadata">

**Author:** ![tflight](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/tflight/32/1205_2.png) [@tflight](https://discourse.slimframework.com/u/tflight)\
**Post date:** [March 24, 2017, 5:03pm UTC](https://discourse.slimframework.com/t/problem-with-tutorial-first-app-exaple/1317/2 "2017-03-24T17:03:45Z")

</div>

What does your directory structure look like? Is your front controller (index.php) running inside a `mylocalhost` folder within your `public` or `public_html` folder? It looks like you might be trying to run Slim from within a subdirectory of your document root.

---

<div class="post-metadata">

**Author:** ![mangel](https://avatars.discourse-cdn.com/v4/letter/m/a698b9/32.png) [@mangel](https://discourse.slimframework.com/u/mangel)\
**Post date:** [March 24, 2017, 5:22pm UTC](https://discourse.slimframework.com/t/problem-with-tutorial-first-app-exaple/1317/3 "2017-03-24T17:22:39Z")

</div>

my index.php is in my document root  
my document root have public permits

---

<div class="post-metadata">

**Author:** ![tflight](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/tflight/32/1205_2.png) [@tflight](https://discourse.slimframework.com/u/tflight)\
**Post date:** [March 24, 2017, 5:30pm UTC](https://discourse.slimframework.com/t/problem-with-tutorial-first-app-exaple/1317/4 "2017-03-24T17:30:48Z")

</div>

Okay. I’m not sure why you are trying to access `mylocalhost/hello` when the route is `'/hello'` instead of the URL `/hello`. Since you haven’t defined a route that begins with `/mylocalhost`, any URLs that try to go there will not be found.

---

<div class="post-metadata">

**Author:** ![mangel](https://avatars.discourse-cdn.com/v4/letter/m/a698b9/32.png) [@mangel](https://discourse.slimframework.com/u/mangel)\
**Post date:** [March 24, 2017, 5:46pm UTC](https://discourse.slimframework.com/t/problem-with-tutorial-first-app-exaple/1317/5 "2017-03-24T17:46:20Z")

</div>

i no undestund sorry  
if i put in route  
$app-\>get(’/’, function () {  
the string “/” is mylocalhost isent’t it?  
and if i write  
$app-\>get(’/hello’, function () {  
the string "/hello  
is for all route “mylocalhot/hello” isnt’it?

i have to create the subdirectory /hello into my project?  
sorry but i realy not undestund  
thank for your interesting

---

<div class="post-metadata">

**Author:** ![tflight](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/tflight/32/1205_2.png) [@tflight](https://discourse.slimframework.com/u/tflight)\
**Post date:** [March 24, 2017, 8:45pm UTC](https://discourse.slimframework.com/t/problem-with-tutorial-first-app-exaple/1317/6 "2017-03-24T20:45:55Z")

</div>

No, you should not create a subdirectory in your project.

```php
$app->get('/', function () {
    // would respond to something like http://example.com/
}
$app->get('/home', function () {
    // would respond to something like http://example.com/home
}
$app->get('/home/{name}', function () {
    // would respond to something like http://example.com/home/mangel
    // or would also respond to http://example.com/home/tflight
}

```

Or if using something like MAMP

```php
$app->get('/', function () {
    // would respond to something like http://localhost:8080/
}
$app->get('/home', function () {
    // would respond to something like http://localhost:8080/home
}
$app->get('/home/{name}', function () {
    // would respond to something like http://localhost:8080/home/mangel
    // or would also respond to http://localhost:8080/home/tflight
}

```

---

<div class="post-metadata">

**Author:** ![mangel](https://avatars.discourse-cdn.com/v4/letter/m/a698b9/32.png) [@mangel](https://discourse.slimframework.com/u/mangel)\
**Post date:** [March 27, 2017, 4:10pm UTC](https://discourse.slimframework.com/t/problem-with-tutorial-first-app-exaple/1317/7 "2017-03-27T16:10:59Z")

</div>

that is that i do… but dosn’t work i no undestund why… o better

$app-\>get(’/’, function () {  
// would respond to something like [http://example.com/](http://example.com/)  
that-s work  
but

$app-\>get(’/home’, function () {  
// would respond to something like [http://example.com/home](http://example.com/home)  
}  
dosent’t work…

i try to explain better  
DocumentRoot /var/www/html/htdocs/myprogect

into /var/www/html/htdocs/myprogect i have index.php

ServerName matteo.local  
now if i write in code  
$app-\>get(’/’, function () {…  
and i do matteo.local  
it’s work  
but if i write in code  
$app-\>get(’/hello’, function () {  
and i try  
matteo.local/hello  
it-s dosn’t work

---

<div class="post-metadata">

**Author:** ![tflight](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/tflight/32/1205_2.png) [@tflight](https://discourse.slimframework.com/u/tflight)\
**Post date:** [March 27, 2017, 4:28pm UTC](https://discourse.slimframework.com/t/problem-with-tutorial-first-app-exaple/1317/8 "2017-03-27T16:28:44Z")

</div>

Have you turned on `AllowOverride All` in Apache? Can you be certain your `.htaccess` file is being loaded?

One way to check quickly would be to change your `.htaccess` file to say anything invalid. For example just put the word hello in and save. If you load [http://matteo.local](http://matteo.local) and it _doesn’t_ fail, then your .htaccess file is not being properly loaded.

---

<div class="post-metadata">

**Author:** ![mangel](https://avatars.discourse-cdn.com/v4/letter/m/a698b9/32.png) [@mangel](https://discourse.slimframework.com/u/mangel)\
**Post date:** [March 27, 2017, 5:11pm UTC](https://discourse.slimframework.com/t/problem-with-tutorial-first-app-exaple/1317/9 "2017-03-27T17:11:47Z")

</div>

Yes i have turned on AllowOverride All

 Require all granted AllowOverride All Order allow,deny Allow from all 

i try to change my .htaccess but nothing happend all wark like before… isn’t load?  
what can i will do?

my .htaccess is chmod 775

---

<div class="post-metadata">

**Author:** ![tflight](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/tflight/32/1205_2.png) [@tflight](https://discourse.slimframework.com/u/tflight)\
**Post date:** [March 27, 2017, 5:59pm UTC](https://discourse.slimframework.com/t/problem-with-tutorial-first-app-exaple/1317/10 "2017-03-27T17:59:50Z")

</div>

If you intentionally broke your .htaccess like I suggested and you still get the same result (working for the / route but not for /hello) then that leads me to believe your .htaccess file is not being loaded. How did you install Apache?

---

<div class="post-metadata">

**Author:** ![mangel](https://avatars.discourse-cdn.com/v4/letter/m/a698b9/32.png) [@mangel](https://discourse.slimframework.com/u/mangel)\
**Post date:** [April 3, 2017, 8:57am UTC](https://discourse.slimframework.com/t/problem-with-tutorial-first-app-exaple/1317/11 "2017-04-03T08:57:59Z")

</div>

i don’t remember, but probably i installed LAMP, but i had resolve in part…  
I looked the file apache2.conf and i change AllowOverride All , sorry  
i before had change only in file. conf for virtualHost and i forgot apache2.conf,  
I had change now and i set again my .htaccess and now work! but work only if i put index.php in url  
mylocalhost/hello/matteo dasent work  
mylocalhost/index.php/hello/matteo work

---

<div class="post-metadata">

**Author:** ![tflight](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/tflight/32/1205_2.png) [@tflight](https://discourse.slimframework.com/u/tflight)\
**Post date:** [April 3, 2017, 10:58am UTC](https://discourse.slimframework.com/t/problem-with-tutorial-first-app-exaple/1317/12 "2017-04-03T10:58:48Z")

</div>

Something isn’t correct with your Apache setup. I noticed the config you put in your `.htaccess` is different from what is recommended. Try this, exactly.

```auto
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [QSA,L]

```

Otherwise, it might be a good idea to reinstall Apache with a known good config.

---

<div class="post-metadata">

**Author:** ![mangel](https://avatars.discourse-cdn.com/v4/letter/m/a698b9/32.png) [@mangel](https://discourse.slimframework.com/u/mangel)\
**Post date:** [April 3, 2017, 11:41am UTC](https://discourse.slimframework.com/t/problem-with-tutorial-first-app-exaple/1317/13 "2017-04-03T11:41:14Z")

</div>

I do it and dosn’t work, i try again to modyfy .htaccess and write “hello” and anything cange,  
my apache dosn’t load .htaccess  
now it work with MyLocalHost/index.php/hello/matteo  
probably because i change in apache2.conf  
AllowOverride All  
but .htaccess dosn’t load  
but  
MyLocalHost/hello/matteo dosn’t work

Ok i’ll try to reinstall apache
