{"id":2725,"date":"2025-06-23T03:05:34","date_gmt":"2024-07-10T12:20:09","guid":{"rendered":""},"modified":"2025-02-02T00:46:19","modified_gmt":"2025-02-01T23:46:19","slug":"how-to-install-laravel-php-framework-with-nginx-on-ubuntu-22-04","status":"publish","type":"post","link":"https:\/\/netcloud24.com\/knowledgebase\/how-to-install-laravel-php-framework-with-nginx-on-ubuntu-22-04\/","title":{"rendered":"Linux VPS &#038; VPS Windows Setup Guide | NetCloud24 Laravel PHP Framework with Nginx on Ubuntu 22.04"},"content":{"rendered":"<p>\u00a0<\/p>\n<\/p>\n<header>\n<h1>\u00a0<\/h1>\n<\/header>\n<article>\n<p><strong>Laravel<\/strong> is a powerful PHP framework designed for web application development. Combined with Nginx, a high-performance web server, Laravel can be deployed to create robust, scalable web applications. In this guide, we will walk you through how to install Laravel with Nginx on <strong>Ubuntu 22.04<\/strong>. Hosting your Laravel application on a  will give you the performance, flexibility, and scalability that a <strong>VPS server<\/strong> provides, ensuring your application can handle growing traffic and user demand.<\/p>\n<h2>Step 1: Update Your VPS Server<\/h2>\n<p>Before installing Laravel, make sure your <a href=\"https:\/\/ie.netcloud24.com\">VPS server<\/a> is updated with the latest software packages. Run the following commands to update your system:<\/p>\n<pre><code>sudo apt update &amp;&amp; sudo apt upgrade -y<\/code><\/pre>\n<p>Using a <strong>Windows VPS<\/strong> ensures that your Laravel application runs on a high-performance environment, providing a faster and more reliable experience for your users.<\/p>\n<h2>Step 2: Install Nginx<\/h2>\n<p><strong>Nginx<\/strong> is a lightweight and efficient web server that will handle HTTP requests for your Laravel application. Install Nginx with the following command:<\/p>\n<pre><code>sudo apt install nginx -y<\/code><\/pre>\n<p>After installation, start and enable Nginx to run at boot:<\/p>\n<pre><code>sudo systemctl enable nginx --now<\/code><\/pre>\n<p>To verify that Nginx is running, open your browser and visit <code>http:\/\/your-server-ip<\/code>. You should see the default Nginx welcome page.<\/p>\n<h2>Step 3: Install PHP and Required Extensions<\/h2>\n<p>Laravel is built using PHP, so you&#8217;ll need to install PHP and the necessary extensions to ensure proper functionality. Run the following command to install PHP and the required extensions:<\/p>\n<pre><code>\r\nsudo apt install php-fpm php-mysql php-cli php-xml php-mbstring php-zip php-curl php-json php-bcmath -y\r\n<\/code><\/pre>\n<p>PHP-FPM (FastCGI Process Manager) will be used by Nginx to process PHP files efficiently.<\/p>\n<h2>Step 4: Install Composer<\/h2>\n<p><strong>Composer<\/strong> is a dependency manager for PHP and is required to install Laravel. Use the following commands to install Composer on your server:<\/p>\n<pre><code>\r\nsudo apt install curl -y\r\ncurl -sS https:\/\/getcomposer.org\/installer | php\r\nsudo mv composer.phar \/usr\/local\/bin\/composer\r\n<\/code><\/pre>\n<p>Verify the installation by checking the Composer version:<\/p>\n<pre><code>composer --version<\/code><\/pre>\n<h2>Step 5: Install Laravel<\/h2>\n<p>Now that Composer is installed, you can use it to install Laravel. Navigate to the web root directory and create a new Laravel project:<\/p>\n<pre><code>\r\ncd \/var\/www\/html\r\ncomposer create-project --prefer-dist laravel\/laravel laravel-app\r\n<\/code><\/pre>\n<h2>Step 6: Set Permissions for Laravel<\/h2>\n<p>Laravel requires specific ownership and permissions to function correctly. Set the correct permissions with the following commands:<\/p>\n<pre><code>\r\nsudo chown -R www-data:www-data \/var\/www\/html\/laravel-app\r\nsudo chmod -R 755 \/var\/www\/html\/laravel-app\r\n<\/code><\/pre>\n<h2>Step 7: Configure Nginx for Laravel<\/h2>\n<p>Next, you&#8217;ll need to configure Nginx to serve the Laravel application. Open a new Nginx configuration file:<\/p>\n<pre><code>sudo nano \/etc\/nginx\/sites-available\/laravel-app<\/code><\/pre>\n<p>Add the following configuration, replacing <code>your-domain.com<\/code> with your actual domain or IP address:<\/p>\n<pre><code>\r\nserver {\r\n    listen 80;\r\n    server_name your-domain.com;\r\n    root \/var\/www\/html\/laravel-app\/public;\r\n\r\n    index index.php index.html;\r\n\r\n    location \/ {\r\n        try_files $uri $uri\/ \/index.php?$query_string;\r\n    }\r\n\r\n    location ~ \\.php$ {\r\n        include snippets\/fastcgi-php.conf;\r\n        fastcgi_pass unix:\/var\/run\/php\/php-fpm.sock;\r\n        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;\r\n        include fastcgi_params;\r\n    }\r\n\r\n    location ~ \/\\.ht {\r\n        deny all;\r\n    }\r\n\r\n    error_log \/var\/log\/nginx\/laravel-error.log;\r\n    access_log \/var\/log\/nginx\/laravel-access.log;\r\n}\r\n<\/code><\/pre>\n<p>Save the file and exit the editor. Then, enable the site and restart Nginx:<\/p>\n<pre><code>\r\nsudo ln -s \/etc\/nginx\/sites-available\/laravel-app \/etc\/nginx\/sites-enabled\/\r\nsudo nginx -t\r\nsudo systemctl restart nginx\r\n<\/code><\/pre>\n<h2>Step 8: Configure Laravel Environment<\/h2>\n<p>Laravel uses a <code>.env<\/code> file to manage environment-specific settings, such as database connections. Open the <code>.env<\/code> file and configure the database settings:<\/p>\n<pre><code>sudo nano \/var\/www\/html\/laravel-app\/.env<\/code><\/pre>\n<p>Update the following lines with your MySQL\/MariaDB database information:<\/p>\n<pre><code>\r\nDB_DATABASE=laravel_db\r\nDB_USERNAME=laravel_user\r\nDB_PASSWORD=your_password\r\n<\/code><\/pre>\n<p>Save the file and exit the editor.<\/p>\n<h2>Step 9: Complete Laravel Installation<\/h2>\n<p>To finalize the Laravel installation, run the following command to generate an application key:<\/p>\n<pre><code>php artisan key:generate<\/code><\/pre>\n<p>Your Laravel installation is now complete. You can access your Laravel application by visiting <code>http:\/\/your-domain.com<\/code> in your web browser.<\/p>\n<h2>Step 10: Optimize Your VPS Server for Laravel<\/h2>\n<p>To get the best performance out of your Laravel application, hosting it on a  is the optimal choice. A <strong>VPS server<\/strong> provides dedicated CPU, memory, and storage resources that ensure your application runs smoothly, even as traffic grows. A VPS also allows for better resource management and the ability to scale your infrastructure as needed, keeping your web application fast and reliable.<\/p>\n<h2>Conclusion<\/h2>\n<p>Installing Laravel with Nginx on Ubuntu 22.04 is a powerful combination for developing modern web applications. By hosting your Laravel application on a , you can take advantage of improved performance, scalability, and control, ensuring your application performs optimally as it grows.<\/p>\n<p>For more information about VPS hosting and optimizing your Laravel setup, visit  today.<\/p>\n<\/article>\n<footer>\n<p>\u00a9 2024 Windows VPS &#8211; All Rights Reserved<\/p>\n<\/footer>\n<div class=\"post-author-box\" style=\"border-top:1px solid #ddd;margin-top:20px;padding-top:15px;\">\n<p><strong>Author:<\/strong> \u0141ukasz Bodziony<\/p>\n<p><strong>Website:<\/strong> <a href=\"https:\/\/ca.netcloud24.com\" target=\"_blank\" rel=\"dofollow\">Windows VPS<\/a><\/p>\n<p><em>\u0141ukasz Bodziony is the CEO and founder of <a href=\"https:\/\/netcloud24.com\" target=\"_blank\" rel=\"dofollow\">NETCLOUD24<\/a>, a global VPS hosting brand proudly originating from Poland. With extensive experience in cloud computing, virtualization, and server management, he delivers high-performance <strong>Windows VPS<\/strong> and <strong>Remote Desktop Services (RDS)<\/strong> solutions to clients across Europe, North America, and beyond.<\/em><\/p>\n<p><em>His expertise covers a wide range of technologies, including <strong>Microsoft Azure<\/strong>, <strong>Proxmox VE<\/strong>, <strong>Amazon Web Services (AWS)<\/strong>, and numerous other virtualization and cloud platforms.<\/em><\/p>\n<p><em>Beyond running his hosting business, \u0141ukasz also provides <strong>professional paid server configuration and optimization services<\/strong> for companies and individuals. Outside of work, he is dedicated to caring for his children and building a secure future for them.<\/em><\/p>\n<p><em>If you are interested in working with him or need expert assistance with your hosting, cloud environment, or server setup, feel free to reach out via <a href=\"https:\/\/ca.netcloud24.com\" target=\"_blank\" rel=\"dofollow\">Windows VPS<\/a>.<\/em><\/p>\n<\/p><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u00a0 \u00a0 Laravel is a powerful PHP framework designed for web application development. Combined with Nginx, a high-performance web server, Laravel can be deployed to create robust, scalable\u2026<\/p>\n","protected":false},"author":1,"featured_media":3421,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_seopress_robots_primary_cat":"","_seopress_titles_title":"","_seopress_titles_desc":"","_seopress_robots_index":"","footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[],"tags":[14,12,11,23,20,21,22,17,7,8,6,10,18,19,15,24,16,5,13,9],"class_list":["post-2725","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","tag-cheapvps","tag-cloudvps","tag-hostingvps","tag-rds","tag-rdscal","tag-remotedesktop","tag-remotedesktopvps","tag-servervps","tag-ukvps","tag-virtualserver","tag-vpshosting","tag-vpsserver","tag-vpssolutions","tag-vpswindows","tag-vpswithwindows","tag-windowsrds","tag-windowsserver","tag-windowsvps","tag-windowsvpshosting","tag-windowsvpsuk"],"jetpack_publicize_connections":[],"_links":{"self":[{"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/posts\/2725","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/comments?post=2725"}],"version-history":[{"count":0,"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/posts\/2725\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/media\/3421"}],"wp:attachment":[{"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/media?parent=2725"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/categories?post=2725"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/tags?post=2725"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}