Back to Homepage

LAMP: Installing Laravel on LAMP (Linux, Apache, MySQL, PHP)

3 min read

Tags:

LAMP: Installing Laravel on LAMP (Linux, Apache, MySQL, PHP)

Introduction:
Known for its elegant syntax and robust features, Laravel is a popular PHP framework for web application development. This blog post will walk you through installing Laravel on your system if you have a LAMP stack (Linux, Apache, MySQL, PHP).

Prerequisites:

Make sure you have the following prerequisites before we begin:

  • An operating system based on Linux (e.g., Ubuntu, CentOS)

  • Installed and running Apache web server

  • MySQL or MariaDB installed and running

  • PHP version 7.4 or higher installed

Step 1: To install the required PHP extensions for LAMP, open a terminal window and run the following command:

sudo apt-get install php7.4-mbstring php7.4-xml php7.4-bcmath
sudo apt install php-cli unzip

Step 2: Laravel relies on Composer, a dependency manager for PHP. Follow these steps to install Composer:

  1. Download the Composer installer by running the following command in the terminal

cd ~
curl -sS https://getcomposer.org/installer -o /tmp/composer-setup.php
HASH=`curl -sS https://composer.github.io/installer.sig`

Verify the integrity of the downloaded installer by running the following command:

php -r "if (hash_file('SHA384', '/tmp/composer-setup.php') === '$HASH') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"

Install Composer globally by running the following command:

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

Verify the installation by typing composer --version in the terminal. You should see Composer's version information.

Step 3: Create a New Laravel Project Now that Composer is installed, let's create a new Laravel project:

  1. Open a terminal and navigate to your web server's document root directory. For example

cd /var/www/html

Run the following command to create a new Laravel project:

composer create-project --prefer-dist laravel/laravel myproject 

Replace myproject with the desired name for your project.

Step 4: Laravel requires specific environment configurations, so follow these steps to set up the environment:

  1. Change to the project's directory

cd myproject

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

Step 5: Configure Apache To configure Apache to serve your Laravel project, follow these steps:

  1. You will need a text editor to open the Apache configuration file. The location of the file may vary depending on your distribution, but the most common paths are:

    • Ubuntu: /etc/apache2/sites-available/000-default.conf

    • CentOS: /etc/httpd/conf/httpd.conf

  2. Add the following lines inside the <VirtualHost>

DocumentRoot /var/www/html/myproject/public
<Directory /var/www/html/myproject>
    AllowOverride All
</Directory>

More Detailed information available on: LAMP Ubuntu

Check out our other Laravel Posts

Follow @LaravelSage on X → Follow @LaravelSage on Facebook →
Aniket Singh

Aniket Singh

View All Articles

Full-stack developer with a knack for Merging creativity with technical expertise for standout solutions.

Related Articles

Laravel 10 on Nginx running Ubuntu 23.10

Laravel 10 on Nginx running Ubuntu 23.10

This guide provides a thorough walkthrough on installing Laravel 10 on a Nginx server running Ubuntu 23.10. With real-time examples, you will be well on your way to setting up and exploring the new functionalities Laravel 10 has to offer

Install OpenResty on Ubuntu 22.10

Install OpenResty on Ubuntu 22.10

OpenResty is a robust, high-performance web platform based on NGINX and LuaJIT, known for its ability to handle a significant number of concurrent connections without any issue

Subscribe for 20+ new Laravel tutorials every week

You can unsubscribe at any time. You'll also get -20% off my courses!

© 2024

 

Laravel Sage

   |    Privacy Policy