Guide to Install Laravel on Linux
This guide will help you install Laravel on your Linux machine. Laravel is a PHP framework that is used to build web applications. It is a powerful and flexible framework that makes it easy to build web applications quickly.
Prerequisites
Before you start, make sure you have the following installed on your Linux machine:
Step 1: If you don't have Apache then Install Apache
- Install Apache using the package manager for your Linux distribution. For example, on Ubuntu, you can install Apache using the following command:
sudo apt-get update
sudo apt-get install apache2
- Start the Apache service and enable it to start on boot:
sudo systemctl start apache2
sudo systemctl enable apache2
- Verify that Apache is running by visiting http://localhost/ in your web browser.
Step 2: Install MySQL
- Install MySQL using the package manager for your Linux distribution. For example, on Ubuntu, you can install MySQL using the following command:
sudo apt-get install mysql-server
- Start the MySQL service and enable it to start on boot:
sudo systemctl start mysql
sudo systemctl enable mysql
- (Optional) Secure your MySQL installation by running the following command:
sudo mysql_secure_installation
-
Create a new MySQL database for your Laravel project:
-
Open a terminal window.
-
Run the following command to log in to MySQL:
mysql -u root -p
- Enter your MySQL root password when prompted.
- Create a new database Laravel project:
CREATE DATABASE botivus;
- Create a new user:
CREATE USER 'botivus'@'localhost' IDENTIFIED BY 'password';
- Grant the user all privileges on the database:
GRANT ALL PRIVILEGES ON botivus.* TO 'botivus'@'localhost';
- Flush the privileges to ensure that the changes take effect:
FLUSH PRIVILEGES;
- Exit the MySQL shell by running the following command:
EXIT;
Step 3: Install PHP
- Install PHP and the required PHP extensions using the package manager for your Linux distribution. For example, on Ubuntu, you can install PHP using the following command:
sudo apt install php8.3 php8.3-curl php8.3-fileinfo php8.3-gd php8.3-bcmath php8.3-gettext php8.3-mbstring php8.3-bcmath php8.3-exif php8.3-mysqli php8.3-pdo php8.3-zip -y
- Restart the Apache service to apply the changes:
sudo systemctl restart apache2
- Verify that PHP is installed by creating a
phpinfo.php
file in the Apache web root directory:
echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/phpinfo.php
- Visit http://localhost/phpinfo.php in your web browser to view the PHP information.
Step 4: Install Composer
- Download and install Composer by running the following commands:
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php composer-setup.php
php -r "unlink('composer-setup.php');"
sudo mv composer.phar /usr/local/bin/composer
or
sudo apt-get install composer
- Verify that Composer is installed by running the following command:
composer --version
Step 5: Install Node.js
- Install Node.js using the package manager for your Linux distribution. For example, on Ubuntu, you can install Node.js using the following command:
sudo apt-get install nodejs
- Verify that Node.js is installed by running the following command:
node --version
- Install the Node.js package manager (npm) by running the following command:
sudo apt-get install npm
- Verify that npm is installed by running the following command:
npm --version
Step 6: Setup our Laravel Project
- Extract the project files to the directory then in this folder have 2 folder documentation and core folder. Now copy the core folder to the root folder.
Note: If you are a developer please follow the below steps to install our Laravel project. If you are not a developer please use don't use the below steps only follow GUI steps.
- Navigate to the project directory and install the project dependencies using Composer:
cd ~/Downloads/laravel-project
- Comment the below line on
/public/index.php
file:
if (! file_exists(__DIR__.'/../storage/installed')) {
header('Location: /installer/index.php');
exit;
}
// to
// if (! file_exists(__DIR__.'/../storage/installed')) {
// header('Location: /installer/index.php');
// exit;
// }
composer install
- Create a copy of the
.env.example
file and rename it to.env
:
cp .env.example .env
- Generate an application key by running the following command:
php artisan key:generate
- Run the following command to migrate the database:
php artisan migrate
- Generate the application storage link by running the following command:
php artisan storage:link
- Generate dummy data for testing:
php artisan db:seed
- Start the Laravel development server:
php artisan serve
- Also start the npm server by running the following command:
npm run dev
- Open a web browser and navigate to http://localhost:8000 to view the Laravel project.
Conclusion
Congratulations! You have successfully installed Laravel on your Linux machine. You can now start building web applications with Laravel. If you have any questions, feel free to reach out to our support team. 🚀