Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| deploy_laravel_application_on_a_linux_vds [2025/05/12 12:25] – kkaragoz | deploy_laravel_application_on_a_linux_vds [2025/05/13 07:48] (current) – kkaragoz | ||
|---|---|---|---|
| Line 95: | Line 95: | ||
| </ | </ | ||
| ===== 3- Bind a Domain ===== | ===== 3- Bind a Domain ===== | ||
| - | Connect a domain to a server can be done by simply changing the DNS records of the domain. Lets assume the VDS server' | + | Connect a domain to a server can be done by simply changing the DNS records of the domain. You will typically manage these records through your **domain registrar' |
| + | |||
| + | Here is an example DNS record table you might configure: | ||
| ^ Type ^ Name ^ Content | ^ Type ^ Name ^ Content | ||
| Line 103: | Line 105: | ||
| | AAAA | @ | Public IPv6 | Auto | | | AAAA | @ | Public IPv6 | Auto | | ||
| - | | + | |
| - | | + | |
| - | | + | * '' |
| - | | + | |
| - | | + | |
| + | * '' | ||
| + | |||
| + | {{ : | ||
| + | |||
| + | You don't have to add explicit records for every single subdomain if you use the '' | ||
| + | |||
| + | **DNS Propagation: | ||
| - | {{ : | + | Once these DNS records are pointing to your server' |
| ===== 4- Nginx Installation & Configuration ===== | ===== 4- Nginx Installation & Configuration ===== | ||
| [[https:// | [[https:// | ||
| Line 236: | Line 245: | ||
| ===== 5- SSL Certification: | ===== 5- SSL Certification: | ||
| - | It is time to apply SSL certificates | + | It is essential |
| + | |||
| + | You mentioned using " | ||
| + | |||
| + | To install | ||
| <code bash> | <code bash> | ||
| sudo apt update && sudo apt upgrade | sudo apt update && sudo apt upgrade | ||
| </ | </ | ||
| - | We are ready to install | + | Now we are ready to install Certbot: |
| <code bash> | <code bash> | ||
| sudo apt install certbot python3-certbot-nginx | sudo apt install certbot python3-certbot-nginx | ||
| </ | </ | ||
| - | After installation is completed, | + | After installation is completed, |
| <code bash> | <code bash> | ||
| - | cd / | + | sudo certbot |
| </ | </ | ||
| + | When you run this command, Certbot will: | ||
| + | * Prompt you for an email address for urgent renewal or security notices. | ||
| + | * Ask you to agree to the terms of service. | ||
| + | * Scan your Nginx configuration files for '' | ||
| + | * Present a list of identified domains and ask you to select which ones you want certificates for. | ||
| + | * Communicate with the Let's Encrypt servers to verify domain ownership (usually by serving a temporary file through your web server). | ||
| + | * If successful, it will obtain the SSL certificates. | ||
| + | * **Automatically modify** your Nginx configuration file(s) in '' | ||
| + | * Add the '' | ||
| + | * Point to the correct '' | ||
| + | * (Optionally) Ask if you want to redirect HTTP traffic (port 80) to HTTPS (port 443). It is highly recommended to choose the redirect option for better security and SEO. | ||
| + | * **Automatically set up a renewal mechanism** (usually a systemd timer or cron job) that will attempt to renew your certificates before they expire (Let's Encrypt certificates are valid for 90 days). | ||
| - | Then run the following command for automatic SSL certificate | + | After Certbot completes its process |
| <code bash> | <code bash> | ||
| - | sudo certbot | + | sudo nginx -t # Test Nginx configuration for syntax errors |
| - | </ | + | sudo systemctl reload nginx # Reload Nginx to apply changes |
| - | Enter the related fields like email, confirm terms, select domains, etc. Then Certbot will notify about the certification status. If it's done, you can reload the nginx again. | + | |
| - | <code bash> | + | |
| - | sudo systemctl reload nginx | + | |
| </ | </ | ||
| + | You can verify that SSL is working by visiting your domain(s) in a web browser and checking for the padlock icon in the address bar and ensuring the URL starts with '' | ||
| + | |||
| + | **Important: | ||
| ===== 6- PHP Installation ===== | ===== 6- PHP Installation ===== | ||
| Let's proceed to uninstall the currently installed PHP packages and then install a specific version (like PHP 8.2) cleanly using the Ondřej Surý PPA, which is the recommended way for up-to-date PHP versions on Ubuntu/ | Let's proceed to uninstall the currently installed PHP packages and then install a specific version (like PHP 8.2) cleanly using the Ondřej Surý PPA, which is the recommended way for up-to-date PHP versions on Ubuntu/ | ||
| Line 493: | Line 519: | ||
| </ | </ | ||
| - | We need to set the [[https:// | ||
| <WRAP center round info 60%> | <WRAP center round info 60%> | ||
| Laravel will need to write to the bootstrap/ | Laravel will need to write to the bootstrap/ | ||
| + | </ | ||
| + | |||
| + | We need to set the [[https:// | ||
| + | |||
| + | |||
| + | <WRAP center round alert 60%> | ||
| + | The method given below is not a safe approach! | ||
| </ | </ | ||
| <code bash> | <code bash> | ||
| - | sudo chmod -R 755 storage | + | sudo chmod -R 0777 storage |
| </ | </ | ||
| <code bash> | <code bash> | ||
| - | sudo chmod -R 755 bootstrap/ | + | sudo chmod -R 0777 bootstrap/ |
| + | </ | ||
| + | |||
| + | Using '' | ||
| + | |||
| + | ==== Laravel - Safer & More Standard Approach ==== | ||
| + | |||
| + | The goal is to grant write permissions only to the specific user or group that the web server (Nginx/ | ||
| + | |||
| + | On Debian systems, the web server user and group is typically www-data. | ||
| + | |||
| + | Here's a safer and more standard approach: | ||
| + | |||
| + | === Step 1: Ensure Correct Ownership === | ||
| + | First, make sure the entire application directory is owned by your deployment user (vicky) and their primary group (vicky). You already have this step, which is correct: | ||
| + | |||
| + | <code bash> | ||
| + | sudo chown -R vicky:vicky / | ||
| + | </ | ||
| + | |||
| + | === Step 2: Change Group Ownership for Writable Directories === | ||
| + | Change the group ownership of the storage and bootstrap/ | ||
| + | |||
| + | <code bash> | ||
| + | sudo chgrp -R www-data / | ||
| + | sudo chgrp -R www-data / | ||
| + | </ | ||
| + | |||
| + | === Step 3: Set Appropriate Permissions === | ||
| + | Now, set the permissions. A common pattern is 775 for directories and 664 for files. | ||
| + | * 775 for directories means: | ||
| + | * Owner (vicky): Read, Write, Execute (7) - Can list contents, create/ | ||
| + | * Group (www-data): Read, Write, Execute (7) - Can list contents, create/ | ||
| + | * Others: Read, Execute (5) - Can list contents, navigate into, but cannot write or delete. | ||
| + | |||
| + | |||
| + | * 664 for files means: | ||
| + | * Owner (vicky): Read, Write (6) - Can read and modify the file. | ||
| + | * Group (www-data): Read, Write (6) - Can read and modify the file. | ||
| + | * Others: Read (4) - Can only read the file. | ||
| + | |||
| + | |||
| + | You can apply these recursively using find for better control over files vs. directories: | ||
| + | |||
| + | <code bash> | ||
| + | # Set permissions for directories within storage and bootstrap/ | ||
| + | sudo find / | ||
| + | sudo find / | ||
| + | |||
| + | # Set permissions for files within storage and bootstrap/ | ||
| + | sudo find / | ||
| + | sudo find / | ||
| + | </ | ||
| + | |||
| + | Note: You could also do sudo chmod -R 775 / | ||
| + | |||
| + | === Step 4: Set SetGID Bit (Recommended) === | ||
| + | To ensure that any new files or directories created within storage and bootstrap/ | ||
| + | |||
| + | <code bash> | ||
| + | sudo chmod g+s / | ||
| + | sudo chmod g+s / | ||
| + | </ | ||
| + | |||
| + | ==== Static App - Appropriate Permissions ==== | ||
| + | Generally do not need to set the same 775 group write permissions or change the group ownership to www-data for your static application' | ||
| + | |||
| + | The goal for static assets is to allow the web server (www-data user) to read and execute/ | ||
| + | |||
| + | A standard and safe permission set for static web content folders is: | ||
| + | |||
| + | **Ownership**: | ||
| + | |||
| + | <code bash> | ||
| + | sudo chown -R vicky:vicky / | ||
| + | </ | ||
| + | |||
| + | **Permissions**: | ||
| + | * Directories: | ||
| + | * Files: 644 (Owner: Read, Write; Group: Read; Others: Read). This allows the owner (vicky) to read and modify the files and allows the web server user (www-data) to read the files. | ||
| + | |||
| + | You can set these permissions recursively: | ||
| + | |||
| + | <code bash> | ||
| + | # Ensure ownership is correct | ||
| + | sudo chown -R vicky:vicky / | ||
| + | |||
| + | # Set directory permissions to 755 | ||
| + | sudo find / | ||
| + | |||
| + | # Set file permissions to 644 | ||
| + | sudo find / | ||
| + | </ | ||
| + | |||
| + | A slightly simpler, though less precise, common alternative for static sites is just: | ||
| + | |||
| + | <code bash> | ||
| + | # Ensure ownership is correct | ||
| + | sudo chown -R vicky:vicky / | ||
| + | |||
| + | # Set recursive permissions to 755 (grants execute to files, which is harmless for static assets) | ||
| + | sudo chmod -R 755 / | ||
| </ | </ | ||
| Line 519: | Line 652: | ||
| php artisan migrate | php artisan migrate | ||
| </ | </ | ||
| - | |||
