Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

UUID's avatar
Level 6

Hard Time

I want Ensure Correct Ownership:
-What is the Recommendations for the folder in the Server.
-Which folders belong to www:data and which to ubuntu.
-How not effect to jobs and Logs .




-rwxrwxr-x   1 ubuntu ubuntu   4028 Nov  9  2022 README.md
drwxrwxr-x  13 ubuntu ubuntu   4096 Feb 21 08:00 app
-rwxrwxr-x   1 ubuntu ubuntu   1739 Nov  9  2022 artisan
drwxrwxrwx   3 ubuntu ubuntu   4096 Nov 10  2022 bootstrap
-rwxrwxr-x   1 ubuntu ubuntu   2246 Dec  8 10:58 composer.json
-rwxrwxr-x   1 ubuntu ubuntu 359187 Feb 20 15:31 composer.lock
drwxrwxr-x   2 ubuntu ubuntu   4096 Dec 11 09:18 config
drwxrwxr-x   5 ubuntu ubuntu   4096 Nov 10  2022 database
drwxrwxr-x   3 ubuntu ubuntu   4096 Nov 10  2022 lang
drwxrwxr-x 501 ubuntu ubuntu  20480 Nov 21 12:59 node_modules
-rwxrwxr-x   1 ubuntu ubuntu 720204 Nov 21 12:59 package-lock.json
-rwxrwxr-x   1 ubuntu ubuntu    771 Nov 21 12:59 package.json
-rwxrwxr-x   1 ubuntu ubuntu   1206 Nov  9  2022 phpunit.xml
drwxrwxr-x  26 ubuntu ubuntu   4096 Feb 27 13:30 public
drwxrwxr-x   7 ubuntu ubuntu   4096 Feb 21 08:10 resources
drwxrwxr-x   2 ubuntu ubuntu   4096 Nov 10  2022 routes
drwxrwxr-x   6 ubuntu ubuntu   4096 Nov 10  2022 storage
drwxrwxr-x   4 ubuntu ubuntu   4096 Nov 10  2022 tests
drwxr-xr-x  48 ubuntu ubuntu   4096 Feb 20 15:50 vendor
-rwxrwxr-x   1 ubuntu ubuntu    250 Feb 22  2023 vite.config.js
-rwxrwxr-x   1 ubuntu ubuntu    970 Feb 22  2023 webpack.mix.js

thank u for helping 😚

0 likes
1 reply
LaryAI's avatar
Level 58

When setting up file permissions and ownership for a web server, it's important to ensure that the web server has the necessary permissions to read and write to certain directories, while also maintaining security by limiting permissions where they are not needed.

Here's a general recommendation for setting permissions and ownership for a Laravel application:

  1. The storage and bootstrap/cache directories need to be writable by the web server because Laravel writes cache files and logs to these directories. The storage directory also contains user-uploaded files.

  2. The public directory should be readable by the web server as it contains assets like images, JavaScript, and CSS that need to be served to clients.

  3. Most other directories and files should have read-only permissions for the web server for security reasons.

  4. The user that the web server runs as (often www-data for Apache and nginx on Ubuntu) should own the directories that need write permissions.

Here's how you can set the permissions:

# Assuming your Laravel project is located in /var/www/html/your-project

# Change the ownership of the storage and bootstrap/cache directories to www-data
sudo chown -R www-data:www-data /var/www/html/your-project/storage
sudo chown -R www-data:www-data /var/www/html/your-project/bootstrap/cache

# Set the correct permissions for directories and files
sudo find /var/www/html/your-project -type d -exec chmod 755 {} \;
sudo find /var/www/html/your-project -type f -exec chmod 644 {} \;

# Ensure the storage and bootstrap/cache directories are writable by the web server
sudo chmod -R 775 /var/www/html/your-project/storage
sudo chmod -R 775 /var/www/html/your-project/bootstrap/cache

This setup ensures that:

  • The web server has read and execute permissions on directories and read permissions on files.
  • The web server can write to storage and bootstrap/cache.
  • The permissions are secure for other directories and files.

Remember to replace /var/www/html/your-project with the actual path to your Laravel project.

As for the jobs and logs:

  • Laravel's queue jobs are typically processed by a queue worker, which should run under a user that has write permissions to the storage directory to create log files.
  • Laravel's log files are written to the storage/logs directory, so the same permissions apply as mentioned above.

By following these recommendations, you should have a secure and functional setup for your Laravel application on the server.

Please or to participate in this conversation.