6

I am trying to upload a web app (which I made using Laravel 5) to a DigitalOcean droplet. But I get a 404 Error:

The requested URL /public/login was not found on this server.

This is my apache2.conf

<Directory />
    Options FollowSymLinks
    AllowOverride None
    Require all denied
</Directory>

<Directory /usr/share>
    AllowOverride None
    Require all granted
</Directory>

<Directory /var/www/html/hotelguide/public> 
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>

000-default.conf

<VirtualHost *:80>

    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html/hotelguide/public

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

This is my folder structure This is my folder structure

This is the output of php artisan route:list This is the output of php artisan route:list

UPDATE: LARAVEL LOG

Stack trace:
#0 /var/www/html/hotelguide/vendor/symfony/console/Application.php(183): Symfony\Component\Console\Application->find('routes')
#1 /var/www/html/hotelguide/vendor/symfony/console/Application.php(117): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#2 /var/www/html/hotelguide/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(107): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#3 /var/www/html/hotelguide/artisan(36): Illuminate\Foundation\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#4 {main}

UPDATE: PHP ERROR LOG (last error)

124.43.95.22 - - [02/Sep/2016:14:01:29 +0530] "GET /login HTTP/1.1" 500 206 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36"

After completing the steps detailed by Alexey I am now getting an HTTP 500 error.

UPDATE: 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>

UPDATE: CSS AND JS NOT FOUND ERROR enter image description here

user9492428
  • 603
  • 1
  • 9
  • 25
  • Does this happen with any page or just /login? Meanwhile try a `php composer.phar update` – Adrenaxus Sep 02 '16 at 07:45
  • @Adrenaxus After I tried what Alexey said below, I am now getting an HTTP 500 error. I cannot access any other page without going through the login first, but even if I type `188.166.***.***/home` I am still getting the same HTTP 500 error. – user9492428 Sep 02 '16 at 07:57

3 Answers3

2

Based on the previous discussion :

  • your APACHE_RUN_USER & APACHE_RUN_GROUP are www-data
  • your /var/www/html/hotelguide/public folder owner is root and its group is www-pub

The current permission of your public folder are not good for Apache.
Therefore you have to give permission to Apache in this directory, and to do that, you will just have to type this command :

chown -R www-data:www-data /var/www/html/hotelguide/
jquiaios
  • 567
  • 3
  • 15
  • Please refer the screenshot in the new update. All the required css and js files are in the public/bower_components/adminlte folder – user9492428 Sep 02 '16 at 10:14
  • 1
    Can you try to access it with the capital letters & see if it's working ? `http://188.166.***.***/bower_components/AdminLTE/bootstrap/c‌​ss/bootstrap.min.css` – jquiaios Sep 02 '16 at 10:21
  • `GET http://188.166.***.***/bower_components/adminlte/dist/css/AdminLTE.min.css home:18` There is no error 404, only an error in the GET method – user9492428 Sep 02 '16 at 10:30
  • 1
    Di you try with or without the capital letters ? If there is no 404, what is the error you have ? – jquiaios Sep 02 '16 at 10:35
  • I tried with the capital letters. Earlier in the Developer Tools console, the error was: `http://188.166.***.***/bower_components/adminlte/bootstrap/c‌​ss/bootstrap.min.css Failed to load resource: the server responded with a status of 404 (Not Found)` but now the error is: `GET http://188.166.***.***/bower_components/AdminLTE/bootstrap/c‌​ss/bootstrap.min.css` – user9492428 Sep 02 '16 at 10:38
  • please apologize my confusion. I am still getting a 404 error. I got confused reading with something else. Summary: I am getting the 404 error with capital and simple letters both – user9492428 Sep 02 '16 at 10:42
  • do you think it has something to do with permissions? – user9492428 Sep 02 '16 at 10:50
  • 1
    Can you try to edit `/var/www/html/hotelguide/public/.htaccess` and add `RewriteBase /hotelguide/` just below the `RewriteEngine On` please ? – jquiaios Sep 02 '16 at 11:41
  • Hi, again. When I did the edit you proposed, the webpage stopped working again (no worries I took a backup of the original htaccess). Again I got a 500 Internal Server error and when I checked the server logs: `[core:error] [pid 2086] [client 112.134.83.66:35238] AH00124: Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace` Sorry for the late reply – user9492428 Sep 03 '16 at 06:05
  • Strange... Can you try to edit `/var/www/html/hotelguide/public/.htaccess` again, but this time add `RewriteBase /` just below the `RewriteEngine On`? – jquiaios Sep 03 '16 at 08:42
  • Like you said, I added `RewriteBase /` (without the hotelguide) right under `RewriteEngine On`. This time, the page loaded without any server error, but the CSS and JS are still 404. – user9492428 Sep 03 '16 at 10:30
  • you were right from the beginning. I **completely** forgot that Linux servers were case sensitive. I tried `` but that didn't work either, for some reason. So I just went to the FTP and changed _AdminLTE_ to _adminlte_ . Thanks for all your help. It was much appreciated. – user9492428 Sep 03 '16 at 11:24
  • You too! :) Best of luck! – user9492428 Sep 03 '16 at 11:41
