1

Previously, I've asked for a Laravel issue in this question:

Laravel: Routing conflict when launching app by accesing "http://localhost/<myapp>/public", when project folder is placed in default Apache directory

There, I've mentioned that I have a Laravel project folder placed into the default Apache root directory. That's it, the one that is used for placing the content of any website. In my Linux Mint installation, that directory is: "/var/www/html/", so my project is in a subdirectory called "infoalq".

Also, I've mentioned I had two ways for viewing the content of the project. One of them is running the command "php artisan serve" in the terminal, while placed in the project folder (in my case, "/var/www/html/infoalq/") and then, going to the URL "http://localhost:8000" (using port 8000) in the browser. The other way is just going to the URL "http://localhost/infoalq/public/" (using the HTTP port 80, like is configured in Apache by default), just with having the Apache server active.

The issue is this one: I can't access simultaneously to the content of the app in both ways. I mean, if I access to it by going to "http://localhost:8000", it shows perfectly the welcome view, but then, if I go to "http://localhost/infoalq/public/" in another tab in the same session, I get an error page showing this:

UnexpectedValueException
The stream or file "/var/www/html/infoalq/storage/logs/laravel.log" could not be opened in append mode: Failed to open stream: Permission denied The exception occurred while attempting to log: The stream or file "/var/www/html/infoalq/storage/logs/laravel.log" could not be opened in append mode: Failed to open stream: Permission denied The exception occurred while attempting to log: The stream or file "/var/www/html/infoalq/storage/logs/laravel.log" could not be opened in append mode: Failed to open stream: Permission denied The exception occurred while attempting to log: The stream or file "/var/www/html/infoalq/storage/logs/laravel.log" could not be opened in append mode: Failed to open stream: Permission denied The exception occurred while attempting to log: The stream or file "/var/www/html/infoalq/storage/logs/laravel.log" could not be opened in append mode: Failed to open stream: Permission denied The exception occurred while attempting to log: The stream or file "/var/www/html/infoalq/storage/logs/laravel.log" could not be opened in append mode: Failed to open stream: Permission denied The exception occurred while attempting to log: The stream or file "/var/www/html/infoalq/storage/logs/laravel.log" could not be opened in append mode: Failed to open stream: Permission denied The exception occurred while attempting to log: The stream or file "/var/www/html/infoalq/storage/logs/laravel.log" could not be opened in append mode: Failed to open stream: Permission denied The exception occurred while attempting to log: The stream or file "/var/www/html/infoalq/storage/logs/laravel.log" could not be opened in append mode: Failed to open stream: Permission denied The exception occurred while attempting to log: The stream or file "/var/www/html/infoalq/storage/logs/laravel.log" could not be opened in append mode: Failed to open stream: Permission denied The exception occurred while attempting to log: The stream or file "/var/www/html/infoalq/storage/logs/laravel.log" could not be opened in append mode: Failed to open stream: Permission denied The exception occurred while attempting to log: The stream or file "/var/www/html/infoalq/storage/logs/laravel.log" could not be opened in append mode: Failed to open stream: Permission denied The exception occurred while attempting to log: file_put_contents(/var/www/html/infoalq/storage/framework/sessions/adfnCUfB0vFv305r0P8mUgkdJHbvlfqctbHu6etu): Failed to open stream: Permission denied Context: {"exception":{}} Context: {"exception":{}} Context: {"exception":{}} Context: {"exception":{}} Context: {"exception":{}} Context: {"exception":{}} Context: {"exception":{}} Context: {"exception":{}} Context: {"exception":{}} Context: {"exception":{}} Context: {"exception":{}} Context: {"exception":{}}

Something similar happens in the opposite case. When I try to access the website by the URL "http://localhost:8000" in another tab, after accessing to it by the URL "http://localhost/infoalq/public/" (which initially works fine), I get an error page showing this:

ErrorException
file_put_contents(/var/www/html/infoalq/storage/framework/sessions/IlqNl7oqUUAiMPAUjx6FlQOvOsNcHadDLNePjvG3): Failed to open stream: Permission denied

So then, I have to restart the browser every time I want to view the app running with any of those ways.

As I've mentioned in the other post, I'm using:

  • Linux Mint 21 Vanessa

  • Apache/2.4.52 (Ubuntu)

  • PHP 8.2.1

  • Laravel v9.48.0

Does anyone knows if is there a solution for this? Or it's just like this and there's nothing to do? I mean, perhaps there is no way to run the project simultaneously in both ways, without restarting the browser. I think there it must be a conflict between the Apache server and the PHP server. If there's any concept that I'm not clear about or I'm confusing about, please let me know.

Thank you very much!

