davellanedam / phalcon-micro-rest-api-skeleton

This is a basic API REST skeleton written on Phalcon PHP. Great For building an MVP for your frontend app (Vue, react, angular, or anything that can consume an API)
MIT License
57 stars 20 forks source link

Unable to setup this skeleton #4

Closed amsharma9 closed 6 years ago

amsharma9 commented 6 years ago

Hi,

I am using Wamp on Windows 7, 64bit. I setup the whole project by downloading zip file and setting it up. Ran Composer. I setup the database connection details in server.development.php. The setting SetEnv APPLICATION_ENV "development" doesn't work in Windows so I have setup a Environment variable for the same.

I haven't modified app.php. I am just trying to get it the basic website going so that I can do more. It keeps giving 500 "Internal Server Error". I have modified the .htaccess and cleaned it, just leaving basic commands but still this error doesn't go away. There is nothing in Apache or PHP error logs.

Do I need to setup some of the Postman configuration. I have no knowledge of that. I did have a look at that file. I haven't touched the ACL files also. I just want to first see index.phmtl to know everything is working fine. Then I will go to next step. I am working on REST API for the first time so kindly pardon my ignorance.

Amal

davellanedam commented 6 years ago

Hello Amal, no worries, thank you for trying this! Will you please check if you have at least PhalconPHP 3.2+ installed? You can do that by checking phpinfo() function. Also you should set a virtual host for testing, for example: my http://project.local point it to the root of the project, it will make you life easy. Please restore .htaccess file, every line is mandatory to make this work. If you are still getting error 500, please attach a screenshot of the browser.

amsharma9 commented 6 years ago

Sorry I missed out mentioning the versions: Phalcon 3.4 Apache 2.4.23 PHP 7,0.10 MySQL 5.7.14

I have setup a virtual host http://restapi.local but it still gave the 500 error. Image attached.

If I add the below line in .htaccess as mentioned in your setup guidelines then I get error shown below in Apache error log. SetEnv APPLICATION_ENV "development"

[Mon Aug 06 11:27:35.040683 2018] [core:alert] [pid 4492:tid 932] [client 127.0.0.1:51846] C:/Wamp/www/restapi/public/.htaccess: Invalid command 'Header', perhaps misspelled or defined by a module not included in the server configuration
davellanedam commented 6 years ago

Are you able to run phpinfo() function and get info? You should do it in a different project just to check if it runs, you should see phalconPHP installed like this. Also the virtual host project must point to the root of the project, not the public folder.

amsharma9 commented 6 years ago

Yes, I can see phpinfo() output as you mentioned. I have another project in Phalcon which works fine. My C:\Wamp\bin\apache\apache2.4.23\conf\extra\httpd-vhosts.conf file has an entry for each virtual host. It points to the root folder.

<VirtualHost *:80>
    ServerName restapi.local
    DocumentRoot "c:/wamp/www/restapi"
    <Directory  "c:/wamp/www/restapi/">
        Options +Indexes +Includes +FollowSymLinks +MultiViews
        AllowOverride All
        Require local
    </Directory>
</VirtualHost>
amsharma9 commented 6 years ago

Ok, it worked. I can see the first API page now. I have commented out below lines in C:\Wamp\www\restapi\public\.htaccess. This is the .htaccess in public folder. It was giving the same "Header" error I mentioned above.

#AddDefaultCharset UTF-8

#SetEnv APPLICATION_ENV "development"

#CORS
#Header always set Access-Control-Allow-Origin: "*"
#Header always set Access-Control-Allow-Headers: "Origin, X-Requested-With, Content-Type, Access-Control-Allow-Origin, Authorization, Accept, X-Accept-Charset, X-Accept, Client-Security-Token"
#Header always set Access-Control-Allow-Methods: "POST, GET, PUT, OPTIONS, PATCH, DELETE"
#Header always set Access-Control-Allow-Credentials: "true"
#Header always set Access-Control-Max-Age: "1000"

Are these lines essential for its functioning?

davellanedam commented 6 years ago

Yes, those are essential, without them it won't work. First line is for character encoding, second to set environment, and the other are for making requests to the API from anywhere and enabling requests with token. Looks like the problem is in your Apache somewhere. I think you have to search the Internet for problems with .htaccess and "Header" in apache to see what's going on. Please keep me posted.

davellanedam commented 6 years ago

Can you try changing to this options in you virtual host configuration please? And then restore the .htaccess to its original.

<VirtualHost *:80>
  ServerName restapi.local
  DocumentRoot "c:/wamp/www/restapi"
  <Directory  "c:/wamp/www/restapi/">
    Allow From All
    AllowOverride All
    Options +Indexes
    Require all granted
  </Directory>
</VirtualHost>
amsharma9 commented 6 years ago

@davellanedam I tried the commands you mentioned. It didn't help. Its working now with all commands. I had to enable the headers_module in Apache. It wasn't enabled. Now to the second step, how to get a model to show up as API.

davellanedam commented 6 years ago

Oh great news! From now on its just to follow up the guide and you are done. Thank you trying this again. If you need any help please open another issue. Enjoy.

amsharma9 commented 6 years ago

Thanks for you prompt help @davellanedam and its great that you are so keen to help. Its very nice of you. I will probably trouble you again with my queries.