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:
- When you delete the .htaccess file the error persists.
- 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 ofphp7.0-xml
to avoid the HTTP ERROR 500.
Thank you