[{"data":1,"prerenderedAt":26},["ShallowReactive",2],{"article-deploying-laravel-with-php-8-4-and-nginx-on-ubuntu-a-production-ready-guide":3},{"id":4,"title":5,"slug":6,"summary":7,"thumbnail":8,"category":9,"tags":15,"categoryId":10,"tagIds":21,"date":22,"updatedAt":22,"views":23,"readingTime":24,"content":25},"NNIuMMku8AYheiRIift9","Deploying Laravel with PHP 8.4 and Nginx on Ubuntu: A Production-Ready Guide","deploying-laravel-with-php-8-4-and-nginx-on-ubuntu-a-production-ready-guide","Learn how to configure a high-performance environment for Laravel using PHP 8.4 and Nginx on Ubuntu. This guide covers everything from PPA installation to advanced Nginx virtual host configuration.","",{"id":10,"name":11,"description":12,"updatedAt":13,"slug":14,"createdAt":13},"Gxt2q3kFYWvJFkbBBB2R","Laravel","the PHP framework for artisan","2025-12-31T00:34:45.475Z","laravel",[16],{"id":17,"color":18,"createdAt":19,"slug":14,"updatedAt":20,"name":11},"U2ARZAP6vtCPeEX2o8ZI","#ff2d20","2026-02-16T04:41:46.456Z","2026-06-04T12:55:00.696Z",[17],"2026-02-17T01:00:15.468Z",11,4,"## Introduction\n\nWhile Laravel's built-in development server (`php artisan serve`) is convenient for local coding, it is not designed for production or staging environments. For high-performance, concurrent handling, and robust security, a combination of Nginx and PHP-FPM is the industry standard. With the release of PHP 8.4, developers can now leverage new language features like Property Hooks and Asymmetric Visibility while maintaining the lightning-fast execution Laravel is known for.\n\nThis guide provides a comprehensive, step-by-step walkthrough for setting up Laravel on an Ubuntu server using Nginx and PHP 8.4, specifically focusing on virtual host configuration to bypass the need for the artisan development server.\n\n## Prerequisites\n\nBefore starting, ensure you have:\n- An Ubuntu 22.04 or 24.04 server instance.\n- A user with `sudo` privileges.\n- Basic familiarity with the command line.\n- A domain name or IP address pointing to your server.\n\n## Step 1: Update the System and Add Repositories\n\nFirst, ensure your package list is up to date. Since PHP 8.4 is the latest version, we need to add the `ondrej/php` PPA (Personal Package Archive) to fetch the most recent binaries.\n\n```bash\nsudo apt update && sudo apt upgrade -y\nsudo apt install -y software-properties-common\nsudo add-apt-repository ppa:ondrej/php -y\nsudo apt update\n```\n\n## Step 2: Install PHP 8.4 and Essential Extensions\n\nLaravel requires several PHP extensions to handle encryption, database connections, and string manipulation. We will install PHP 8.4-FPM (FastCGI Process Manager) which is necessary for Nginx to communicate with PHP.\n\n```bash\nsudo apt install -y php8.4-fpm php8.4-mysql php8.4-mbstring php8.4-xml php8.4-curl php8.4-zip php8.4-bcmath php8.4-intl php8.4-cli php8.4-gd\n```\n\nAfter installation, verify the version:\n\n```bash\nphp -v\n```\n\n## Step 3: Install Nginx\n\nNginx acts as our web server and reverse proxy. Install it using the following command:\n\n```bash\nsudo apt install -y nginx\n```\n\nEnsure the Nginx service is running and enabled to start on boot:\n\n```bash\nsudo systemctl enable nginx\nsudo systemctl start nginx\n```\n\n## Step 4: Install Composer and Laravel\n\nComposer is the dependency manager for PHP. We will install it globally and then create a new Laravel project in the `/var/www` directory.\n\n```bash\ncurl -sS https://getcomposer.org/installer | php\nsudo mv composer.phar /usr/local/bin/composer\n\ncd /var/www\nsudo composer create-project laravel/laravel my-laravel-app\n```\n\n## Step 5: Configure Permissions\n\nFor Nginx to serve the Laravel application, the web server user (`www-data`) must own the storage and bootstrap cache directories.\n\n```bash\nsudo chown -R www-data:www-data /var/www/my-laravel-app/storage\nsudo chown -R www-data:www-data /var/www/my-laravel-app/bootstrap/cache\nsudo chmod -R 775 /var/www/my-laravel-app/storage\n```\n\n## Step 6: Configure the Nginx Virtual Host\n\nInstead of running `php artisan serve`, we will create an Nginx server block. This configuration tells Nginx how to handle incoming requests and pass them to PHP 8.4-FPM.\n\nCreate a new configuration file:\n\n```bash\nsudo nano /etc/nginx/sites-available/my-laravel-app\n```\n\nPaste the following configuration, replacing `example.com` with your domain or IP address:\n\n```nginx\nserver {\n    listen 80;\n    listen [::]:80;\n    server_name example.com;\n    root /var/www/my-laravel-app/public;\n\n    add_header X-Frame-Options \"SAMEORIGIN\";\n    add_header X-Content-Type-Options \"nosniff\";\n\n    index index.php;\n\n    charset utf-8;\n\n    location / {\n        try_files $uri $uri/ /index.php?$query_string;\n    }\n\n    location = /favicon.ico { access_log off; log_not_found off; }\n    location = /robots.txt  { access_log off; log_not_found off; }\n\n    error_page 404 /index.php;\n\n    location ~ \\.php$ {\n        fastcgi_pass unix:/var/run/php/php8.4-fpm.sock;\n        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;\n        include fastcgi_params;\n    }\n\n    location ~ /\\.(?!well-known).* {\n        deny all;\n    }\n}\n```\n\n### Key Configuration Details:\n- **root**: Points to the `/public` directory of Laravel, not the root folder.\n- **try_files**: Ensures that SEO-friendly URLs are routed through `index.php`.\n- **fastcgi_pass**: Points to the PHP 8.4 socket file.\n\n## Step 7: Enable the Configuration and Restart Nginx\n\nEnable the site by creating a symbolic link to the `sites-enabled` directory and test the configuration for syntax errors.\n\n```bash\nsudo ln -s /etc/nginx/sites-available/my-laravel-app /etc/nginx/sites-enabled/\nsudo nginx -t\n```\n\nIf the test is successful, restart Nginx and PHP-FPM:\n\n```bash\nsudo systemctl restart nginx\nsudo systemctl restart php8.4-fpm\n```\n\n## Conclusion\n\nYou have successfully deployed a Laravel application on Ubuntu using PHP 8.4 and Nginx. By configuring a virtual host, you have created a environment that is significantly more stable and scalable than the default development server. Your application is now reachable via your domain name, with PHP-FPM efficiently handling processes in the background. \n\nFor a production environment, your next steps should include setting up an SSL certificate using Let's Encrypt and configuring a database like MySQL or PostgreSQL.",1780799669228]