In this article, we will have explained the necessary steps to install and set up Laravel on Debian 10. Before continuing with this tutorial, make sure you are logged in as a user with sudo
privileges. All the commands in this tutorial should be run as a non-root user.
Laravel is a very popular open-source PHP framework with the expressive and elegant syntax used to design modern and beautiful web applications. Laravel aims to take the pain out of web development and make it an enjoyable and creative experience, turning web devs into web artisans.
Install Laravel on Debian 10
Step 1. The first command will update the package lists to ensure you get the latest version and dependencies.
sudo apt update sudo apt upgrade sudo apt install software-properties-common apt-transport-https wget
Step 2. Install LAMP Stack.
You need to set up the LAMP stack on your Ubuntu system. If you haven’t done so already, use our traditional LAMP guide to set up Ubuntu to serve PHP before you continue.
Step 3. Install Composer.
The composer is an application-level package manager for PHP that provides a standard format for managing dependencies of PHP software and required libraries. Run the following command to install Composer on the Ubuntu system:
curl -sS https://getcomposer.org/installer | php sudo mv composer.phar /usr/local/bin/composer sudo chmod +x /usr/local/bin/composer
Step 4. Install Laravel on the Debian system.
Now we clone the latest Laravel source code from its official git repository to your local system. Just execute the following command:
cd /var/www git clone https://github.com/laravel/laravel.git
Then, change the Laravel directory and use the composer to install all dependencies required for the Laravel framework:
cd /var/www/laravel sudo composer install
After that, set the directory permissions accordingly:
chown -R www-data.www-data /var/www/laravel chmod -R 755 /var/www/laravel chmod -R 777 /var/www/laravel/storage
Step 5. Set Encryption Key.
First, we rename the .evn.example
file to .env
in the project’s main directory. This will use to set up the application environment for the project:
mv .env.example .env
Then, generate base64 random number encryption key:
$ php artisan key:generate Application key set successfully.
After generates random encryption, now we edit the .env configuration file and update the required settings. Also, make sure APP_KEY is properly set as generated in the above command:
$ nano .env
APP_NAME=Laravel APP_ENV=local APP_KEY=base64:godetzp+AeHu7kc2chedelicsq2BQ/1gfFWEpoAk= APP_DEBUG=true APP_URL=http://localhost ...
Step 6. Create a MariaDB database for Laravel.
Laravel uses the MariaDB database to store all its data like posts, pages, users, plugins, and themes settings. Log in to your MariaDB server with the following command and enter your MariaDB root password:
mysql -u root -p
Once you’re in the MariaDB console, create a new database:
CREATE DATABASE laravel; CREATE USER 'laravel'@'localhost' IDENTIFIED BY 'your-passwd'; GRANT ALL ON laravel.* to 'laravel'@'localhost'; FLUSH PRIVILEGES; quit
Then, edit the .env
file and update database settings:
DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=laravel DB_USERNAME=laravel DB_PASSWORD=your-passwd
Step 7. Configuring Apache for Laravel.
Create a new virtual host configuration file for your Laravel website, named your-domain.com.conf:
nano /etc/apache2/sites-available/your_domain.com.conf
Update configuration as:
<VirtualHost *:80> ServerAdmin [email protected] DocumentRoot "/var/www/laravel/public" ServerName your-domain.com ServerAlias www.your-domain.com ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined <Directory /var/www/laravel/> Options FollowSymlinks AllowOverride All Require all granted </Directory> </VirtualHost>
To enable the virtual host we have just created, run the following command:
ln -s /etc/apache2/sites-available/your-domain.com.conf /etc/apache2/sites-enabled/your-domain.com.conf
For the new configuration to take effect, restart the Apache service by typing:
sudo a2ensite your_domain.com.conf sudo a2enmod rewrite sudo systemctl restart apache2
Step 8. Accessing Laravel.
Now you can access the Laravel web install wizard using an HTTP connection:
https://your-domain.com
That’s all you need to do to install the Laravel on Debian 10 Buster. I hope you find this quick tip helpful. For further reading on Laravel, please refer to their official knowledge base. If you have questions or suggestions, feel free to leave a comment below.