Deploying Laravel Jetstream Inertia based app on LEMP stack and Ubuntu 22
Today I deployed a Laravel 10 Jetstream Inertia based app on LEMP stack and Ubuntu 22. Here is the gist of what I went through.
- Deploy server with Ubuntu 22
- I deployed a private Github repo so I needed to generate a public ssh key for your user.
ssh-keygen -t ed25519-sk -C "YOUR_EMAIL"
. Next add that key to your Github repo deploy tokens. - Clone repo to /var/www/[your-site]
git clone [myrepo] .
- Install Basic Laravel with LEMP stack and Composer with this tutorial. Also handy to refer to Laravel's recommended Nginx config
Used
strong (level 2) password for mysql setup which required logging in
using sudo mysql and setting the root password before continuing with
the usual sudo mysql_secure_installation
process.
Also needed additional php plugins for my app php-gd, php-zip
My public folder was not in the root so I have to set it to ./laravel/public for my vhost file.
In order to mock my production domain (which does not have DNS records yet). I edited my local hosts file (windows) and added the public IP of my server and my production domain. This way I can access my production domain and see my site (You could also access your site with your servers IP).
- Install Node 20.x using this tutorial. Do not install the default nodejs package unless you want an older version
- Setup swap so that
npm run build
works better using this tutorial. Before doing this the server would freeze and not complete the build process. - Install app using repo readme ie
cd laravel
# composer install without dev dependencies
composer install --optimize-autoloader --no-dev
cp .env.example .env
nano .env
# update admin login, database details, smtp and repatcha
# turn off debugging
Run these commands to install npm packages and compile the front end.
npm i
npm run build
- Set up Laravel cron using docs
# example
* * * * * cd /path-to-your-project && php artisan schedule:run >> /dev/null 2>&1
Todo
- Setup SMTP
- Setup DNS records for Let Encrypt
Comments
Post a Comment