1080*80 ad

How to Install Laravel on Ubuntu 20.04

Installing the powerful Laravel framework on an Ubuntu 20.04 server is a straightforward process, enabling you to leverage its elegant syntax and robust features for web development. Before you begin, ensure your server is updated and you have root privileges or a user with sudo access.

The foundation for a successful Laravel installation involves setting up the necessary server components. This typically includes PHP, Composer (Laravel’s dependency manager), a database system, and a web server.

First, update your server’s package list by running:
sudo apt update
sudo apt upgrade -y

Laravel requires PHP and several extensions. Install them using:
sudo apt install php-cli php-mysql php-curl php-mbstring php-xml php-zip php-bcmath php-json -y

Next, install Composer globally on your system. This allows you to manage Laravel and its dependencies easily. Download and run the Composer installer script:
curl -sS https://getcomposer.org/installer | php
Then move the Composer executable to a directory in your system’s PATH:
sudo mv composer.phar /usr/local/bin/composer
Make it executable:
sudo chmod +x /usr/local/bin/composer

A database is essential for most web applications. You can install MySQL or PostgreSQL. For MySQL, use:
sudo apt install mysql-server -y
Secure your MySQL installation afterwards by running the security script:
sudo mysqlsecureinstallation

Choose your web server: Nginx or Apache.
For Nginx:
sudo apt install nginx -y
For Apache:
sudo apt install apache2 -y

With the prerequisites in place, you can now create your new Laravel project using Composer. Navigate to your web server’s root directory (e.g., /var/www/html/ for Apache or /var/www/ for Nginx) or your desired project location, and run:
composer create-project –prefer-dist laravel/laravel yourprojectname
Replace your_project_name with the name you want for your application directory.

Navigate into your newly created project directory:
cd yourprojectname

Copy the example environment file and configure your application settings, especially database credentials:
cp .env.example .env
Edit the .env file using a text editor like nano:
nano .env
Update lines like DB_DATABASE, DB_USERNAME, and DB_PASSWORD to match your database setup.

Set the appropriate permissions for the storage and bootstrap/cache directories so the web server can write to them:
sudo chown -R www-data:www-data storage bootstrap/cache
sudo chmod -R 775 storage bootstrap/cache
sudo chmod -R o+rwx storage (or adjust permissions based on your security needs, chown is usually sufficient)

Configure your web server (Apache or Nginx) to serve the application. You’ll need to create a virtual host (Apache) or server block (Nginx) that points the webroot to the public directory within your Laravel project. Ensure URL rewriting is enabled and configured correctly for your chosen web server.

After configuring the web server and saving the configuration file, restart the web server:
For Nginx: sudo systemctl restart nginx
For Apache: sudo systemctl restart apache2

Finally, access your server’s IP address or domain name in a web browser. You should see the default Laravel welcome page, confirming a successful installation. You can now begin building your application.

Source: https://kifarunix.com/install-laravel-php-framework-on-ubuntu/

900*80 ad

      1080*80 ad