Laravel - the requested url cannot be found on this server - apache

I have deployed my project on linode and configured everything correctly but I find the homepage the only thing to be working. Anything else is giving me The requested url can not be found on this server. I have check all my configurations and everything seems to be correct. a2enmod rewrite is enabled and this 000-default.conf:
<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 webmaster#localhost
DocumentRoot /var/www
<Directory /var/www>
Options Indexes FollowSymLinks
AllowOverride All
RewriteEngine On
RewriteBase /var/www/application
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>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
What else is missing?
Edit:
VirtualHost configuration:
ServerRoot: "/etc/apache2"
Main DocumentRoot: "/var/www"
Main ErrorLog: "/var/log/apache2/error.log"
Mutex default: dir="/var/lock/apache2" mechanism=fcntl
Mutex mpm-accept: using_defaults
Mutex watchdog-callback: using_defaults
Mutex rewrite-map: using_defaults
PidFile: "/var/run/apache2/apache2.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
Define: ENABLE_USR_LIB_CGI_BIN
User: name="www-data" id=33
Group: name="www-data" id=33

You need to set document root to the public folder of your application like so:
"var/www/your-site.com/public"

Try follow my config:
<VirtualHost *:80>
ServerName yourproject.com
ServerAlias www.yourproject.com
ServerAdmin webmaster#localhost
DocumentRoot /var/www/yourproject/public
<Directory "/var/www/yourproject/public">
Require all granted
Allowoverride All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Turns out the .htaccess was missing so that was the reason. I have added it and it is working normally.

Related

How to change root directory for lamp on Ubuntu

I'm trying to change the root directory of my new lamp on Ubuntu but I have an error message when I open localhost or 127.0.0.1 : **Forbidden
You don't have permission to access this resource.**
I'm using Apache/2.4.46 (Ubuntu) Server at 127.0.0.1 Port 80 with Ubuntu 21.04.
I already changed apache2.conf and 000-default.conf :
000-default.conf:
<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 webmaster#localhost
DocumentRoot /home/matt/phpRoot
ServerName 127.0.0.1
# 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 apache2.conf :
<Directory />
Options Indexes FollowSymLinks
AllowOverride None
Require all denied
</Directory>
<Directory /usr/share>
AllowOverride None
Require all granted
</Directory>
<Directory "/home/matt/phpRoot">
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
#<Directory /srv/>
# Options Indexes FollowSymLinks
# AllowOverride None
# Require all granted
#</Directory>
in 000-default.conf and apache2.conf
change /home/matt/phpRoot to /var/www

Apache redirects to wrong virtual host

