The requested URL /ProjectName/users was not found on this server. Laravel - php

I am following the quickstart of laravel and it said "type /users" but not working for me.
I have wrote in the browser, http://DomainServer/ProjectName/users and it throws:
The requested URL /ProjectName/users was not found on this server.
Laravel
I tried the following,
To enable the apache module mod_rewrite and also does not work.

Steps for Apache Web Server and Laravel in Linux Environment.
Open httpd.conf
sudo vim /etc/httpd/conf/httpd.conf
# for debian users: /etc/apache2/apache2.conf
Make sure the DocumentRoot is pointing to the laravel project's public directory
Add the Directory element for that path and Allowoverride All... as follows
DocumentRoot "/var/www/html/laravel/public/"
<Directory "/var/www/html/laravel/public">
Allowoverride All
</Directory>
Open .htaccess from ../laravel/public/ and make sure it has the following
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
Restart httpd services
sudo service httpd restart
Now http://DomainServer/users will work in your browser.

Find httpd.conf and change the <Directory> element from
<Directory "/var/www/html/">
Allowoverride None
</Directory>
to
<Directory "/var/www/html/">
Allowoverride All
</Directory>
Then it works after restart the apache without change the DocumentRoot.

First find the htaccess file in your Laravel project
next add the following coding in htaccess file
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
save the htaccess file
and restart the apache server using following code
sudo service apache2 restart
remember htaccess file and index.php file must be available in same folder in your project

the default url have a prefix "index.php" before your page if you try .../public/index.php/your_page it will run, so you need to add the module rewrite if you are using appache to write your url without this prefix

Try pointing your browser to http://DomainServer/ProjectName/public/users - the 'public' folder is the default 'entry point' for your Laravel app.

Make sure you have mod_rewrite enabled in Apache .

For me i enabled the mod_rewrite and it worked for me well.
Enable mod_rewrite for Apache:
cd /etc/apache2/sites-available/
sudo a2enmod rewrite

in my case I wanted to get this route as not authenticated user .
RouteServiceProvider has default :
/**
* Define the "api" routes for the application.
*
* These routes are typically stateless.
*
* #return void
*/
protected function mapApiRoutes()
{
Route::prefix('api')
->middleware('api')
->namespace($this->namespace)
->group(base_path('routes/api.php'));
}
which means you need to add that prefix "api/" to your url, say:
http://yourdomain.com/api/route_url_part
Then put route to api.php , not web.php wich is auth 'middlwared'
(optionally for Android emulators)
if you are trying to do that in, say, android emulator you have to shut down server and start it as:
php artisan serve --host=0.0.0.0
and in java android url instead of localhost put in the ip retrived from prompt window's ipconfig command. Say mine was 192.168.0.106
(IPv4 Address one). Then it will work.

$ sudo nano /etc/apache2/apache2.conf
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
Change to
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
$ sudo a2enmod rewrite
$ sudo systemctl restart apache2

Related

Symfony 3 on Apache server // Postman POST request not working without app.php in url

I have a working Symfony 3 API on an Apache Server - more info here and here these are already resolved
I am now facing a routing problem I think, my postman POST methods working fine if use a URL like: https://example.com/app.php/mcPDF/ but when I try with URL: https://example.com/mcPDF/ it says 404 not found.
I tried several answers here, like changing the htaccess IfModule mod_rewrite.c> section and added various settings in 000-default.conf file like:
<Directory /var/www/html/pdf/web>
AllowOverride All
Order Allow,Deny
Allow from All
DirectoryIndex app.php
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [QSA,L]
</Directory>
and every time I do changes I do:
- bin/console cache:clear --env=prod --no-warmup
- bin/console cache:warmup --env=prod
and I also did the sudo a2enmod rewrite and restarted the server many times
Please advise, let me know what info you need more
All my PROD servers use configuration below and they all work fine. Try to update yours accordingly to see what happens.
# $ nano /etc/apache2/sites-available/000-default.conf
<VirtualHost *:80>
DocumentRoot /var/www/my_app/current/web
<Directory /var/www/my_app/current/web>
AllowOverride All
Require all granted
Allow from All
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [QSA,L]
</IfModule>
</Directory>
ErrorLog ${APACHE_LOG_DIR}/${APP_NAME}-error.log
CustomLog ${APACHE_LOG_DIR}/${APP_NAME}-access.log combined
</VirtualHost>
UPDATE: Stage dependent configurations are shown here in details. http://www.inanzzz.com/index.php/post/0ew3/deploying-a-symfony-applications-to-staging-and-production-servers-with-capistrano

Routes not working on server using Laravel 5.2

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 )

.htaccess file not works in LAMP

