I am trying to create a Rest API in PHP, and I would like to use a framework. I have followed several tutorials on the subject. Despite my efforts, I am unable to get any of them to work, for either cakephp or codeigniter. The sites that contain these tutorials have numerous comments attached from people giving compliments to the writer. So I believe somebody got them to work.
Here is one example of what I have done: I built the Rest application according to this tutorial http://www.bravo-kernel.com/2015/04/how-to-build-a-cakephp-3-rest-api-in-minutes/ using composer to install my plugins and extensions. I did all of this under the directory path /var/www/html/cakephp/cake3api_app/. I built the cocktails table in my database, and I reconfigured config/app.php to have access to it. I opened up my FireFox web browser, and accessed the index page. Among other things, it had this output:
Please be aware that this page will not be shown if you turn off debug mode unless you replace src/Template/Pages/home.ctp with your own version.
URL rewriting is not properly configured on your server.
1) Help me configure it
2) I don't / can't use URL rewriting
Environment
Your version of PHP is 5.5.9 or higher (detected 5.6.20-0+deb8u1).
Your version of PHP has the mbstring extension loaded.
Your version of PHP has the openssl extension loaded.
Your version of PHP has the intl extension loaded.
Filesystem
Your tmp directory is writable.
Your logs directory is writable.
The FileEngine is being used for core caching. To change the config edit config/app.php
Database
CakePHP is able to connect to the database.
DebugKit
DebugKit is loaded.
I go to my Rest client and enter a local host URL that I can't post due to lack of reputation (localhost "slash" cakephp "slash" cake3api_app "slash" cocktails), and this is what it gave me:
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>404 Not Found</title>
</head><body>
<h1>Not Found</h1>
<p>The requested URL /cakephp/cake3api_app/cocktails was not found on this server.</p>
<hr>
<address>Apache/2.4.10 (Debian) Server at localhost Port 80</address>
</body></html>
I assume (perhaps incorrectly) this is because I need to configure my URL rewriting on Apache. I followed the URL given by the aforementioned CakePHP debug page (lack of reputation prevents me from posting the link), and it is all Greek to me. It seems I need to write what the page is talking about to an .htaccess file, but I am unsure which one, and also where in the .htaccess file I need to write it. There are several .htaccess files that come with CakePHP and the zipped tutorial code from GitHub has several of its own.
So my question is this: What do I need to do in order to make the code in question work in such a way that I can type a URL into my browser and it gives me JSON data in return?
The source code to the tutorial can be found here: https://github.com/bravo-kernel/application-examples/tree/master/blog-how-to-build-a-cakephp3-rest-api
Edit:
I changed the lines in /etc/apache2/apache2.conf that read "AllowOverride None" to read "AllowOverride All", but this had no effect.
Adding "LoadModule rewrite_module libexec/apache2/mod_rewrite.so" to /etc/apache2/apache2.conf broke apache, but adding it to the .htaccess at the CakePHP application root has no effect.
The file /etc/apache2/sites-available/default did not exist on my machine, but creating it and adding the code listed on the CakePHP book page had no effect.
There was not an app/ directory in the CakePHP application, but creating one and adding an .htaccess file to it with the contents specified in the CakePHP book had no effect.
Adding the line "RewriteBase /var/www/html/cakephp/cake3api_app/" to the .htaccess file in the webroot directory had no effect.
I restarted Apache after each of these changes.