According to I install slim on http://localhost/Learn/SlimAPI/API/
I can open slim by localhost:8080 on brownser but when I tried to open it base on location like
http://localhost/Learn/SlimAPI/API/public/
why it’s error
any way I can open it?
Please note, the public/
directory must not be part of the url.
Have you already set up CORS? Setting up CORS
What Should I do when I want to upload my slim PHP to a website and would like to use real URL like
http://www.aaa.com/developer/customer/list
like this
I wrote an article about this topic. Maybe you will find an answer there. Slim 4 - CORS.
You have to check for the allowed hosts. When it’s valid you just send an *
instead.
$response = $response->withHeader('Access-Control-Allow-Origin', '*')
Yes, Now it’s work.
so How can I upload my project to real host on internet and I don’t want to run command like this
php -S localhost:8081 -t public public/index.php
How can I get URL like http://example.com/customer/add ?
You need a webhosting and a domain. You can find it in google.
I know that I mean after I upload slim folder to my wen hosting. what’s the URL of API exmaple I upload slim to htdoc/slim/
You should upload your local project directly into the htdocs/
directory of the webserver. When you upload it into a sub-directory of htdocs/
, then your URL contains the path of that sub-directory. But again, to get a URL as mentioned above, just upload the source directly into the htdocs/
directory and not into htdocs/slim/
.
so for slim I can’t upload to htdocs/slim/
? why ? will it not work?
Of course you can, it’s your server
Your question was how to get a url like http://example.com/customer/add
, and this was my answer to this specific question. When you upload it into htdocs/slim/
then you may have another URL, like http://example.com/slim/customer/add
. Is this what you want?
When I upload it into htdocs/slim/
then my URL is not http://example.com/slim/public/index.php?
so I not need to go to Slim’s public directory, right?
The public/
directory should be the DocumentRoot directory of your webserver and must never be part of the URL. Also index.php
must never be in the URL. public/index.php
is the “front controller” and is the entry point to your Slim application. Is this an Apache webserver? Do you have set up the .htaccess
files? This Slim tutorial explains everything in detail how to configure Slim for Apache. The easiest way for you would be to configure the DocumentRoot to htdocs/public/
or htdocs/slim/public/
. You may ask your webhosting provider how to change this setting.