The stream or file "/var/www/html/myscipt/storage/logs/laravel.log" could not be opened: failed to open stream: Permission denied

Posted December 4, 2019 39k views

I uploaded script on the var/www/html document root, configured the virtual host on /etc/apache2/sites-available/000-default.conf by changing the document root from

DocumentRoot /var/www/html to DocumentRoot /var/www/html/myscript/public
according to the docummentation of the script i bought.

Also, configured the /etc/apache2/apache2.conf by changing:

<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted


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

Then restart apache using the command:
sudo systemctl restart apache2

But before then I have created custom virtual host following the guide on this article:

Because of this advice by the writer below on that article:

“Apache on Ubuntu 18.04 has one server block enabled by default that is configured to serve documents from the /var/www/html directory. While this works well for a single site, it can become unwieldy if you are hosting multiple sites. Instead of modifying /var/www/html, let’s create a directory structure within /var/www for our your_domain site, leaving /var/www/html in place as the default directory to be served if a client request doesn’t match any other sites”.

After that, I uploaded the file/script on the document root of the custom virtual host I created following the above article. When I visited the site the script I uploaded appear on the browser. because of that, I deleted the custom virtual host directory from Filezilla including the app/script and also disabled the custom virtual host and enabled the default using this command:

sudo a2dissite mydomain.conf
sudo a2ensite 000-default.conf

then restart using this command:
sudo systemctl restart apache2

I now uploaded the script on the default one which the document root is var/www/html using Filezilla and do the configurations shown above. I also extracted the file before uploading it.

So, after everything, when I visited my site using the IP Address I found this error:
The stream or file ”/var/www/html/myapp/storage/logs/laravel.log" could not be opened: failed to open stream: Permission denied"

but when I visit the site using the domain name I also found this error:
“Not Found
The requested URL was not found on this server”

Again, when I uploaded the composer, I didn’t complete the rest steps, I only uploaded the composer and stopped there, I didn’t go further to set dependency and others because that part on the guide is complicated for me, I didn’t understand it at all. This is the guide below:
So, I don’t know if that is part of the problem am facing now.

I also found some articles on the web to solve this error. the command given there didn’t work for me. These are the commands and the responses I got when I run them:

sudo chown -R $USER:www-data storage : No such file or directory
sudo chmod -R 777 storage : No such file or directory
chown -R www-data:www-data /var/www/html/laravel: No such file or directory
composer install : composer could not find a composer.json in /root

Please everyone what do I do to solve this problem to get my site working fine. Thank

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
2 answers


It looks like that there is no such directory /var/www/html/laravel, that is why your chmod command is failing.

What you need to do is run the following command instead:

chown -R www-data:www-data /var/www/html

Then this should work as normal as Apache would have access to the Laravel log file.

Hope that this helps!

  • Wow, it worked, thanks so much but it only worked for the IP address but the domain name does not work. It said 404 not found
    Not Found
    The requested URL was not found on this server.
    what do I do to get the domain work too? thanks

    • Hi @IGLIGHT,

      I’m happy to hear that it’s working now!

      Regarding the domain, you need to first check that the document root for your domain name’s Apache Vhost is setup correctly to /var/www/html.

      What you could do is:

      • Check your available virtual hosts:
      ls -l /etc/apache2/sites-enabled
      • Find the virtual host for your domain name

      • Open the file with your favorite text editor:

      nano /etc/apache2/sites-enabled/your-domain.conf
      • Find the document root reference and make sure that it matches the /var/www/html directory

      • After that run an Apache config test:

      apachectl -t
      • If you get Syntax OK go ahead and restart Apache:
      systemctl restart apache2

      Hope that this helps!

      • Hello @bobbyiliev,

        Everything is working well now, what happened was that I didn’t clear cache on chrome. I observed that when I tried visiting the site on the internet explorer and Mozilla Firefox browser it was working, so I now exit from chrome, reopen it again and tried visiting the site using chrome. Now it’s working well now both in chrome and other browsers. Thanks for your support so far @bobbyiliev am grateful.

        But one thing is left. The SSL that I install initially is not working again, now the site is no longer secured. Should I try reinstall the SSL again or what do I do now? Thanks

        • Hi @IGLIGHT,

          No problem at all! I’m happy to hear that it is working now.

          Yes, I believe that it should be ok to try using the certbot command to issue a new SSL certificate.

          Let me know how it goes!