0

You need to point Apache to a public directory and restart it:

DocumentRoot "/var/www/html/hotelguide/public"
<Directory "/var/www/html/hotelguide/public">

After doing that use /login URL instead of /public/login.

Community
  • 1
  • 1
Alexey Mezenin
  • 158,981
  • 26
  • 290
  • 279
  • I tried that. Now I am getting an HTTP 500 error saying `188.166.***.*** is not working. Cannot handle the request`. I thought this was due to permissions, but even after I ran `sudo chmod -R o+w hotelguide` and `sudo chmod -R o+w hotelguide/storage` I am still getting the same HTTP 500 error – user9492428 Sep 02 '16 at 07:55
  • Please post last error message instead of stack trace. – Alexey Mezenin Sep 02 '16 at 08:11
  • the stack trace is the last messages logged in the laravel log. If the error is not being logged, is there a problem with the permissions? – user9492428 Sep 02 '16 at 08:18
  • 1
    Can you check if your public folder is owned by www-data ? And provide the content of the .htaccess file (if existing) located in /var/www/html/hotelguide/public/ folder. – jquiaios Sep 02 '16 at 08:54
  • @Julqas I updated the question with the .htaccess file as requested. I am not sure how I could check if the public folder is owned by www-data – user9492428 Sep 02 '16 at 09:15
  • 1
    Can you provide the content of .htaccess file located in `/var/www/html/hotelguide/` this time please ? To check the owned of a folder, in CLI you can do `ls -l /var/www/html/hotelguide/` and check owner and group (something like `drwxr-xr-x 4 www-data www-data 4096 Aug 17 09:13 public`), or if you are using a graphic FTP client, I think doing a right click on folder then "properties", something like that can do the trick. – jquiaios Sep 02 '16 at 09:26
  • @Julqas When I ran `ls -l` I saw that the public folder is owned by `www-pub` as shown in this: `drwxr-sr-x 3 root www-pub 4096 Sep 2 11:48 public`. Also, I'm sorry but there is no .htaccess file in `var/www/html/hotelguide` The .htaccess folder is only present in the public folder – user9492428 Sep 02 '16 at 09:32
  • 1
    Not exactly, the owner of your public folder is `root`, and the group is `www-pub`. Can you provide the result of this command `groups www-pub` please ? And the value configured in your `/etc/apache2/envvars` file for APACHE_RUN_USER & APACHE_RUN_GROUP. – jquiaios Sep 02 '16 at 09:50
  • @Julqas When I try to run `groups www-pub` I get an error saying `groups: www-pub: no such user` and in the envvars file, `APACHE_RUN_USER = www-data` and `APACHE_RUN_GROUP = www-data` – user9492428 Sep 02 '16 at 09:55
  • 1
    If you can check what are the best practice in terms of permissions & such for Laravel, but doing a `chown -R root:www-data /var/www/html/hotelguide/` would do a lot more sense for me here.. If it's not working maybe you can try `chown -R www-data:www-data /var/www/html/hotelguide/` – jquiaios Sep 02 '16 at 09:59
  • @Julqas You are a God. The second code worked. For some reason none of my css files and js files are being, loaded though. When I check the inspector it says `http://188.166.***.***/bower_components/adminlte/bootstrap/css/bootstrap.min.css Failed to load resource: the server responded with a status of 404 (Not Found)` I don't understand this because bower_components is inside my `hotelguide/public` folder and the public folder is the root of my site – user9492428 Sep 02 '16 at 10:07
  • 1
    Glad it helped :) I will write an answer for next people to find directly the answer. For the css & js file, is the file `/var/www/html/hotelguide/public/bower_components/adminlte/bootstrap/c‌​ss/bootstrap.min.css` exists for example ? – jquiaios Sep 02 '16 at 10:10
0

Based on the location of your project. Add the configuration in httpd.conf as given below:

<Directory "/var/www/html/project_name/public">
   Allowoverride All
</Directory>
Danyal Sandeelo
  • 12,196
  • 10
  • 47
  • 78