Laravel api on apache2 ubuntu server 404 not found - laravel

I have a locally created laravel RESTFUL API and I deployed it on my ec2 ubuntu server using git.
I've set it like my main website.. /var/www/api.myapp.com/public_html/myapp-be and for its config I have this /etc/apache2/sites-available/api.myapp.com.conf.
Almost all blogs and tutorials that I found about deploying laravel on apache2 ubuntu server were almost the same and I've followed them all. However, when I test my API on postman with https://api.myapp.com/api/somefunctionhere it says 404 not found, The requested URL was not found on this server. Apache/2.4.29 (Ubuntu) Server at api.myapp.com port 443.
But when I test my local api on postman, it works fine, thus, I confirm that nothing is wrong with my laravel.
My config looks like this
<VirtualHost *:80>
<Directory /var/www/api.myapp.com/public_html/myapp-be/public/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
Require all granted
</Directory>
ServerAdmin developer#myapp.com
ServerName api.myapp.com
Redirect permanent / https://api.myapp.com/
ServerAlias api.myapp.com
DocumentRoot /var/www/api.myapp.com/public_html/myapp-be/public
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/error.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} =api.myapp.com [OR]
RewriteCond %{SERVER_NAME} =api.myapp.com
RewriteRule ^ https://${SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
<VirtualHost *:443>
<Directory /var/www/api.myapp.com/public_html/myapp-be/public/>
AllowOverride All
</Directory>
ServerName api.myapp.com
DocumentRoot /var/www/api.myapp.com/public_html/myapp-be/public
</VirtualHost>
Is there a spot that I missed here? Obviously I missed a spot but I've been looking for it for almost 3hours already and still wont work.
Any idea guys? Thanks!
UPDATE: I tried adding /public to the prefix and it worked, I don't even know why it worked - https://api.myapp.com/public/api/somefunctionhere

Related

Why all the directories of my laravel application is indexed in google?

My application is in Laravel + Vue I'v hosted on Hostinger VPS ubuntu 20.
when I type my site in Google like exptradies.com google showing all the directories as bellow image.
This is my site config
<VirtualHost *:80>
ServerName exptradies.com
ServerAlias www.exptradies.com
ServerAdmin admin#exptradies.com
DocumentRoot /var/www/html/exptradies/public
<Directory /var/www/html/exptradies>
AllowOverride All
Options +FollowSymlinks
Require all granted
ReWriteEngine On
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} =www.exptradies.com [OR]
RewriteCond %{SERVER_NAME} =exptradies.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
Does anyone know What I'm missing in the configuration.
for the ssl I use Letsencypt cerbot.
Your web server is configured to show directory indexes. That shows a web page with a list of files for directory requests when the directory does not contain an index document. You can disable this by using
Options -Indexes
That can either go beneath AllowOverride All or in your .htaccess file.
After making the configuration change you will have to wait a couple weeks for Googlebot to recrawl those pages and stop indexing them.
Add public to your path in Directory and this probably will solve your problem
<Directory /var/www/html/exptradies/public>
AllowOverride All
Options +FollowSymlinks
Require all granted
ReWriteEngine On
</Directory>
Don't forget to restart apache service

Apache2 serve multiple laravel project

I have an ubuntu 22.04 webserver on which i have configured php, mariadb, apache2 stack.
I then deployed a laravel project, which works fine, under the path.
/var/www/html/site1.it
So now I created a project under the path /var/www/html/site2.it and re-executed the same steps done for site1.
So I created the site2.conf, entered the configuration and restarted apache2.
On my mac in the hosts file I then set the IP <-> site pair to reach the site via domain.
However, when I type the url http://site2.it on the browser, I call site1.it
Do you have any suggestions or advice?
EDIT: Steps to configure Apache2 site
I've followed this tutorial:
Deploy Laravel on Apache server
apache site1.conf file:
<VirtualHost *:80>
ServerAdmin site1#localhost
ServerName site1
ServerAlias site1.it
DocumentRoot /var/www/html/site1.it/public
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} =site1.it [OR]
RewriteCond %{SERVER_NAME} =site1
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
#<VirtualHost *:443>
# DocumentRoot /var/www/html/site1.it/public
# ServerName site1
# ServerAlias www.site1.it
# SSLEngine on
# SSLCertificateFile /home/
# SSLCertificateKeyFile /home
#
# <Directory /var/www/html/site1.it/public>
# Order allow,deny
# AllowOverride All
# Allow from all
# </Directory>
#</VirtualHost>

Laravel routes behind reverse proxy generating wrong url

