I have a live server.With apache installed. For some reason it doesn't accept my routes. The main laravel page shows but when you use a root I get:
Not Found
The requested URL /sayit was not found on this server.
Apache/2.4.18 (Ubuntu) Server at aragonserv.co.za Port 443
When I say "https://example.com/sayit"
Please find below the files I have on figured
File: /etc/apache2/sites-available/ example.conf
<VirtualHost *:80>
ServerAdmin admin#example.com
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/example.com/public
<Directory /var/www/example.com/public>
Options Indexes FollowSymLinks MultiViews
AllowOverride all
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
RewriteEngine on
RewriteCond %{SERVER_NAME} =www.example.com [OR]
RewriteCond %{SERVER_NAME} =example.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
File: /var/www/example.com/public/.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>
My Routes web.php
<?php
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
Route::get('/', function () {
return view('welcome');
});
Route::get('/sayit', 'TestController#sayHello');
My Controller
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class TestController extends Controller
{
//TEST METHOD
public function sayHello(){
return echo "Hello";
}
}
Check the following:
1 - Enable apache rewrite module sudo a2enmod rewrite and reload apache.
2 - Files permissions
sudo chgrp -R www-data storage bootstrap/cache
sudo chmod -R ug+rwx storage bootstrap/cache
Related
On Ubuntu I've installed Laravel and PHP.
But when I type ip of my server in the browser I can see only files and folders.
Ubuntu 16.04, php 7.4, apache2
This is my folder /var/www/html/myproj/:
root#srv:/var/www/html/myproj# ls
CHANGELOG.md bpl laradock routes webpack.mix.js
README.md composer.json package.json server.php
app composer.lock phpunit.xml storage
artisan config public tests
bootstrap database resources vendor
What I have to do yet?
This is laravel.conf file that is in /etc/apache2/sites-available:
<VirtualHost *:80>
ServerName yourdomain.tld
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html/myproj/public
<Directory /var/www/html/myproj>
AllowOverride All
<RequireAll>
Require ip 127.0.0.1 xxx.xx.xx.xx
</RequireAll>
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
.htaccess looks like this:
<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>
Assuming you are using Apache2, there are several things to do.
First, try to open the public path in your browser, for example : http://localhost/public
If the problem remains, verify in your server configuration that .htaccess file are handled, this property must be set in the apache2 configuration :
AllowOverride All
Here is an example with the default web server folder :
<Directory /var/www/html/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
In general this value is set to None by default, so change it to All.
But, to be sure you can do that, you must have activated the mod_rewrite extension, so in linux terminal type this :
sudo a2enmod rewrite
sudo service apache2 restart
configure the nginx vhost file to point /public folder & also add laravel rewrite rule in vhost file
If you are using nginx try settings below:
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name example.com www.example.com;
root /var/www/html/myproj/public;
}
I'm getting a 404 error when I'm deploying my project on a live server. I'm getting a laravel page saying Sorry, the page you are looking for could not be found. so I know it is reaching my project.
I ran php artisan config:cacheand php artisan route:cacheto register my routes and cache, but it still isn't changing. not really sure why I'm getting this error. My document root in my vhost is set to my public folder as well.
Steps I took to deploy
cloned my project from git
changed branch to my develop branch
made my permissions for the project 777 (I know its wrong by I just wanted to get it to deploy and see if it had bugs)
pointed my vhost to project/public
added .env (was using it in previous deployment)
composer install
composer update
php artisan config:cache
php artisan route:cache
vhost
<IfModule mod_ssl.c>
<VirtualHost *:443>
DocumentRoot /var/www/html/API/public
#DocumentRoot /var/www/API/public/
ServerName api.app.io
ServerAlias api.app.io
ErrorLog ${APACHE_LOG_DIR}/api-error.log
CustomLog ${APACHE_LOG_DIR}/api-access.log combined
<Directory "/var/www/API/public">
#Options +Includes
#Options +FollowSymLinks -Indexes
Options All
AllowOverride All
Require all granted
</Directory>
SSLCertificateFile /etc/letsencrypt/live/api.app.io/cert.pem
SSLCertificateKeyFile /etc/letsencrypt/live/api.app.io/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateChainFile /etc/letsencrypt/live/api.app.io/chain.pem
</VirtualHost>
</IfModule>
.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]
# Handles JWT middleware
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule .* - [e=HTTP_AUTHORIZATION:%1]
</IfModule>
Try to change php version in your hosting panel.
i developed a website in laravel but problem is if someone know the name of files he can directly access that files of website which i don't want
JobScholar
app
Exceptions
Http
Mail
Models
Permission.php
Providers -
Role.php
User.php
.env
etc etc
application is working fine but what i want if user type
http://localhost:8080/JobScholar/app/
or
http://localhost:8080/JobScholar/User.php/
he should rediret to home controller or see an error message
my .htaccess
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
Options -Indexes
ErrorDocument 403 http://localhost:8080/JobScholar/index
Options +FollowSymLinks
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /JobScholar/$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>
## Don't listing directory
#Options -Indexes
#
## Follow symbolic links
#
#
## Default handler
#DirectoryIndex index.php
i don't want the user to access any of the file or directory the only directory and files he can see are only those whose routes are defines
Laravel basic flow is that ALL the requests go through index.php file in public folder. So you have to make sure your server points all the request to that folder so index.php can serve and take care of the rest.
Quick fix is to create vHost file(assuming you're not on shared host).
Here's a sample:
<VirtualHost *:80>
ServerName www.site.com
ServerAlias site.com
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html/site_name/public
<Directory /var/www/html/site_name/public>
AllowOverride All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
On apache server it will go in:
/etc/apache2/sites-available/
Then enable the site a2ensite site_name.conf
Finally point your site to server IP in /etc/hosts like so: 127.0.0.45 site.com
Also be sure to enable mod rewrite using a2enmod rewrite so .htaccess provided by Laravel can make required rewrites to the URL.
Finally restart apache: service apache2 restart
I'm a trying to learn the framework Laravel. I installed it and I configured the virtual hosts
When I tried to access the project, it works
but when I tried another root such as /justForTest
it didn't work
I don't know why ?!
Route::get('/', function () {
return view('welcome');
});
Route::get('/justForTest', function () {
//return view('welcome');
return "Hello world !";
});
image
I tried many solutions on the net in vain.
I use kubunto 17.04 and this is what I did
-I added the Directory with AllowOverride all on my lsapp.div.conf
<VirtualHost *:80>
ServerAdmin ham.elmaslouhi#gmail.com
ServerName lsapp.dev
ServerAlias www.lsapp.dev
DocumentRoot /var/www/html/lsapp/public
<Directory "/var/www/html/lsapp/public">
AllowOverride all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
-I have enabled the rewrite mode with a2enmod rewrite
-I added the line RewriteBase /laravel/ on my htaccess file
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteBase /laravel/
# 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's for helping me.
Remove or comment #RewriteBase /laravel/ in your .htacess
I'm deploying a webapp to a digitalOcean droplet and it displays the home route just fine. I have dependencies installed, Apache conf pointing to laravel's public folder, permissions given to www-data so Apache can use the folder but, when I try to access a link defined in the site, already defined in the routes file, for example /about I get a 404 error.
Why could this be?
The droplet's runs Ubuntu 16.04, I have Apache and php7.
I was reading this two posts: 1 and 2 but got no luck
My apache conf file is
<Directory /var/www/html/analizalabs/public>
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Require all granted
</Directory>
My sites-available file
ServerAdmin tecnofunk#cryptolab.net
DocumentRoot /var/www/html/analizalabs/public/
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
Part of my routes file
Route::get('/','PagesController#home');
Route::get('/about','PagesController#about');
Route::get('/contact','PagesController#contact');
My htaccess file
<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>
Permissions like...
drwxrwxr-x 8 www-data dev 4096 Sep 9 21:58 public
where dev is the group I use to modify files with rw access in that directory.
It seems rewrite module isn't enabled, You have to enable it using:
a2enmod rewrite
Note1: rewrite module is not enabled by default in ubuntu
Note2: You can check enabled modules with apache2ctl -M and apachectl -M in mac ( or httpd -M in both )