I am trying to set up two virtual hosts, one for my website and another for my nextcloud instance. This is what my config files look like:
/etc/apache2/site-available/000-default.conf
<IfModule mod_ssl.c>
<VirtualHost _default_:80>
ServerName domain.com
ServerAlias www.domain.com
DocumentRoot "/var/www/html"
CustomLog /var/log/apache2/nc-access.log combined
ErrorLog /var/log/apache2/nc-error.log
SSLEngine on
SSLCertificateFile /etc/ssl/certs/ssl-cert-snakeoil.pem
SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key
</VirtualHost>
<Directory /var/www/html/>
Options +FollowSymlinks
AllowOverride All
<IfModule mod_dav.c>
Dav off
</IfModule>
LimitRequestBody 0
SSLRenegBufferSize 10486000
</Directory>
</IfModule>
/etc/apache2/site-available/nextcloud.conf
<IfModule mod_ssl.c>
<VirtualHost _default_:443>
ServerName nextcloud.domain.com
DocumentRoot "/var/www/nextcloud"
CustomLog /var/log/apache2/nc-access.log combined
ErrorLog /var/log/apache2/nc-error.log
SSLEngine on
SSLCertificateFile /etc/ssl/certs/ssl-cert-snakeoil.pem
SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key
</VirtualHost>
<Directory /var/www/nextcloud/>
Options +FollowSymlinks
AllowOverride All
<IfModule mod_dav.c>
Dav off
</IfModule>
LimitRequestBody 0
SSLRenegBufferSize 10486000
</Directory>
</IfModule>
Output of apache2ctl -S, showing the activated hosts:
VirtualHost configuration:
*:80 domain.com (/etc/apache2/sites-enabled/000-default.conf:2)
*:443 nextcloud.domain.com (/etc/apache2/sites-enabled/nextcloud.conf:2)
ServerRoot: "/etc/apache2"
Main DocumentRoot: "/var/www/html"
Main ErrorLog: "/var/log/apache2/error.log"
Mutex ssl-cache: using_defaults
Mutex default: dir="/var/run/apache2/" mechanism=default
Mutex watchdog-callback: using_defaults
Mutex rewrite-map: using_defaults
Mutex ssl-stapling-refresh: using_defaults
Mutex ssl-stapling: using_defaults
Mutex proxy: using_defaults
PidFile: "/var/run/apache2/apache2.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
User: name="www-data" id=33
Group: name="www-data" id=33
When I enter domain.com in my browser, I am expecting it to load /var/www/html, my website. However, it loads my nextcloud (/var/www/nextcloud) instance. What do I do to make domain.com redirect to my website instead of my nextcloud instance?
You should modify your configurations like this (explanation below):
/etc/apache2/site-available/000-default.conf
<VirtualHost _default_:80>
ServerName domain.com
ServerAlias www.domain.com
DocumentRoot "/var/www/html"
CustomLog /var/log/apache2/80_nc-access.log combined
ErrorLog /var/log/apache2/80_nc-error.log
<Directory /var/www/html/>
Options +FollowSymlinks
AllowOverride All
<IfModule mod_dav.c>
Dav off
</IfModule>
LimitRequestBody 0
</Directory>
</VirtualHost>
/etc/apache2/site-available/nextcloud.conf
<IfModule mod_ssl.c>
<VirtualHost _default_:443>
ServerName nextcloud.domain.com
DocumentRoot "/var/www/nextcloud"
CustomLog /var/log/apache2/443_nc-access.log combined
ErrorLog /var/log/apache2/443_nc-error.log
SSLEngine on
SSLCertificateFile /etc/ssl/certs/ssl-cert-snakeoil.pem
SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key
<Directory /var/www/nextcloud/>
Options +FollowSymlinks
AllowOverride All
<IfModule mod_dav.c>
Dav off
</IfModule>
LimitRequestBody 0
SSLRenegBufferSize 10486000
</Directory>
</VirtualHost>
</IfModule>
Changes
In your :80 VirtualHost, you should not have any SSL directives. Port 80 is for http:// connections. So I remove everything that had to do with SSL.
In your :443 VirtualHost, there you want to have your SSL directives. So keep those.
<Directory> directives should be included in the <VirtualHost> sections. These only make sense in the context of your <VirtualHost> anyway. There should be a generic <Directory> in httpd.conf that blocks direct access to all directories anyway.
I suggest you use separate log files for each <VirtualHost>. It is a good habit to have, trust me I have had Apache server with 20 hosts, it is impossible to figure out which log entry is for which. Also you might want to put your SSL in Debug log to troubleshoot something...
To reach the first <VirtualHost>, enter http://example.com
To reach the second <VirtualHost>, enter https://example.com
There is no redirection here. Just <Virtualhost> names and ports assignment. Apache looks at what you asked for (the site in the address bar of your browser) and uses the <VirtualHost> that best matches your request. If it cannot find a specific one, it will use the first one by default.
That explains why if you try https://example.com, Apache will select the <VirtualHost> based on the port. Here it is port 443 (https://). So Apache will respond with your cloud <VirtualHost>. The port is the deciding factor here, not the domain name.

Apache vhost loads incorrect doc root