This is my .htaccess file. I am used Codeigniter Framework for my project.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /project_name/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
Where is my mistake here? But It Works in xampp.
You can't just move from one server to another and not make sure your prerequistes are there. These things are not on by default on most systems. You also have not given any specifics about your setup or even your document root.
So going off that it's an Ubuntu server and apache2, you need to do these things.
First thing you need to do if this is a new LAMP install is make sure rewrite is on.
Run this command to enable mod_rewrite.
sudo a2enmod rewrite
Then you need to make sure you allow .htaccess in your document root.
edit
/etc/apache2/sites-available/000-default.conf
In this file search for this
AllowOverride None
and change it to
AllowOverride All
Then restart apache2.
sudo service apache2 restart
EDIT: Based on your comment, you need to make your vhost look like this and then restart apache2.
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /var/www/html>
AllowOverride All
</Directory>
</VirtualHost>
Open your terminal
Run this following code:
sudo nano /etc/apache2/apache2.conf
go down and change:
AllowOverride All
look like:
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
Then restart apache2.
sudo service apache2 restart
and then .htaccess file is
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
Are you sure mod_rewrite module is loaded ? go to httpd.conf and search for -
LoadModule rewrite_module modules/mod_rewrite.so
and make sure theres no # [hash tag] before

running laravel on a different port

I'm using Bitnami MampStack on OS X 10.9. Because this is an inherited laptop, I had to set up Apache under MAMP to listen on port 8888. I tweaked it to listen on 8889 as well and added the following as a VirtualHost in my httpd.conf file:
<VirtualHost *:8889>
DocumentRoot "/Applications/mampstack-5.4.26-0/apache2/htdocs/codebright/public"
ServerName localhost
<Directory "/Applications/mampstack-5.4.26-0/apache2/htdocs/codebright/public">
Require all granted
</Directory>
</VirtualHost>
I followed the example here (so all my source code matches his). The index blade works, but the edit, create, and delete blades return a 404.
As I was testing, I discovered that http://localhost:8889/create returned a 404, but http://localhost:8889/index.php/create returned the correct view. Also, browsing http://localhost:8888/codebright/public/create works as expected.
So...me being kinda new to Laravel and MVC frameworks in general, is there some way I can have this installing running properly on port 8889?
Your virtualhost is working as it should, you just have now to be sure your public/.htaccess file is in place:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
This is the file that rewrites your urls removing the /index.php from them.
EDIT
Also, check if you have mod_rewrite installed and enabled, because your .htaccess uses it, in Ubuntu/Debian, to enable it, you have to execute:
sudo a2enmod rewrite
Figured it out, thanks to this. I was missing AllowOverride All in the <Directory> section. Updated httpd.conf:
<VirtualHost *:8889>
DocumentRoot "/Applications/mampstack-5.4.26-0/apache2/htdocs/codebright/public"
ServerName localhost
<Directory "/Applications/mampstack-5.4.26-0/apache2/htdocs/codebright/public">
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
I thought I might have been missing RewriteEngine On in the VirtualHost definition but it doesn't seem to have an effect on my problem.

codeigniter .htaccess in amazon ec2 removal of index.php not working

codeigniter .htaccess in amazon ec2 removal of index.php not working
code
RewriteEngine on
RewriteBase http://ec2-xx-xxx-xx-xx.us-west-2.compute.amazonaws.com/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
config file
$config['base_url'] = 'http://ec2-xx-xxx-xx-xx.us-west-2.compute.amazonaws.com/';
You can change your .htaccess like this
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
and change the value of "AllowOverride None" on /etc/httpd/conf/httpd.conf (if you use AMI Linux)
into "AllowOverride All"
after that restart your apache with command like this:
sudo service httpd restart
It's work and tested on my aws ec2.
(if you use ubuntu)
Activate the mod_rewrite module with
sudo a2enmod rewrite
and restart the apache
sudo service apache2 restart
To use mod_rewrite from within .htaccess files (which is a very common use case), edit the default VirtualHost with
sudo nano /etc/apache2/sites-available/000-default.conf
Search for “DocumentRoot /var/www/html” and add the following lines directly below:
<Directory "/var/www/html">
AllowOverride All
</Directory>
Save and exit the nano editor via CTRL-X, “y” and ENTER.
Restart the server again:
sudo service apache2 restart
Justudin is correct!
Also you can use the "AllowOverride All" rule to only your project; writing in /etc/httpd/conf/httpd.conf something like this:
<Directory "/var/www/your_website">
AllowOverride All
</Directory>
Only you can use the "AllowOverride All" rule to all deployed application; writing in /etc/httpd/conf/httpd.conf :
<Directory "/var/www/html">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>

Categories