0

I have a Rest API that works on my local machine. But when uploading it to the server I get some errors.

I installed Apache, PHP and the php-cli package.

$ sudo apt install apache2
$ sudo apt install php libapache2-mod-php 
$ sudo apt install php-cli

I enabled the Apache module and mod_rewrite in Apache

$ sudo a2enmod php7.0
$ sudo a2enmod rewrite

I also verified that mod_rewrite is enabled with:

$ ls /etc/apache2/mods-enabled | grep rewrite

And I tested that PHP worked on the web server using SSH

$ sudo wget http://localhost/info.php

My directory v0 contains index.php and .htaccess

When making any request with Postman I get the following errors:

  • The requested URL /APIs/cluvi/v0/employees was not found on this server
  • Apache/2.4.25 (Debian) Server at < EXTERNAL-IP > Port 80

When entering from the browser I get the following error:

  • HTTP ERROR 500

Then I have some observations:

  1. When you delete the .htaccess file the error persists.
  2. When deleting the file index.php the error disappears when I enter the directory v0 from the browser because the contents of the directory are displayed.

I also read that it could be a permissions issue. My permissions set to folders and files are:

$ sudo usermod -a -G www-data your_username
$ sudo chgrp -R www-data /var/www/html 
$ sudo chmod -R g+w /var/www/html

I have deployed APIs with LAMP and I had no problems. But maybe by installing Apache and PHP separately I'm not considering something that I do not realize. Or I have some error in the index.php code that I am not seeing and I would like to know how to debug this HTTP status.


SOLUTION

/var/log/apache2/error_log

PHP Warning:  require_once(webpresentation/views/JsonView.php): failed to open stream: No such file or direct$
PHP Fatal error:  require_once(): Failed opening required 'webpresentation/views/JsonView.php' (include_path=$

Solution: In the URL of the request had a segment of more, which did not exist in the directory structure of the server project. Therefore, the solution was to compare the URL with the directory structure and match them.

PHP Fatal error:  Uncaught Error: Call to undefined function utf8_encode() in /var/www/html/APIs/cluvi/app-cl$

Solution: $ sudo apt-get install php7.0-xml && sudo systemctl restart apache2

And finally I had the following errors:

  • PHP Warning: require_once ...
  • PHP Fatal error: require_once()

Which I solved keeping the require_once () that I had in the application deployed locally.

Finally, my main solution was the use of the file /var/log/apache2/error_log and the installation of php7.0-xml to avoid the HTTP ERROR 500.

Thank you

Braian Coronel
  • 22,105
  • 4
  • 57
  • 62
  • 1
    If the error is 500, then there should be something on the error log of php – Ray A Dec 18 '18 at 08:07
  • You should read the php error logs. I would recommend to create an docker development environment that matches the stack of your server, it will prevent problems like this in the future! – Romano Schoonheim Dec 18 '18 at 08:09
  • http://35.243.140.230/info.php – Braian Coronel Dec 18 '18 at 08:10
  • @RomanoSchoonheim Does LAMP prevent this too? If you have a tutorial to recommend Docker I would read it with pleasure. – Braian Coronel Dec 18 '18 at 08:13
  • When deleting the file index.php the error disappears when I enter the directory v0 from the browser because the contents of the directory are displayed.... it seems you have fatal error in index,php file – Shanteshwar Inde Dec 18 '18 at 08:19
  • 1
    @RomanoSchoonheim Someone is struggling to find their error logs, and you're suggesting *Docker*!? That sounds like telling someone who's just learning to walk to "try running, you'll go faster". The key advice here is to **read the PHP error logs**. – IMSoP Dec 18 '18 at 09:53
  • 1
    @IMSoP I totally agree with you, it was a ridiculous suggestion to use docker to prevent environmental issues. ITDevelopers ignore the docker suggestion, reading the error logs will help you! – Romano Schoonheim Dec 18 '18 at 10:20
  • 1
    @RomanoSchoonheim It's a reasonable suggestion *for someone at a level where they have a chance of succeeding at it*. Docker is not a simple technology, so someone starting out is just going to have a whole new set of headaches trying to understand it. If the question was "I'm migrating from environment X to environment Y and I get this error because of a difference in server configuration" then "try using Docker to minimise the differences when you migrate" might be a good answer; but my impression is the OP in this case isn't at that stage. – IMSoP Dec 18 '18 at 10:29
  • I solved my error using the php log – Braian Coronel Dec 18 '18 at 21:50
  • @ShanteshwarInde There was content displayed because I had SetEnv DEVELOPMENT On – Braian Coronel Dec 18 '18 at 21:52
  • @IMSoP Anyway I have read documentation and displayed Docker images (Jira Unofficial Software) but I wanted to use only what is necessary for this API. And I did not use LAMP because I have the db in another server. – Braian Coronel Dec 18 '18 at 22:01

0 Answers0