How to access a laravel api in apache virtual host? - laravel

I have set up apache virtual host and have a site with below config (the website is working well):
NB: The domain names below fictitious.
<VirtualHost *:80>
ServerName www.bill.test.com
ServerAlias bill.test.com
Redirect / https://bill.test.com/
</VirtualHost>
<VirtualHost *:443>
ServerName www.bill.test.com
ServerAlias bill.test.com
DocumentRoot /applications/www/bill.test.com/public_html/public
SSLEngine on
SSLCertificateFile /home/user1/ssl_certificate/test.com/wildcard_eneoapps_com.crt
SSLCertificateKeyFile /home/user1/ssl_certificate/test.com/wildcard_eneoapps_com.key
SSLCertificateChainFile /home/user1/ssl_certificate/test.com/DigiCertCA.crt
ErrorLog /applications/www/bill.test.com/error.log
CustomLog /applications/www/bill.test.com/requests.log combined
<Directory "/applications/www/bill.test.com/public_html/public">
AllowOverride All
</Directory>
</VirtualHost>
Also, on this server I have an API located in the directory below:
/applications/www/html/ebill-api
Now when I try to call this API in the code, I get the error below:
Client error: `POST http://12.ipp.106.21/ebill-api/public/api/login' resulted in a `404 Not Found` response:\n
My httpd.conf file looks like below:
DocumentRoot "/applications/www/html"
#
# Relax access to content within /var/www.
#
<Directory "/applications/www">
AllowOverride None
# Allow open access:
Require all granted
</Directory>
# Further relax access to the default document root:
<Directory "/var/www/html">
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important. Please see
# http://httpd.apache.org/docs/2.4/mod/core.html#options
# for more information.
#
Options Indexes FollowSymLinks
#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
AllowOverride None
#
# Controls who can get stuff from this server.
#
Require all granted
</Directory>
Please help as I am new to configuring apache and confuse why this doesn't work. I was able to call an API on a separate
server but I don't understand why calling this one which is on thesame server as the website is not working.

Since you have the Laravel api in a subfolder, you should adjust the APP_URL in your .env file to be http://12.ipp.106.21/ebill-api/public/
Try this change. See if it help.

Related

Apache2 setup macOS Monterey error Forbidden

I'm looking for a way to use multiple DocumentRoots on the local Apache server of MacOs Monterey. localhost works very well but for the other locations I have an error "Forbidden You don't have permission to access this resource."
I tried to use VirtualHost but it doesn't work
httpd.conf
ServerName localhost:80
#
# Deny access to the entirety of your server's filesystem. You must
# explicitly permit access to web content directories in other
# <Directory> blocks below.
#
<Directory />
AllowOverride none
Require all denied
</Directory>
#
# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
#
DocumentRoot "/Library/WebServer/Documents"
<Directory "/Library/WebServer/Documents">
Options FollowSymLinks Multiviews
MultiviewsMatch Any
AllowOverride All
Require all granted
</Directory>
<IfModule dir_module>
DirectoryIndex index.html
</IfModule>
<Directory "/Library/WebServer/CGI-Executables">
AllowOverride None
Options None
Require all granted
</Directory>
Include /private/etc/apache2/other/*.conf
extra/httpd-vhosts.conf
# Virtual Hosts
Listen 80
<VirtualHost *:80>
ServerName localhost
DocumentRoot "/Library/WebServer/Documents"
</VirtualHost>
<VirtualHost *:80>
ServerAdmin example#example.com
DocumentRoot "/Users/TooikLeChevalier/Documents/IUT/S3/Prog-Web-Serveur"
ServerName iut.local
# ServerAlias iut
ErrorLog "/Users/TooikLeChevalier/Documents/IUT/S3/Prog-Web-Serveur/crash_log/Error"
CustomLog "/Users/TooikLeChevalier/Documents/IUT/S3/Prog-Web-Serveur/crash_log/Custom" common
<Directory "/Users/TooikLeChevalier/Documents/IUT/S3/Prog-Web-Serveur">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerAdmin example#example.com
DocumentRoot "/Users/TooikLeChevalier/Documents/Perso/EclypseGames/Local_Dev"
ServerName eclypsegames.local
ErrorLog "/Users/TooikLeChevalier/Documents/Perso/EclypseGames/Local_Dev/crash_log/Error"
CustomLog "/Users/TooikLeChevalier/Documents/Perso/EclypseGames/Local_Dev/crash_log/Custom" common
<Directory "/Users/TooikLeChevalier/Documents/Perso/EclypseGames/Local_Dev">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
../hosts
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
127.0.0.1 iut.local
127.0.0.1 eclypsegames.local
I have enclosed with you all the documents that could be useful in solving my problem.
Thanks in advance for your help

How to set up a virtual host on ubuntu

I am trying to make to move to use Ubuntu for developing. I am working on an exciting Laravel project that is due to go live at the end of the month. I have cloned the repro and now trying to set up a virtual host ( my understanding is that you need this for the site work properly locally ). I have followed this video: https://www.youtube.com/watch?v=lkLAJd-Wb80&t=6s. But all I am getting is a 404 page not found. Hope someone can help with this.
<VirtualHost *:80>
<Directory /var/www/html/myapp/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
ServerName myapp.test
ServerAdmin info#myapp
DocumentRoot /var/www/html/myapp/public
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
I have also added myapp to the hosts file.
You missed the public directory while defining the path in <Directory>. It should be something like this:
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
ServerAdmin info#myapp
ServerName myapp.test
ServerAlias myapp.test
DocumentRoot /var/www/html/myapp/public
<Directory /var/www/html/myapp/public>
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
Allow from all
Require all granted
</Directory>
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>
Hope this helps you.
Could you try with listening to 80 port like below?
Listen 80
<VirtualHost *:80>
<Directory /var/www/html/myapp/public>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
ServerName myapp.test
ServerAdmin info#myapp
DocumentRoot /var/www/html/myapp/public
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
My virtual host configuration is like bellow where I used 8080 port.
Listen 8080
<VirtualHost *:8080>
ServerAdmin info#gmail.com
DocumentRoot "D:/appinstall/htdocs/www/app-test-server/public"
ServerName localhost
ErrorLog "logs/app-test-server.log"
CustomLog "logs/app-test-server.log" common
</VirtualHost>

How to serve different web apps using one domain name in Apache?

I'm currently trying to deploy my Django 2.0 App on an Apache Web Server. However I'm experiencing difficulties in configuring it because my Virtual Host configuration overrides other Virtual Hosts which is used by other projects (Ruby and PHP WebApps). We only have one domain name at the moment so I cannot use other domain names to host my app.
Is it possible to serve different kind of apps with one domain name using Apache Virtual Hosts?
Since you can only have 1 VirtualHost (one domain, one port, one IP), you cannot create additionnal VH. You need to "split" the paths to the different applications some other way.
Let assume www.example.com:
ServerRoot "/some/path/apache"
[...] OTHER LoadModule directives [...]
LoadModule alias_module modules/mod_alias.so
Listen *:80
<VirtualHost *:80>
ServerName www.example.com
ServerAlias example.com
# Logs
LogLevel warn
CustomLog "logs/www.example.com_access-log" combined
ErrorLog "logs/www.example.com_error-log"
# Index file. Add as many as required for your applications
<IfModule dir_module>
DirectoryIndex index.html
</IfModule>
# Where the documents are
DocumentRoot "/some/path/apache/htdocs"
<Directory />
Options FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
</Directory>
<Directory "/some/path/apache/htdocs">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
This VirtualHost is a basic configuration for the www.example.com domain. Now you want to have Ruby, PHP WebApps and Django 2.0 App under that single domain. You have 3 choices:
Get 1 domain per application, not applicable here, that is your question.
Make a sub-directory in htdocs, and a path in the URI for each application.
Put each application in some directory, not under DocumentRoot and use Alias.
Use sub-domains.
Not applicable.
Sub-directory and path
Create /some/path/apache/htdocs/Ruby, put your Ruby app. here.
Will be accessed via http://www.example.com/Ruby
Create /some/path/apache/htdocs/PHPWebApps, put your PHP app. here.
Will be accessed via http://www.example.com/PHPWebApps
Create /some/path/apache/htdocs/Django, put your Django app. here.
Will be accessed via http://www.example.com/Django
The URI value must match the directory value.
In some directory, use Alias
If you do not need, or want the URI to match the directory name (like in 2.), use Alias.
Create /SOME_DIR_FOR_Ruby, put your Ruby app. here.
Add Alias "/Ruby" "/SOME-DIR-FOR-Ruby"
Will be accessed via http://www.example.com/Ruby
Create /SOME_DIR_FOR_PHPWebApps, put your PHP app. here.
Add Alias "/PHPWebApps" "/SOME_DIR_FOR_PHPWebApps"
Will be accessed via http://www.example.com/PHPWebApps
Create /SOME_DIR_FOR_Django, put your Django app. here.
Add Alias "/Django" "/SOME_DIR_FOR_Django"
Will be accessed via http://www.example.com/Django
Use sub-domains
This is where you could use multiple VirtualHosts. But you have to be able to create sub-domains. This is done either via a DNS configuration, or through your hosting provider.
You could setup http://ruby.example.com, http://php.example.com, http://django.example.com. Each of these will have 1 VirtualHost, but will all be mapped to the same IP in the DNS.
Then setup 3 VH:
<VirtualHost *:80>
ServerName ruby.example.com
# Logs
LogLevel warn
CustomLog "logs/ruby.example.com_access-log" combined
ErrorLog "logs/ruby.example.com_error-log"
# Index file. Add as many as required for your applications
<IfModule dir_module>
DirectoryIndex index.html
</IfModule>
# Where the documents are
DocumentRoot "/some/path/apache/htdocs/Ruby"
<Directory />
Options FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
</Directory>
<Directory "/some/path/apache/htdocs/Ruby">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName php.example.com
# Logs
LogLevel warn
CustomLog "logs/php.example.com_access-log" combined
ErrorLog "logs/php.example.com_error-log"
# Index file. Add as many as required for your applications
<IfModule dir_module>
DirectoryIndex index.html
</IfModule>
# Where the documents are
DocumentRoot "/some/path/apache/htdocs/php"
<Directory />
Options FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
</Directory>
<Directory "/some/path/apache/htdocs/php">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName django.example.com
# Logs
LogLevel warn
CustomLog "logs/django.example.com_access-log" combined
ErrorLog "logs/django.example.com_error-log"
# Index file. Add as many as required for your applications
<IfModule dir_module>
DirectoryIndex index.html
</IfModule>
# Where the documents are
DocumentRoot "/some/path/apache/htdocs/django"
<Directory />
Options FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
</Directory>
<Directory "/some/path/apache/htdocs/django">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
On Apache 2.2, you have to add NameVirtualHost *:80, in Apache 2.4, nothing, it is always "on".
All these values can be changed as you like, this is just an example to explain the concept.

apache You don't have permission to access (ubuntu amazon ec2)

I've created and installed Apache on amazon EC2 few times before.
But this time I cannot seems to get apache to run the code that I put on a Volume I created and mounted on /data1/
I use the following 000-default.conf in my /etc/apache2/sites-available that is already enabled
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
RewriteEngine On
ServerAdmin webmaster#localhost
#DocumentRoot /var/www/html/web
DocumentRoot /data1/proj/ba/web
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /data1/proj/ba/web>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
And I get http://ec2-54-197-1-250.compute-1.amazonaws.com/
Forbidden
You don't have permission to access / on this server.
Apache/2.4.7 (Ubuntu) Server at
ec2-54-197-1-250.compute-1.amazonaws.com Port 80
I tried
sudo adduser $USER www-data
sudo chown -R www-data:www-data /data1/proj
sudo chmod -R g+rw /data1/proj
and also other variation of these cmds
Now the strange thing is that if I change the DocumentRoot to /var/www/html/web
and create a symlink sudo ln -s /data1/proj/ba/web/ /var/www/html/web
than it is working! this is ok for now but in the future it might be a problem for me.
Any idea what i'm doing wrong?
here is the new format:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName myproj.co.il
ServerAlias www.myproj.co.il
RewriteEngine On
ExpiresActive On
CustomLog /var/log/apache2/access.log vhost_combined
DocumentRoot /data1/projects/myproj/
<Directory /data1/projects/myproj/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
<FilesMatch "\.(gif|jpg|png|js|css)$">
ExpiresDefault "access plus 1 month"
</FilesMatch>
</Directory>
</VirtualHost>
Note the Require all granted line that replaced the
Order allow,deny
allow from all

Error with subdomain basic authentication via htpasswd

Issue:
I have Laravel running on Apache 2.4.9 and my domains are organized as follows:
beta.domain.com => /var/www/beta
www.domain.com => /var/www/live
The beta subdomain has basic authentication. Everything is working as expected except when I started poking around the apache2 error logs. I get the following error message:
AH01797: client denied by server configuration:
/var/www/beta/public/index.php, referer: https://beta.domain.com/
My setup:
Here is my setup:
<VirtualHost *:80>
# Redirect all http traffic to https
Redirect 301 / https://www.domain.com/
</VirtualHost>
<VirtualHost *:443>
# some SSL setup for www here
ServerName www.domain.com
DocumentRoot /var/www/live/public
<Directory /var/www/live/public>
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
LogLevel warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
SetEnv ENVIRONMENT "live"
</VirtualHost>
<VirtualHost *:443>
# some SSL setup for beta here
ServerName beta.domain.com
DocumentRoot /var/www/beta/public
<Directory /var/www/beta/public>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
# allow from one ip
Allow from xxx.xxx.xxx
Satisfy any
AuthUserFile /path/to/htpasswd/.htpasswd
AuthName "Password required"
AuthType Basic
Require valid-user
</Directory>
LogLevel warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
SetEnv ENVIRONMENT "beta"
</VirtualHost>
Failed attempts:
I've found several differing answers for this, none of which worked for me. These are the ones that seem the most convincing, but again they didn't work for me.
Replacing <Directory> with <Location> tags (http://httpd.apache.org/docs/current/mod/mod_auth_basic.html#authbasicprovider) - the errors were gone, but I lost basic authentication
Using Require all granted instead of Order allow/deny - this also
removed basic authentication for me. Also not sure if this makes
sense in my scenario.
Because I'm using Apache 2.4+, I changed
Order allow, deny
Allow from all
to simply
Require all granted
This fixes the error message, but to allow for basic authentication on the beta subdomain, I also had to remove Satisfy any
So the set up for beta would be changed to this:
<Directory /var/www/beta/public>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
# removed in 2.4
# Order allow,deny
# allow from one ip
Require ip xxx.xxx.xxx
# No longer require Satisfy any in 2.4
# Satisfy any
AuthUserFile /path/to/htpasswd/.htpasswd
AuthName "Password required"
AuthType Basic
Require valid-user
</Directory>

Resources