PHP LARAVEL How to install

Learn how to set up PHP Laravel with a step-by-step guide, including an example.

Installing Laravel is a straightforward process. You just need to download the source code and install the dependencies. To make it easier, we will show an example of how to install Laravel on Ubuntu.

1. Install Composer

Composer is a dependency manager for PHP that helps you manage the libraries your application depends on. You can install it with the following command:

sudo apt-get install composer

2. Install Laravel

Once you have composer installed, you can install Laravel with the following command:

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

This will create a new Laravel project in the directory my-laravel-project. You can change the directory name to whatever you want.

3. Configure Apache

Once you have your project installed, the next step is to configure Apache to serve the project. To do this, you need to create a virtual host for the project in the Apache configuration file. You can do this with the following command:

sudo nano /etc/apache2/sites-available/my-laravel-project.conf

This will open a new file in the nano text editor. You can then copy the following configuration into the file and save it:

<VirtualHost *:80>
  ServerName my-laravel-project.local
  DocumentRoot /var/www/my-laravel-project/public
  <Directory "/var/www/my-laravel-project/public">
    AllowOverride All
  </Directory>
</VirtualHost>

This will configure Apache to serve the project at the URL my-laravel-project.local. You can change this to whatever you like.

4. Enable the Virtual Host

To enable the virtual host, you need to run the following commands:

sudo a2dissite 000-default
sudo a2ensite my-laravel-project.conf
sudo service apache2 restart

This will enable the virtual host for the project and restart Apache. You should now be able to access the project at the URL my-laravel-project.local.

5. Configure Database Connection

The final step is to configure the database connection. You can do this by editing the .env file in the project root directory. You can then set the database connection details in the following variables:

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=my-laravel-project
DB_USERNAME=root
DB_PASSWORD=secret

Once you have set the connection details, you should be able to access the database with the Laravel application.

And that's it! You should now have Laravel installed and configured on your system. You can now start developing your application.

Answers (0)