Leandro

  • Have you tried running "chmod 755 -r ./storage" for the storage directory? – slaff.bg Jan 28 '23 at 03:13
  • You should also make a virtual host if you missed it. – slaff.bg Jan 28 '23 at 03:17
  • @slaff.bg I've tried this: 'leandro@leandro-Lenovo-B50-10:/var/www/html/infoalq$ sudo chmod 755 -r ./storage' And I got this: 'chmod: no se puede acceder a '755': No existe el archivo o el directorio' In english: 'Cannot access to '755': Not such file or directory' About the virtual host, I've configured one with these steps (in Spanish): [link] (https://rogertm.com/configurar-virtual-host-servidor-lamp-local/) However, I've got a little bit messed up Thanks for suggesting! – Leandro Caplan Jan 28 '23 at 03:32
  • 1
    You absolutely should not put your project under the Apache docroot. The idea is to have the docroot map to the `public/` dir of your project. If your public dir is at `/var/www/html/infoalq/public`, you should edit your Apache config and make that full directory the `DocumentRoot`. If you don't do this, it means your your entire project - including your `.env` and any sensitive info! - is public and browseable, instead of just the intended code under `public/`. – Don't Panic Jan 28 '23 at 03:56
  • 1
    As to your actual problem - you are running 2 webservers, as 2 different users. Apache runs as some user, maybe `www-data`. When you visit the site through Apache, it is that user that creates your logs and session files on disk. Next you run php's built in dev server, which I guess runs as the user you are logged in as when you type `php artisan serve`. That is almost certainly not `www-data`, so when you visit this other version of your site, that user will try to write to the logs/sessions/etc, and does not have permissions. – Don't Panic Jan 28 '23 at 04:00
  • 1
    The solution is to not do this - it makes no sense to serve your site with 2 different servers simultanesously. The php dev server is fine for very basic development but has severe limitations which you will probably hit soon with a Laravel project. And if you have Apache set up and configured, why bother with the php dev server? NOTE - you really have to fix your Apache config though. – Don't Panic Jan 28 '23 at 04:02
  • @Don'tPanic I appreciate your answer. I'll follow your advice and make that full directory the DocumentRoot in Apache config. Despite that at the moment, I have absolutely none sensitive info, I'll probably have it in the future. Thanks a lot! – Leandro Caplan Jan 28 '23 at 04:14

1 Answers1

0

Using the terminal in /etc/apache2/sites-available/, create a file with the following name: infoalq.local.conf

Add the following content to it:

<VirtualHost *:80>
        ServerName infoalq.local
        ServerAlias www.infoalq.local

        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html/infoalq

        <Directory /var/www/html/infoalq>
                Options Indexes MultiViews
                AllowOverride None
                Require all granted
        </Directory>

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

After that you have to ensite the domain name:

sudo a2ensite infoalq.local
sudo systemctl reload apache2.service

Into /etc/hosts add the following line:

127.0.0.1       infoalq.local www.infoalq.local

Use the following URL address: http://infoalq.local

slaff.bg
  • 139
  • 1
  • 6
  • I've replaced the text at "000-default.conf". Then, I run "sudo a2ensite infoalq.local", and I get: "ERROR: Site infoalq.local does not exist!". After that, I run "sudo systemctl reload apache2.service" , and added the line "127.0.0.1 infoalq.local www.infoalq.local" at "/etc/hosts", and tried to reload the server both before and after adding that line. All I got it was, that when I access "http://localhost", just opens the Laravel project folder as root directory, instead of showing Apache2 Default Page, so I did a rollback. My error: https://flareapp.io/share/bP984opm#F40 – Leandro Caplan Jan 28 '23 at 03:58
  • Well, when I last edited the "000-default.conf", I've preserved the original content, and after that added the code you posted. The result is, that the "http://infoalq.local" URL works fine, that's it, the virtual host is well configured. However, It didn't solved the issue I've asked for, I'm still having the same problem. Anyway, It was a helpful tip, thank you for it! – Leandro Caplan Jan 28 '23 at 04:06
  • I forgot to say to change the name of the config file or make a new one with the following name: infoalq.local.conf I will also edit the post. – slaff.bg Jan 28 '23 at 04:06
  • 1
    @Leandro Caplan Thanks for the feedback. Everything should be fine now. I have edited the post. – slaff.bg Jan 28 '23 at 04:12
  • 1
    Linux Mint is a community-driven Linux distribution based on Ubuntu, so it probably uses the same command and architecture as Ubuntu. However, if there is any other problem, write here, and I will look into it. – slaff.bg Jan 28 '23 at 04:18
  • Thanks to you. I'll probably continue editing those config files tomorrow, to make them as tidy as possible (here in Argentina is 01:30 in the morning). I already got my virtual host working fine, and the main issues solved (just avoiding running two different servers into one folder like Don't Panic says, and I had another important issue solved in another post). However, I really appreciate your predisposition! Thanks again! – Leandro Caplan Jan 28 '23 at 04:30