Deployment of api created in lumen at aws server - php

I deploy the project in my regular routine but this time while deploying at aws facing some errors. I deployed there using the ssh command and a key pair at ubuntu 16.04. I installed lamp, PHP, and PHPMyAdmin there successfully.
This is the link and error I am facing http://52.60.197.219/api/category, it says error 404 not found
I tried almost all solutions available but no luck.
Suggestions will be highly appreciated.
my.htaccess file `
Options -MultiViews
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ Api_load.php [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
`
my index.php file named as Api_load.php $app = require __DIR__.'/api/bootstrap/app.php';
$app->run();
structure of a deployed application
API(folder contains all files and codes)
.htaccess,
Api_load.php

yes , its a common error. its all because of conflicting .htaccess file.
Follow these steps.
1)Create Zip of your folder and unzip into the directory you are going to deploy your code.
2)Edit you .env file according to your requirements i.e changing Db username,password and database name.
3).htaccess file and index file in public folder, bring them to the outside of the root directory.
4)now access your baseUrl/endpoint name.
it will work.

Try to solve your problem by adding the config below to /etc/apache2/apache2.conf or site-avaliable/000-default.conf, then restart apache2.
<Directory /home/away/workspace/park/public>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>

Related

Laravel redirecting project to "projectURL/public/public"

first of all this are my laravel and PHP versions:
Laravel Framework 7.17.2
PHP 7.3.19 (cli)
I am having a wierd problem with my laravel project:
in my vhost file I have:
<VirtualHost *:80>
ServerName www.name.test
DocumentRoot "C:\web\name\name\backend\public"
</VirtualHost>
in the hosts file:
127.0.0.1 www.name.test
when trying to acces the project by typing:
http://www.name.test
it redirects me to the url
http://www.name.test/public/public
I have .htaccess in my root folder and in the public folder with the following :
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Send Requests To Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
I dont know why this started to happen, previously it was working fine but sth I gues was changed accidentally on the project since it happens in everycomputer, so it does not look like a php configuration problem.
hope someone can give some tip about the issue.
There are 2 ways to fix this issue:
Step 1:
Just rename your server.php to index.php file present in your project root directory.
Step 2:
Copy index.php present inside public folder of your project root directory and paste it inside the root directory. Make sure there is no other index.php present before.
Then replace these 2 lines:
require __DIR__.'/../vendor/autoload.php';
require_once __DIR__.'/../bootstrap/app.php';
with
require __DIR__.'/vendor/autoload.php';
require_once __DIR__.'/bootstrap/app.php';
Hope either of the 2 ways helps!!

Laravel giving 500 internal error on Shared hosting

I have an laravel app working fine on my local machine. I have just transferred it to my server (Shared hosting) and put everything on a public folder in public_html and everything else in one step above public_html. The problem is now it shows 500 internal error on every route. I have changed .htaccess code to given code on documentation, folder rights to storage and bootstrap are set to 777.
Nothing in error logs and also nothing in laravel log files. when I installed fresh laravel installation it worked on the server as well. Tried updated code with my project but still 500 internal error.
For Laravel 8 / IONOS Managed Server this works for me:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteBase /
Options +FollowSymLinks
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Send Requests To Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
If you are using IONOS (or 1and1, maybe works fot other too...), the .htaccess file should be different from the default in laravel public directory.
Replace its content with this:
RewriteBase /
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
The error may be due to the configuration of .env file.As your question is not clear enough. so i wil explain 2 methods
With vendor and .env file (Not Recomended)
- Unzip the main zip file and upload your public_html folder ( upload
vendor folder as well)
Give 777 recursive permission to storage/ and bootstrap/ folder
Create database in phpmyadmin and import .sql file
Set Database in .env file
Now normally for all shared hostings you will have jailed SSH you can contact the hosting provider to get its details.
Once you get access , use command
php artisan cache:clear
php artisan config:clear
php artisan config:cache
The file itself can be found in bootstrap/cache/config.php.
Note that the location of the compiled config file has changed recently. Yours might also be in vendor/config.php or storage/framework/config.php. With a fresh install or if you run composer update the file should be in bootstrap/cache though.
Now Directly from GIT or other Sources without Vendor(Recommended)
Make sure you copy all of the project files including the hidden ones(.env).
if You are using GIT use GIT clone to clone the project.
Check you have all the necessary PHP extensions available in php.ini as in Laravel requirements. Also, watch your PHP version!
Install composer https://getcomposer.org/doc/00-intro.md
When copied, go to your destination folder and run composer install.
Run php artisan key:generate from the command line.
then Run
php artisan cache:clear
php artisan config:clear
php artisan config:cache
http://php.net/manual/en/install.windows.commandline.php
Make sure your webserver is serving pages from project/public folder.
Even after completing these steps if Laravel is still showing error, check
your_project/storage/logs/laravel.log
Laravel default .htacces won't work for IONOS.
This is the perfect .htaccess
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteBase /
Options +FollowSymLinks
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Send Requests To Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>

