Nothing accessible in my Laravel project except the home page - laravel

been searching for the past 3 days about configuring laravel 5.4 on my linux mint 18.2 system running apache 2.4 . when apache server starts and i manually type in localhost in the browser,it does show up the default home page of laravel , but when i try to access it through live preview in brackets (live preview base url : http://localhost as my laravel project pro lies in /var/www/html/)but it throws internal server error corresponding to the errors in my apache configuration.So here i put forward my .htaccess file , 000-default.conf file in sites-enabled directory of apache2 and apache2.conf files :
One important thing : i got my project folder pro under /var/www/html/
1. 000-default.conf(sites-enabled)
<VirtualHost *:80>
ServerName localhost
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html/pro/public
<Directory /var/www/html/pro/public>
Options Indexes +FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
2. apache2.conf
Mutex file:${APACHE_LOCK_DIR} default
PidFile ${APACHE_PID_FILE}
Timeout 300
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 5
User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}
HostnameLookups Off
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
IncludeOptional mods-enabled/*.load
IncludeOptional mods-enabled/*.conf
Include ports.conf
<Directory />
Options FollowSymLinks
AllowOverride None
Require all denied
</Directory>
<Directory /usr/share>
AllowOverride None
Require all granted
</Directory>
<Directory /var/www/html/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
AccessFileName .htaccess
<FilesMatch "^\.ht">
Require all denied
</FilesMatch>
IncludeOptional conf-enabled/*.conf
IncludeOptional sites-enabled/*.conf
Include /etc/phpmyadmin/apache.conf
3 .htaccess (/var/www/html/pro/public/.htaccess)
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteBase /var/www/html/pro/public/
# 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>
thank you before hand!

Your all routes would be available after index.php, i mean if your route's url is abc, then it will be open as http://localhost/index.php/abc. Now you don't need to change anything in .htacesss file.
Go to your project root and give the read write execute permissions, so that laravel will able to cache the file inside bootstrap/cache directory and able to create your logs file inside storage/logs directory.
sudo chmod -R 777 bootstrap/cache
sudo chmod -R 777 storage/logs
If your project didn't run after that also, then sometimes you need to give this permission also.
sudo chmod -R 777 vendor/ storage/
Run these three commands after that
sudo a2ensite 000-default.conf
sudo a2enmod rewrite
sudo service apache2 restart
your route should be served after localhost.
Hope this will help :)

Try giving read/write permissions to your storage and bootstrap folder in laravel. Also setup virtual hosts if you can. Refer here.

Related

i get access forbidden from Apache (httpd) in fedora 34, Laravel, SELinux

I have configured httpd in my fedora and I checked everything is true but i get
access forbidden
I have tested everything about .htaccess but still getting access forbidden. also, my laravel folder permissions are correct.
I tested a sample project while installing httpd it worked perfectly with no 'access forbidden' message.
this is my httpd config
<VirtualHost *:80>
ServerName test.com
ServerAlias www.test.com
DocumentRoot /home/myuser/gitlab/register/public
<Directory /home/myuser/gitlab/register/public>
DirectoryIndex index.php
AllowOverride All
Require all granted
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
this is my htaccess in laravel public folder
<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>
your probably creating the issue by mixing old Apache syntax with new Apache syntax, modern versions of Apache should be something like this...
<VirtualHost *:80>
ServerName test.com
ServerAlias www.test.com
DocumentRoot /home/myuser/gitlab/register/public
<Directory /home/myuser/gitlab/register/public>
DirectoryIndex index.php
AllowOverride All
Require all granted
# Order allow,deny
# Allow from all
</Directory>
</VirtualHost>
I found the problem.
it is because of the
SELinux
ubuntu does not uses SELinux by default but RedHat distributions use it by default. SELinux prevents apache to access the home directory for the sake of security so if you disable or put it to Permissive mode, apache can access your home directory to load the web project. if you do not want to disable SELinux so the correct location for web applications is in /var/www/ folder
so if we change httpd config to
<VirtualHost *:80>
ServerName test.com
ServerAlias www.test.com
DocumentRoot /var/www/gitlab/register/public
<Directory /var/www/gitlab/register/public>
DirectoryIndex index.php
AllowOverride All
Require all granted
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
it works fine

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

Does Laragon ignore .htaccess?

I'm trying to move a working project from XAMPP to Laragon.
Everything is fine, but some directives I've put in my .htaccess don't work anymore: all modules seems to be enabled correctly.
What I'm trying to have working again is the versioning for my assets:
<IfModule mod_rewrite.c|rewrite_module>
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)\.(\d+)\.(css|js)$ $1.$3 [L]
</IfModule>
This is placed in the root of the project with Laravel, but moving it into the public folder does not change anything
In the Apache config I have the following correctly uncommented:
LoadModule rewrite_module modules/mod_rewrite.so
And this is the host configuration (untouched)
<VirtualHost *:80>
DocumentRoot "C:/laragon/www/projectski/public/"
ServerName projectski.localhost
ServerAlias *.projectski.localhost
<Directory "C:/laragon/www/projectski/public/">
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
As you can see it points to /public, but moving to the root (which I would like to, considering server configuration) will disable everything and turn the local site into a directory.
Please help me move to Laragon.
For those still looking for an answer, Laragon does not ignore .htaccess
The error was a simple syntax error in the IfModule
<IfModule mod_rewrite.c | rewrite_module>
# Logic
</IfModule>

laravel 5.6 and apache gives 404 for urls

I have apache2 server on Ubuntu 16.04LTS and I have Laravel 5.6 project called book_donation in /var/www/html now when I visit localhost the Laravel welcome screens appear no problem but whenever I click on any url it gives:
Not Found
The requested URL /book_donation/public/login was not found on this
server. Apache/2.4.18 (Ubuntu) Server at 127.0.0.1 Port 80
and here is .htaccess:
<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>
and here is my /etc/apache2/site-available/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/html
<Directory "/var/www/html">
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>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
My php version is 7.1 and apache version is 2.4.18, how to solve this?
As stated in the docs, you should configure your web server's document / web root to be the public directory.
Create a new file /etc/apache2/site-available/book_donation.test.conf:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName book_donation.test
ServerAlias www.book_donation.test
DocumentRoot /var/www/html/book_donation/public
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Edit your /etc/hosts file and add the following:
127.0.1.1 book_donation.test
Then run:
sudo a2ensite book_donation.test.conf
sudo service apache2 restart
Then you should be able to visit book_donation.test and see your site.
I was facing same problem any new route was not working and gave 404 error. Also check php artisan route:list where new route details showing properly but still it was not working. I also tried following command to make it work
php artisan view:clear
php artisan config:clear
php artisan cache:clear
Here are my project details
My DocumentRoot is /var/www/html/project/public. when add new route in web.php, it was nor working and gave 404 error but root route was working fine. Means any new route was working. so I did following changes and it start working.
changed in /etc/apache2/sites-available/project.conf
<Directory /var/www/html/project/public>
**Allowoverride All**
and enable url rewrite by running sudo a2enmod rewrite
restart apache server by running sudo systemctl restart apache2

Redirect home URL to Magento folder

I have Magento installed on my site at mydomain.com/magento. I'm happy with it to stay in this directory, however when people visit the site directly (i.e. mydomain.com) I would like this to open the Magento folder. How can I do this?
Thank you very much.
You have to make your server redirect "mydomain.com" to the directory you have installed Magento at. If you are using apache you could add a virtualhost like the one below to your httpd.conf:
<VirtualHost *:80>
ServerName mydomain.com
DocumentRoot "/yourpath/magento"
CustomLog "/tmp/access_log" common
LogLevel debug
ErrorLog "/tmp/error.log"
<Directory "/yourpath/magento">
Options FollowSymLinks Multiviews Indexes
MultiviewsMatch Any
# Rewrites to allow links
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# We are not allowing any directive contained in a .htaccess file
AllowOverride None
# We grant all permissions
Require all granted
</Directory>

Resources