My issue is that Apache randomly loads a non-default vhost instead of the domain I ask it to. I've tried just about every solution I found on this site and through searching but nothing seems to fix this problem.
Background:
This is a virtual server hosted on a popular cloud platform
The global apache conf file contains no VirtualHost definitions and the config file below is included properly (Include sites-enabled/*.conf)
Apache 2.4 on Ubuntu 16.04
I had each domain in their own conf file but that did not work either.
Apache has chosen domain3.com as the default for some reason.
When I execute curl localhost on the server, it returns the contents of domain3.com.
The only thing excluded from the vhost below are some SSL definitions that don't seem to be causing any problems.
ServerName is defined as localhost in apache.conf
The vhosts below are saved at /etc/apache2/sites-enabled/000-default.conf
Server weirdness?
I can't seem to actually stop apache. Executing service apache2 stop and then service apache2 status will identify the process as inactive, but I can still load pages under domain1/2/3.com. It's like nothing I do has any effect.
There's like 3 ways to access apache now. Some seem to work, some don't. /etc/init.d/apache2, service apache2, apache2ctl.
It only loads the wrong site about 50% of the time.
I'm completely out of ideas...
NameVirtualHost *:80
# domain1.com
<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.domain1.com
ServerAlias domain1.com
UseCanonicalName Off
ServerAdmin webmaster#localhost
DocumentRoot /var/www/domain1.com/
<Directory /var/www/domain1.com>
Options Indexes FollowSymLinks
AllowOverride 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>
# domain3.com
<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.domain3.com
ServerAlias domain3.com
ServerAlias domain3.net
ServerAlias www.domain3.net
UseCanonicalName Off
ServerAdmin webmaster#localhost
DocumentRoot /var/www/domain3.com/
<Directory /var/www/domain3.com>
Options Indexes FollowSymLinks
AllowOverride 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}/cq2_error.log
CustomLog ${APACHE_LOG_DIR}/cq2_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>
# domain2.com
<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.domain2.com
ServerAlias domain2.com
UseCanonicalName Off
ServerAdmin webmaster#localhost
DocumentRoot /var/www/domain2.com/
<Directory /var/www/domain2.com>
Options Indexes FollowSymLinks
AllowOverride 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>
And my apache2ctl -S output:
AH00548: NameVirtualHost has no effect and will be removed in the next release /etc/apache2/sites-enabled/000-default.conf:1
VirtualHost configuration:
*:80 is a NameVirtualHost
default server www.domain1.com (/etc/apache2/sites-enabled/000-default.conf:4)
port 80 namevhost www.domain1.com (/etc/apache2/sites-enabled/000-default.conf:4)
alias domain1.com
port 80 namevhost www.domain3.com (/etc/apache2/sites-enabled/000-default.conf:54)
alias domain3.com
alias domain3.net
alias www.domain3.net
port 80 namevhost www.domain2.com (/etc/apache2/sites-enabled/000-default.conf:95)
alias domain2.com
ServerRoot: "/etc/apache2"
Main DocumentRoot: "/var/www/html"
Main ErrorLog: "/var/log/apache2/error.log"
Mutex rewrite-map: using_defaults
Mutex ssl-stapling-refresh: using_defaults
Mutex ssl-stapling: using_defaults
Mutex ssl-cache: using_defaults
Mutex default: dir="/var/lock/apache2" mechanism=fcntl
Mutex mpm-accept: using_defaults
Mutex watchdog-callback: using_defaults
PidFile: "/var/run/apache2/apache2.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
User: name="www-data" id=33 not_used
Group: name="www-data" id=33 not_used
As far as Apache choosing a random site:
When you do curl localhost, it is likely that it sending out an HTTP header that has no Host: defined, as it behaves similarly to when you type the IP of the server directly in the browser. The Host: header in the HTTP request is the field that Apache matches against the ServerName and ServerAlias trying to find a match to load up the corresponding DocumentRoot.
So, in that case, if you don't have a default host setup, and an empty Host: comes in, then Apache will randomly choose a site (I have recreated this behavior on my dev server, just to verify).
It is better to set up 000-default.conf as your catch-all and decide what to do when that happens, like redirecting to one of your sites or to a simple php file that just echos something bland. Then set up separate conf files for each site just to stay organized.
If you have DNS records pointing to your server correctly, then the default will only trigger when bots come around testing IPs.
On Ubuntu 16.04 you have systemd .. so the right way to interact with apache is using systemctl <command> apache2
I suggest to kill every apache process and then try to start it again using systemctl start apache2 ..
Moreover, to be sure my default domain is loaded at first, I usually rename its configuration file as 000-domain.conf .. then add other domains, one per file, with no numerical prefix at all
Your configuration looks alright, the weirdness you seem to describe seem to be related to a external issue, being it distro scripts, or whatever..., so try to use only apachectl only to stop/start, if the distro hasn't changed it much is the most "official" method you will find to manage your httpd server start/stop, etc, plus it is the only thing you have now giving you correct information
Also, In your configuration domain3.com would not ever be your default virtualhost, not even if you had defined your servernames incorrectly. So chances are you are seeing what other "service/server" is sending you.
Answer:
Use apachectl only until you fix your discro script issues

Forbidden permission to access /cgi-bin/test.pl

Okay so I have configured Apache on my Linux machine but when I try to run any sort of script on local host from the cgi-bin I get Forbidden permission. i.e. address http://localhost/cgi-bin/test.pl
<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 webmaster#localhost
DocumentRoot /var/www/html
# 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
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
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
<Files ~ "\.(pl|cgi)$">
SetHandler perl-script
PerlResponseHandler ModPerl::PerlRun
Options +ExecCGI
PerlSendHeader On
</Files>
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
That is my 000-default.conf
And yes I have given test.pl 755 permissions and it does run correctly.
Thanks in advance for any help.
do "ls" on each of level.. /usr/ , /usr/lib/ , /usr/lib/cgi-bin without sudo... probably the owner of that file is 'root', if so.. then try 'chown' that file.

Apache2 - Mod_rewrite and .htaccess

I am using Ubuntu 14.04 and apache 2.
Here is my phpinfo file: https://www.vivashost.com/phpinfo.php
Here is my .htacess file:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^feature-pricing-tables.html$ feature.html
Here is my /etc/apache2/sistes-available/000-default.conf file:
<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 webmaster#localhost
DocumentRoot /var/www/html
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www/html>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ServerName vivashost.com
Redirect "/" https://www.vivashost.com/
# 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
But when i try to open https://www.vivashost.com/feature.html it is giving me 404 error.
I am trying to make a rewrite rule that when you open feature.html apache2 must load the content from feature-pricing-tables.html file.
Where is my mistake, can you please help me out fix this thing ?
Thanks in advance!
This is a very common mistake that is made: You've declared the rule backwards.
Currently, your rule says that if I access feature-pricing-tables.html, then load up the content of feature.html.
Use this instead:
RewriteRule ^feature.html$ feature-pricing-tables.html [L]
Also, the L flag is necessary here - in case you add any other rules, you want to stop processing if there's a match for this rule.