How to Install Laravel and Create a New Project on Linux

How to Install Laravel and Create a New Project on Linux

 How to Install Laravel and Create a New Project on Linux

Laravel is a popular PHP framework for web development. This guide will walk you through installing Laravel and creating a new project on a Linux system.

Step 1: Update System Packages

Before installing Laravel, ensure your system is up-to-date. Open the terminal and run:

sudo apt update && sudo apt upgrade -y

Step 2: Install PHP and Required Extensions

Laravel requires PHP and some extensions. Install them using:

sudo apt install php-cli php-mbstring php-xml php-bcmath php-curl unzip -y

Check if PHP is installed correctly:

php -v

Step 3: Install Composer (PHP Dependency Manager)

Laravel requires Composer to manage dependencies. Install it using:

curl -sS https://getcomposer.org/installer | php sudo mv composer.phar /usr/local/bin/composer

Verify installation:

composer -V

Step 4: Install Laravel Installer

Now, install the Laravel Installer globally:

composer global require laravel/installer

Add Composer’s bin directory to your system PATH so you can use the laravel command:

echo 'export PATH="$HOME/.composer/vendor/bin:$HOME/.config/composer/vendor/bin:$PATH"' >> ~/.bashrc source ~/.bashrc

Check if Laravel is installed correctly:

laravel --version

Step 5: Create a New Laravel Project

Once Laravel is installed, create a new project.

Option 1: Using Laravel Installer

laravel new my-app

Option 2: Using Composer

If laravel new doesn’t work, use Composer instead:

composer create-project --prefer-dist laravel/laravel my-app

Step 6: Navigate to Your Project and Start the Server

Move into your project directory:

cd my-app

Start the Laravel development server:

php artisan serve

Now, open your browser and visit:

http://127.0.0.1:8000

Step 7: (Optional) Install Laravel UI for React

If you want to use React with Laravel, install Laravel UI:

composer require laravel/ui

Then scaffold React:

php artisan ui react npm install && npm run dev

Conclusion

Congratulations! 🎉 You have successfully installed Laravel on Linux and created a new project. Now, you can start building your web application.

Souy Soeng

Souy Soeng

Our website teaches and reads PHP, Framework Laravel, and how to download Admin template sample source code free. Thank you for being so supportive!

Github

Post a Comment

CAN FEEDBACK
close