Let me explain my situation. I have a server that host five sites in www/html folder using the Apache 2 server but all of them run on PHP 5.4. I was asked to upload a system on this server, but it uses PHP 7+. The system is dockerized, so it contains their own container running php 7. So, I was thinking in use a reverse proxy to redirect the requests to docker container. Ok, I managed to do it. My container is running and I can access the system in production. But the system is broken, the static files and the routes are not being well formed.
This image shows the error in console. I just hid the IPs.
https://i.stack.imgur.com/5dvVe.png
This my Apache configuration in sites-available folder. I just added the Location tag to redirect for my container.
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
LimitRequestLine 16382
LimitRequestFieldSize 16382
Timeout 12000
AddDefaultCharset ISO-8859-1
SetEnv no-gzip 1
<Directory /var/www/html>
Options -Indexes +FollowSymLinks +MultiViews
AllowOverride All
Require all granted
</Directory>
<Location "/educar">
ProxyPreserveHost On
ProxyPass "http://localhost:8001/educar"
ProxyPassReverse "http://localhost:8001/educar"
</Location>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
This is my first question here, so I just apologized for any mistake.

Apache Multi-Site configuration with SSL - httpd-vhosts.conf , hosts table and .htaccess

My setting is done and it works. Is it the correct way?
I have a Windows server and I installed XAMPP on it. Different domain would point to different IP address to the server. Also, every site runs https on this server. I go through a lot of tutorials and set up self-signed cert to each site.
Then, I configed the server with below setting.
These config works but I am not sure is it secure enough. I afraid that I missed something important.
I need the site to be reachable by below URL:
http://sitea.com (Will redirect to https://sitea.com)
http://www.sitea.com (Will also redirect to https://sitea.com)
https://sitea.com (This great)
https://www.sitea.com (Will force to use non-www version due to program needed- https://sitea.com)
My configuration is listed below. May I ask if it is good enough or if I missed something?
C:\xampp\apache\conf\extra\httpd-vhosts.conf:
<VirtualHost 192.168.242.121:80>
ServerName sitea.com
ServerAlias www.sitea.com
Redirect permanent / https://sitea.com/
</VirtualHost>
<VirtualHost 192.168.242.121:443>
DocumentRoot "S:/websites/sitea/"
ServerName sitea.com
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)(.*) [NC]
RewriteRule (.*) https://%2%{REQUEST_URI} [L,R=301]
SSLEngine on
SSLCertificateFile "ssl/sitea.com/server.crt"
SSLCertificateKeyFile "ssl/sitea.com/server.key"
AccessFileName .htaccess
ErrorLog "S:/websites/sitea/logs/error.log"
CustomLog "S:/websites/sitea/logs/access.log" common
<Directory S:/websites/sitea/>
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
<VirtualHost 192.168.242.120:80>
ServerName siteb.com
ServerAlias www.siteb.com
Redirect permanent / https://siteb.com/
</VirtualHost>
<VirtualHost 192.168.242.120:443>
DocumentRoot "S:/websites/siteb/"
ServerName siteb.com
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)(.*) [NC]
RewriteRule (.*) https://%2%{REQUEST_URI} [L,R=301]
SSLEngine on
SSLCertificateFile "ssl/siteb.com/server.crt"
SSLCertificateKeyFile "ssl/siteb.com/server.key"
AccessFileName .htaccess
ErrorLog "S:/websites/siteb/logs/error.log"
CustomLog "S:/websites/siteb/logs/access.log" common
<Directory S:/websites/siteb/>
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
C:\Windows\System32\drivers\etc\hosts:
192.168.242.121 sitea.com www.sitea.com
192.168.242.120 siteb.com www.siteb.com
Thank you!
Enabling HTTPS on a website does not stop website vulnerabilities, it only secures data which is being transferred between the website server and client i.e. someone can not eaves drop on what the server and client are saying to each other. If a website has a vulnerability people will still be able to exploit it.
In your Apache configuration it looks like some of your apache configurations can be bypassed by accessing your website directly i.e. type it's IP address into a web browser. This would allow someone to bypass your mandated HTTPS for example. You should set up a redirect rule if you want to prevent against this.

Deploy Laravel with LAMP (Ubuntu): Error The requested URL was not found on this server

I try to do my first deploy Laravel 7 + LAMP (Ubuntu).
I succeeded to install Laravel repo I can see my homepage (http://xx.xxx.xx.xxx/).
But when I try to navigate into the website I get this Error:
The requested URL was not found on this server.
I think that i've correctly installed LAMP and Laravel.
The DB is set, I've done the migration.
The problem is probably with the .htaccess, I set my in the repo folder (domain.it/repo):
IfModule mod_rewrite.c>
# That was ONLY to protect you from 500 errors
# if your server did not have mod_rewrite enabled
RewriteEngine On
# RewriteBase /
# NOT needed unless you're using mod_alias to redirect
RewriteCond %{REQUEST_URI} !/public
RewriteRule ^(.*)$ public/$1 [L]
# Direct all requests to /public folder
</IfModule>
And that's my apache2 conf:
<VirtualHost *:80>
<Directory /var/www/html>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ServerAdmin social.legambientecapannori#gmail.com
ServerName legambientecapannoriepianalucchese.it
ServerAlias www.legambientecapannoriepianalucchese.it
DocumentRoot /var/www/legambientecapannoriepianalucchese.it/legambiente/public
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Ah, i've
Thanks in advance
Solved :)
I write the solution for those who will have the same problem
There was an error on the virtual host conf file:
<Directory /var/www/html>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted

Resources