I recently created a Laravel application as a side-project to re-learn the framework. (I’ll post more about it later. It’s a URL Shortener). The documentation for getting this application was mostly correct. However, I discovered at least one issue because I wanted to save money and use a SQLite database instead of the more costly MySQL one.
Transfer files
Get your files over to the site by rsync-ing the directory to the protected area:
# Replace $ACCOUNT with your NFSN account username and
# $HOST with your assigned server hostname.
$ rsync -avz --exclude='.git' \
--exclude='node_modules' \
--exclude='storage/logs/*' \
--exclude='storage/framework/cache/*' \
--exclude='storage/framework/sessions/*' \
--exclude='storage/framework/views/*' \
--exclude='.env' --exclude='vendor' \
--exclude='.DS_Store' --exclude='*.log' \
. $ACCOUNT@$HOST:/home/protected/laravel-app/Code language: Bash (bash)
Update .env
Depending on your application this could be complicated or easy. Copy your .env.example to .env and make any changes necessary.
Set file system permissions
I found 3 directories I needed to update, if you aren’t using the default sqlite database you can skip that one.
#!/bin/bash
directories=(
"database" # ⚠️ where the sqlite database goes
"storage" # logs/cache
"bootstrap/cache" # cache (duh)
)
for directory in "${directories[@]}"; do
chown -R web "$directory"
chmod -R 775 "$directory"
doneCode language: PHP (php)
Get public directory configured
The public directory is locked down so it can’t be moved or overwritten. I moved everything in my Laravel app’s public directory into the nearlyfreespeech one, deleted the empty directory, and then linked to the canonical one. Effectively it lets the public directory be in 2 places at the same time.
From inside the laravel-app directory:
$ ln<span style="background-color: initial; font-size: inherit; text-align: initial; text-wrap-mode: wrap; color: inherit; letter-spacing: -0.015em;"> -s ../../public public</span>Code language: Bash (bash)
Rebuild application
You can forego this step if you transfer your vendor directory and run npm run build first too. From the Laravel app directory:
composer installnpm installnpm run buildphp artisan optimize
.htaccess
Either move or copy the provided .htaccess file to public. Laravel requires its own .htaccess rules for routing (otherwise all requests won’t be directed through index.php).
Conclusion
That should be it. Test your application and get it running. I found a problem with a models generated attributes–💡I had to add the $appends property–but in general it seems to be working well.
