6

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.

Luillyfe
  • 6,183
  • 8
  • 36
  • 46

9 Answers9

48

Steps for Apache Web Server and Laravel in Linux Environment.

  1. Open httpd.conf

    sudo vim /etc/httpd/conf/httpd.conf
    # for debian users: /etc/apache2/apache2.conf
    
  2. Make sure the DocumentRoot is pointing to the laravel project's public directory

  3. 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>
    
  4. 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>
    
  5. Restart httpd services

    sudo service httpd restart
    
  6. Now http://DomainServer/users will work in your browser.

peak
  • 105,803
  • 17
  • 152
  • 177
Andrew Smith
  • 496
  • 1
  • 6
  • 6
5

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.

wasmetqall
  • 139
  • 1
  • 7
4

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

Mathesh Raj
  • 671
  • 6
  • 15
3

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

Amine Achalhi
  • 107
  • 1
  • 1
  • 6
  • This 'answer' is what lead me to see that this was my problem. Just to expand on it, if you think you should be able to do something like `http://DomainServer/ProjectName/users`, but that doesn't work, try `http://DomainServer/ProjectName/index.php/users` (or maybe `http://DomainServer/ProjectName/public/index.php/users`). If that works, then you have the problem that the answer, above, fixes! – Rob Cranfill Oct 14 '15 at 19:04
2

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

Gadoma
  • 6,475
  • 1
  • 31
  • 34
1

Make sure you have mod_rewrite enabled in Apache .

Pankaj Kumar
  • 129
  • 1
  • 12
0

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

0

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.

CodeToLife
  • 3,672
  • 2
  • 41
  • 29
0

$ 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

  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Aug 26 '22 at 08:34