To deploy a Laravel + Inertia app on an Ubuntu server with Nginx, you will need to follow these steps:
- Install Nginx on your Ubuntu server if it's not already installed:
sudo apt update
sudo apt install nginx
- Configure Nginx to serve your Laravel + Inertia app. Create a new Nginx server block configuration file:
sudo nano /etc/nginx/sites-available/myapp
- Inside the file, add the following configuration:
server {
listen 80;
server_name your-domain.com;
root /var/www/myapp/public;
index index.html index.htm index.php;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}
Replace your-domain.com with your actual domain name and /var/www/myapp with the path to your Laravel + Inertia app's root directory.
- Enable the Nginx server block configuration:
sudo ln -s /etc/nginx/sites-available/myapp /etc/nginx/sites-enabled/
- Test the Nginx configuration for any syntax errors:
sudo nginx -t
- If the test is successful, restart Nginx to apply the changes:
sudo systemctl restart nginx
- Install Node.js and npm on your server if they are not already installed. You can use the following commands to install them:
sudo apt install nodejs
sudo apt install npm
- Navigate to your Laravel + Inertia app's root directory and install the dependencies:
cd /var/www/myapp
npm install
- Build the production assets using npm:
npm run prod
- Ensure that the appropriate permissions are set for the storage and bootstrap/cache directories:
sudo chown -R www-data:www-data /var/www/myapp/storage /var/www/myapp/bootstrap/cache
- Your Laravel + Inertia app should now be deployed and accessible through your domain name.
Note: Make sure you have already configured your domain to point to your server's IP address.
I hope this helps! Let me know if you have any further questions.