Can't deploy laravel 5.6.7 project to a subdomain on a web server

I keep getting 500 error when I try to access laravel application on subdomain of a web server.
I have uploaded entire laravel project into a public_html/laravel directory. Document root points to public_html/laravel/public.
I've added 755 permissions to bootstrap and storage directories.
Laravel version: 5.6.7, php version on my machine: 7.1.11. Web server php version 7.0
What can cause this problem?
Differences between php versions?
.htaccess file:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
Edit:
Now I've changed document root to point to public_html/laravel and when I add /public i get 'no input specified' error and error log file looks like this:
Got error "Unable to open primary script: /home/user/public_html/laravel/public/index.php(no such file or directory)"
Final Edit: The problem was php version.
try
chown -R apache:apache /home/user/public_html/laravel/
It's your PHP version. Laravel 5.6 needs PHP >= 7.1.3.
First of all you should update the php version to PHP>=7.0 and secondly if there is a cache problem then you must run this command php artisan config:cache to clear the old configuration for local server. I faced this issue alot and i hope it will help you and others who would have same issue.

Deploying laravel 5.4 project in shared host

I‘m facing some problems with my Laravel 5.4 project. I’ve created my project on localhost everything is working, no problems. Now I need this project to work on shared host. So, I rent a server, create database, create a folder in the same level as public_html, upload all files and folders (except public folder and its content) in this folder. Public folder content I put in public_html folder. I also make changes in my index.php file in public folder and changed two lines:
require __DIR__.'/../my_folder/bootstrap/autoload.php';
$app = require_once __DIR__.'/../my_folder/bootstrap/app.php';
In .env file besides database connection lines, I’ve also changed line DB_HOST=127.0.0.1 to DB_HOST=localhost
When I try to run my project on shared host, the starting page works perfect, but when I try to navigate to other pages, I‘m getting error connecting with routes (NotFoundHttpException in RouteCollection.php)
My .httacces file content is:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
Maybe I need some changes here? I really appreciate any help.

How to run laravel in root directory without the public folder?

I am running the latest version of laravel on my own server running Debian and Apache2.
The contents of laravel are located in /var/www which is what my domain name is pointed to however all of the functionality happens through the public directory so I would have to go to http://mydomain.com/public to access anything.
I would like to change it so that I only have to access http://mydomain.com. Is this possible?
How can I change this? Would I have to move everything up another level to the parent at /var?
I haven't found anything online so far that says that it is possible, or that it is a good idea.
That is not your problem, you need to point the virtual host to the public folder.
The following worked for me, as discussed here: https://stackoverflow.com/a/16569078/3091980
Move all contents of the /public folder down a level. Then update the include lines in index.php to point to the correct location - if it's down a level, remove the "../".
Sorry I deleted my old answer .. that was if u rename server.php to index then it will work but of course not because laarvel not load all service. so you have to paste into root all public folder file. and remove "../" from everywhere in index.php
Add a file in laravel root directory, name it as .htaccess and put this inside,
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ ^$1 [N]
RewriteCond %{REQUEST_URI} (\.\w+$) [NC]
RewriteRule ^(.*)$ public/$1
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ server.php
It will be fixed surely.
Locate your httpd.conf and change the part that DocumentRoot "/var/www" to "/var/www/public" and override directory to allow .htaccess file of laravel
...
DocumentRoot "/var/www/public"
...
<Directory "/var/www/public">
AllowOverride None
Options None
Order allow,deny
Allow from all
</Directory>
...

Categories