give me all the comands to install and run laravel on my linux mint, need to install…
- User
give me all the comands to install and run laravel on my linux mint, need to install mysql, php, composer
- Assistant
give me all the comands to install and run laravel on my linux mint, need to install mysql, php, composer
Sure! Below is a comprehensive guide with all the necessary commands to install and run Laravel on your Linux Mint system. This guide covers the installation of MySQL, PHP, Composer, and sets up Laravel with the Apache web server.
Before starting, ensure your system packages are up to date.
sudo apt update
sudo apt upgrade -y
Install the Apache web server to serve your Laravel application.
sudo apt install apache2 -y
Start and Enable Apache:
sudo systemctl start apache2
sudo systemctl enable apache2
Adjust Firewall to Allow Web Traffic:
If you have ufw enabled, allow Apache through the firewall.
sudo ufw allow 'Apache Full'
Verify Apache Installation:
Open your browser and navigate to http://localhost. You should see the Apache2 Ubuntu Default Page.
Install MySQL to handle your database requirements.
sudo apt install mysql-server -y
Secure MySQL Installation:
Run the security script to set the root password and remove insecure defaults.
sudo mysql_secure_installation
Follow the prompts to set up your MySQL secure installation.
Log into MySQL:
sudo mysql -u root -p
(Optional) Create a Database and User for Laravel:
CREATE DATABASE laravel_db;
CREATE USER 'laravel_user'@'localhost' IDENTIFIED BY 'your_password';
GRANT ALL PRIVILEGES ON laravel_db.* TO 'laravel_user'@'localhost';
FLUSH PRIVILEGES;
EXIT;
Replace laravel_db, laravel_user, and your_password with your preferred database name, username, and password.
Laravel requires PHP and several PHP extensions. Install them with the following commands:
sudo apt install php libapache2-mod-php php-mysql php-xml php-mbstring php-curl php-zip php-gd php-tokenizer php-json php-cli php-bcmath -y
Verify PHP Installation:
php -v
You should see the PHP version information.
Composer is a dependency manager for PHP, essential for managing Laravel and its packages.
Download and Install Composer:
cd ~
curl -sS https://getcomposer.org/installer -o composer-setup.php
HASH=`curl -sS https://composer.github.io/installer.sig`
php -r "if (hash_file('sha384', 'composer-setup.php') === '$HASH') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
Ensure the installer is verified. If verified, proceed:
sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer
Check Composer Installation:
composer --version
You should see the Composer version information.
Now, use Composer to create a new Laravel project.
Navigate to the Web Root Directory:
cd /var/www/html
Create a New Laravel Project:
sudo composer create-project --prefer-dist laravel/laravel laravel-app
This command creates a new Laravel project in /var/www/html/laravel-app.
Set up Apache to serve your Laravel application.
Create a New Virtual Host File:
sudo nano /etc/apache2/sites-available/laravel-app.conf
Add the Following Configuration:
<VirtualHost *:80>
ServerName your_domain_or_ip
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html/laravel-app/public
<Directory /var/www/html/laravel-app>
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/laravel-app_error.log
CustomLog ${APACHE_LOG_DIR}/laravel-app_access.log combined
</VirtualHost>
Replace your_domain_or_ip with your server’s domain name or IP address.
Enable the Site and Rewrite Module:
sudo a2ensite laravel-app.conf
sudo a2enmod rewrite
Disable the Default Site (Optional):
sudo a2dissite 000-default.conf
Restart Apache to Apply Changes:
sudo systemctl restart apache2
Ensure that Apache can read and write necessary files.
sudo chown -R www-data:www-data /var/www/html/laravel-app
sudo chmod -R 755 /var/www/html/laravel-app/storage
sudo chmod -R 755 /var/www/html/laravel-app/bootstrap/cache
Set up your Laravel application's environment configurations.
Navigate to Laravel Project Directory:
cd /var/www/html/laravel-app
Copy the Example Environment File:
cp .env.example .env
Generate an Application Key:
php artisan key:generate
Edit the .env File to Configure Database:
sudo nano .env
Update the following lines with your database details:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel_db
DB_USERNAME=laravel_user
DB_PASSWORD=your_password
Ensure the .env file has the correct permissions:
sudo chmod 644 .env
Open your browser and navigate to http://your_domain_or_ip. You should see the Laravel welcome page.
If you prefer using Laravel's built-in server for development purposes, follow these additional steps.
Navigate to Laravel Project Directory:
cd /var/www/html/laravel-app
Start the Development Server:
php artisan serve
Access Laravel Application:
Open your browser and go to http://127.0.0.1:8000 or the provided URL.
Note: The built-in server is suitable for development but not recommended for production use.
Missing PHP Extensions:
If you encounter errors about missing PHP extensions, install them using sudo apt install php-<extension> -y and restart Apache.
Permissions Issues:
Ensure the storage and bootstrap/cache directories are writable by Apache.
Environment Configuration:
Double-check your .env file for correct database credentials and app settings.
Apache not Serving Correct Directory:
Verify that the DocumentRoot in your virtual host configuration points to public directory of Laravel.
For your convenience, here's a consolidated list of all commands mentioned above:
# Update System
sudo apt update
sudo apt upgrade -y
# Install Apache
sudo apt install apache2 -y
sudo systemctl start apache2
sudo systemctl enable apache2
sudo ufw allow 'Apache Full'
# Install MySQL
sudo apt install mysql-server -y
sudo mysql_secure_installation
# (Optional) Create Database and User
sudo mysql -u root -p
# Inside MySQL shell:
# CREATE DATABASE laravel_db;
# CREATE USER 'laravel_user'@'localhost' IDENTIFIED BY 'your_password';
# GRANT ALL PRIVILEGES ON laravel_db.* TO 'laravel_user'@'localhost';
# FLUSH PRIVILEGES;
# EXIT;
# Install PHP and Extensions
sudo apt install php libapache2-mod-php php-mysql php-xml php-mbstring php-curl php-zip php-gd php-tokenizer php-json php-cli php-bcmath -y
php -v
# Install Composer
cd ~
curl -sS https://getcomposer.org/installer -o composer-setup.php
HASH=`curl -sS https://composer.github.io/installer.sig`
php -r "if (hash_file('sha384', 'composer-setup.php') === '$HASH') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer
composer --version
# Install Laravel
cd /var/www/html
sudo composer create-project --prefer-dist laravel/laravel laravel-app
# Configure Apache for Laravel
sudo nano /etc/apache2/sites-available/laravel-app.conf
# [Add VirtualHost configuration as shown above]
sudo a2ensite laravel-app.conf
sudo a2enmod rewrite
sudo a2dissite 000-default.conf
sudo systemctl restart apache2
# Set Permissions
sudo chown -R www-data:www-data /var/www/html/laravel-app
sudo chmod -R 755 /var/www/html/laravel-app/storage
sudo chmod -R 755 /var/www/html/laravel-app/bootstrap/cache
# Configure Environment
cd /var/www/html/laravel-app
cp .env.example .env
php artisan key:generate
sudo nano .env
# [Update DB settings in .env]
# (Optional) Start Laravel Development Server
php artisan serve
By following these steps, you should have a fully functional Laravel development environment set up on your Linux Mint system. If you encounter any issues or need further customization, the Laravel Documentation is an excellent resource.
Not yet included in a published release.