avatar Deluxe Blog Tips About Projects

Setting file permissions for Laravel

This Lunar New Year, I had several days off. I decided to learn Laravel a bit. Learning by doing is always a good practice. So I migrated our company website from WordPress to Laravel. The website is pretty basic with only some pages and no blog. Converting it into Laravel is like rewriting the WordPress theme in Blade. And it was so easy with the help of my utility CSS library that the final CSS is only about 2KB.

I deployed the website to a VPS from Oracle using a small script to manage my VPS to install the LAMP stack, Git, Composer, and add domains.

The website is a normal Laravel app and was deployed with Composer. But I had a problem setting up file permissions for Laravel. Doing research, I found that it's a common problem for many people. And there are several workarounds. And this post is my finding and applies to my scenarios only.

Note that there are 2 users involved in the process:

  • www-data: The web server (Apache) user
  • ubuntu: My user that uploads files via SFTP and runs commands from the terminal

Laravel requires 2 folders that are writeable by the web server:

  • storage
  • bootstrap/cache

Also, the current user must have write permission for all files and folders to run commands from the terminal.

To keep things simple, I set ubuntu (my user) as the owner of all files and folders. So it has the write permission. And add the write permission for storage and bootstrap/cache folders.

Here are my commands:

# cd to the website folder
cd /var/www/elightup.com

# Reset permissions to 644 for files and 755 for folders
sudo find . -type f -exec chmod 664 {} \;
sudo find . -type d -exec chmod 775 {} \;

# Set the owner to ubuntu
sudo chown ubuntu. . -R

# Set write permission to the web server
chmod o+w storage bootstrap/cache

🔥 HOT: Interested in boosting your WordPress SEO? My Slim SEO plugin is a super lighweight and automated plugin that handles most the hard work for you: meta tags, sitemap, redirection, schema & link building.

👉 Have a look and you will love it: wpslimseo.com