This comprehensive guide walks you through the step-by-step process of installing and deploying a Laravel application on Ubuntu 24.04. From setting up the environment to configuring your web server, you'll learn everything you need to successfully launch your Laravel project
10 min
Edited:30-09-2024
Laravel is an open-source PHP framework designed for web application development. It follows the MVC (Model-View-Controller) architectural pattern, which helps separate the application logic from the user interface. Laravel provides a robust set of tools and features, including routing, authentication, templating, and an expressive ORM (Eloquent), which simplify common tasks in web development. Known for its elegant syntax and developer-friendly environment, Laravel enables developers to build scalable, maintainable, and high-performance applications quickly and efficiently. Additionally, it has a vibrant ecosystem that includes libraries, packages, and resources to enhance productivity and facilitate modern development practices.
Before you begin, ensure you have the following:
A server running Ubuntu 24.04
LEMP stack installed on your machine
Composer installed
You can install LEMP application following this guide:
You can install Composer following this guide:
Run this command to install all the needed extensions for Laravel:
1. sudo apt install php php-cli php-fpm php-mysql php-xml php-mbstring php-zip php-curl php-json -y
You can now install Laravel globally using Composer:
1. composer global require laravel/installer
Make sure to add the Composer vendor directory to your PATH in your ~/.bashrc or ~/.bash_profile:
1. echo 'export PATH="$PATH:$HOME/.config/composer/vendor/bin"' >> ~/.bashrc
2. source ~/.bashrc
Create a new Laravel application:
1. laravel new my-laravel-app
Navigate to the project directory:
1. cd my-laravel-app
Copy the example environment file and set up your application key:
1. cp .env.example .env
2. php artisan key:generate
The .env file contains sensitive configuration information, such as API keys and database credentials. It is crucial to protect this file by excluding it from version control and limiting access to authorized personnel only. Always treat it as confidential to ensure the security of your application and its data.
Assuming you already installed MySQL Server following the guides at the top, access MySQL to create a Database for Laravel:
1. sudo mysql -u root -p
Then run the following commands in the MySQL shell:
1. CREATE DATABASE laravel_db;
2. CREATE USER 'laravel_user'@'localhost' IDENTIFIED BY 'your_password';
3. GRANT ALL PRIVILEGES ON laravel_db.* TO 'laravel_user'@'localhost';
4. FLUSH PRIVILEGES;
5. EXIT;
Configure Laravel Database Settings: Edit your .env file with the database credentials:
1. DB_CONNECTION=mysql
2. DB_HOST=127.0.0.1
3. DB_PORT=3306
4. DB_DATABASE=laravel_db
5. DB_USERNAME=laravel_user
6. DB_PASSWORD=your_password
Run the migrations to create the necessary tables:
1. php artisan migrate
Create a new Nginx configuration file for your Laravel application:
1. sudo nano /etc/nginx/sites-available/my-laravel-app
Add the following configuration:
1. server {
2. listen 80;
3. server_name your_domain_or_IP;
4.
5. root /path/to/my-laravel-app/public;
6. index index.php index.html index.htm;
7.
8. location / {
9. try_files $uri $uri/ /index.php?$query_string;
10. }
11.
12. location ~ \.php$ {
13. include snippets/fastcgi-php.conf;
14. fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
15. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
16. include fastcgi_params;
17. }
18.
19. location ~ /\.ht {
20. deny all;
21. }
22. }
Enable the new site and test the Nginx configuration:
1. sudo ln -s /etc/nginx/sites-available/my-laravel-app /etc/nginx/sites-enabled/
2. sudo nginx -t
Restart Nginx to apply the changes:
1. sudo systemctl restart nginx
Set the correct permissions for the Laravel storage and cache directories:
1. sudo chown -R www-data:www-data /path/to/my-laravel-app/storage
2. sudo chown -R www-data:www-data /path/to/my-laravel-app/bootstrap/cache
Open your web browser and navigate to your server’s domain or IP address. You should see the Laravel welcome page.
1. http://localhost:8000
You can start the built-in server by navigating to your Laravel project directory and running:
1. php artisan serve
You have successfully installed and deployed a Laravel application on Ubuntu 24.04. You can now start building your application. For further development, refer to the official Laravel documentation for more advanced configurations and features. and you should see something like this:
14-10-2024
This article offers a detailed guide on installing and configuring IPTables on an Ubuntu VPS. IPTables is a powerful firewall tool that helps secure your server by controlling inbound and outbound traffic. Learn how to set up rules for traffic filtering, configure basic security policies, and apply custom rules to protect your VPS.
IPtables
security
12 min
This article offers a comprehensive guide on installing and configuring ModSecurity, a powerful web application firewall (WAF), on an Ubuntu VPS. Learn how to secure your server by filtering and monitoring HTTP requests, set up ModSecurity with Nginx or Apache, and apply rules to protect against common web attacks.
Modsecurity
security
10 min
14-10-2024
This article provides a comprehensive guide on installing and configuring PHP-FPM (FastCGI Process Manager) on an Ubuntu VPS. Learn how to optimize PHP performance for your web applications by configuring PHP-FPM with Nginx or Apache, managing pools, and fine-tuning settings for efficient processing of PHP scripts.
PHP-FPM
speed
optimise
12 min