Arch Linux BasedManjaro

How To Install Laravel on Manjaro

Install Laravel on Manjaro

In this tutorial, we will show you how to install Laravel on Manjaro. Laravel is known for its elegant syntax and developer-friendly features, making it an excellent choice for building web applications. Manjaro Linux, on the other hand, offers a user-friendly and powerful environment for developers.

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo‘ to the commands to get root privileges. I will show you the step-by-step installation of the Laravel PHP framework on a Manjaro Linux.

Prerequisites

  • A server or desktop running one of the following operating systems: Manjaro, and other Arch-based distributions.
  • It’s recommended that you use a fresh OS install to prevent any potential issues.
  • SSH access to the server (or just open Terminal if you’re on a desktop).
  • An active internet connection. You’ll need an internet connection to download the necessary packages and dependencies for Laravel.
  • A non-root sudo user or access to the root user. We recommend acting as a non-root sudo user, however, as you can harm your system if you’re not careful when acting as the root.

Install Laravel on Manjaro

Step 1. Before running the tutorial below, make sure that our system is up to date:

sudo pacman -Syu
sudo pacman -S base-devel

Step 2. Installing PHP.

Manjaro provides PHP packages in its official repositories. You can install PHP and some common extensions using the pacman package manager. Install PHP and required extensions for Laravel:

sudo pacman -S php php-fpm php-gd php-intl php-mbstring php-zip php-pdo php-mysql

This command will install PHP and its extensions, making them available for your Laravel project.

Enabling and configuring PHP extensions is essential for Laravel to work correctly. Open your php.ini file for editing:

sudo nano /etc/php/php.ini

Uncomment (remove the ; symbol) or add the following lines to enable extensions:

extension=gd
extension=intl
extension=mbstring
extension=zip
extension=pdo_mysql

Save and exit the text editor.

Verify that PHP is installed by running the following command:

php -v

Step 3. Installing Composer.

Composer is a crucial tool for Laravel development, allowing you to manage project dependencies efficiently. Install Composer globally with the following command:

curl -sS https://getcomposer.org/installer -o composer-setup.php

Install Composer by running the following command:

sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer

Verify that Composer is installed by running the following command:

composer --version

Step 4. Setting up a Database.

Laravel supports multiple database systems, including MySQL, PostgreSQL, SQLite, and SQL Server. For this guide, we’ll focus on setting up MariaDB, a popular choice for Laravel projects due to its performance and compatibility with MySQL.

Use the following command to install MariaDB:

sudo pacman -S mariadb

Start the MariaDB service and enable it to start at boot:

sudo systemctl start mariadb
sudo systemctl enable mariadb

Run the MySQL secure installation script to enhance security:

sudo mysql_secure_installation

Follow the on-screen prompts to set the root password and secure your MariaDB installation.

To create a dedicated database and user for your Laravel project, follow these steps:

sudo mysql -u root -p

Creating a new database and user:

CREATE DATABASE yourdatabase;
CREATE USER 'youruser'@'localhost' IDENTIFIED BY 'yourpassword';
Grant Privileges: Grant the user full privileges over the database:
GRANT ALL PRIVILEGES ON yourdatabase.* TO 'youruser'@'localhost';
FLUSH PRIVILEGES;
EXIT;

Step 5. Installing Laravel on Manjaro.

Navigate to the directory where you want to create your Laravel project and run the following command:

composer create-project --prefer-dist laravel/laravel your-project-name

Replace your-project-name with your desired project name.

Laravel uses an environment file for configuration. Duplicate the .env.example file and name it .env:

cp .env.example .env

Generate a unique application key using the following command:

php artisan key:generate

Next, open the .env file in your project directory and configure your database connection settings. You can use a text editor like Nano or Vim to edit the file:

nano .env

Update the following variables with your database details:

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=yourdatabase
DB_USERNAME=youruser
DB_PASSWORD=yourpassword

Replace yourdatabase, youruser, and yourpassword with the database information you previously set up.

Step 6. Configuring the Web Server for Laravel.

Laravel can run on various web servers, including Apache and Nginx. Choose the one that best suits your needs. Here, we’ll provide instructions for both.

If you haven’t already, install Apache on your Manjaro system:

sudo pacman -S apache

Enable the Apache service and start it:

sudo systemctl enable httpd
sudo systemctl start httpd

Create an Apache virtual host configuration file for your Laravel project. Replace your-domain with your project’s domain or IP address:

sudo nano /etc/httpd/conf/extra/your-domain.conf

Add the following content, adjusting the paths and domain as needed:

<VirtualHost *:80>
ServerAdmin webmaster@your-domain.com
DocumentRoot "/path/to/your-project-name/public"
ServerName your-domain.com
ServerAlias www.your-domain.com

<Directory "/path/to/your-project-name/public">
AllowOverride All
Require all granted
</Directory>
</VirtualHost>

Enable the virtual host configuration:

sudo a2ensite your-domain.conf

Reload Apache to apply the changes:

sudo systemctl restart httpd

Step 7. Running Your Laravel Application.

Once your Laravel project is set up, you can launch it by serving it through the built-in development server. Navigate to your project directory and run:

php artisan serve

This command will start a local development server, allowing you to access your Laravel application at http://localhost:8000 in your web browser.

Install Laravel on Manjaro

Step 8. Configuring File Permissions.

File permissions are crucial for your Laravel application to function correctly. Ensure that the web server user (usually http or nginx) has the necessary permissions to read and write to specific directories.

Grant write permissions to the storage directory:

sudo chmod -R 775 storage

Set permissions for the bootstrap/cache directory:

sudo chmod -R 775 bootstrap/cache

Congratulations! You have successfully installed Laravel. Thanks for using this tutorial to install the latest version of the Laravel PHP framework on the Manjaro system. For additional help or useful information, we recommend you check the official Laravel website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is a seasoned Linux system administrator with a wealth of experience in the field. Known for his contributions to idroot.us, r00t has authored numerous tutorials and guides, helping users navigate the complexities of Linux systems. His expertise spans across various Linux distributions, including Ubuntu, CentOS, and Debian. r00t's work is characterized by his ability to simplify complex concepts, making Linux more accessible to users of all skill levels. His dedication to the Linux community and his commitment to sharing knowledge makes him a respected figure in the field.
Back to top button