How to Install / use Laravel on a Directadmin server

ericosman

Verified User
Joined
Nov 25, 2019
Messages
600
Location
Weert
Hi all,

How to install Laravel on DirectAdmin server.

What is Laravel?
Laravel is an open-source PHP framework used to build websites and apps. It contains all the necessary components and features to help web developers create a website using the PHP scripting language. It is important to note that Laravel isn’t the only framework available to PHP developers. In fact, other popular PHP frameworks include Symfony, CodeIgniter and Yii (just to name a few). And if we venture outside the PHP zone, there’s even more frameworks available, such as Rails which is based on the Ruby language, .NET which uses C#, or Sails.js, a Javascript framework.

Requirements:
  • PHP 7 (or higher)
  • OpenSSL, Mbstring, PDO, Tokenizer, PHP and XML Extensions
  • Apache or Nginx
Steps on how to install
step 1. SSH into your server and update your system and install the nessesery packages

yum update
yum install git curl

step 2. Install Composer
curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer

Step 3. Prepare to install Laravel
To install Laravel project, you need to make sure that the public_html folder is empty. To empty this folder excecute the following command
rm -rf /home/USERNAME/domains/LARAVEL_DOMAIN/public_html/*
Where you have to replace "USERNAME" with the Directadmin username of your user, and "LARAVEL_DOMAIN" with the domain you would like to install Laravel on.

Step 4. cd into your domain
*NOTE DO NOT DO THIS AS ROOT, BUT AS THE USER ITSELF*

cd /home/USERNAME/domains/LARAVEL_DOMAIN/public_html/
Where you have to replace "USERNAME" with the Directadmin username of your user, and "LARAVEL_DOMAIN" with the domain you would like to install Laravel on.

Step 5. Install Laravel
This will be done using the composer command, important that you keep the . at the end.
composer create-project --prefer-dist laravel/laravel .

Because Laravel uses a folder called "public", this has to be set as the default folder to view.

Go to step 6b if you use a subdomain to install Laravel in
Step 6a. Change the document root to /public

1. Login as an Admin into your server.
2. Go to Server Manager --> Custom HTTPD Configurations
3. Look for the domain you want to change the docroot for.
4. Click on httpd.conf
5. Click up right on CUSTOMIZE
6. under "httpd.conf customization for LARAVEL_DOMAIN" add the following line:
|?DOCROOT=`HOME`/domains/`DOMAIN`/public_html/public|
7. click on the SAVE button on the bottom right.

Step 6b. Change the document root to /public for a subdomain
1. Login as the User into your server.
2. Go to Account Manager --> Subdomain Management
3. Where you see Docroot click on the pencil on the right of it and add
4. Click the SAVE button

Now you should be able to see the Laravel welcome page when you visit your domain.

Note that it can take a small amount of time to update your HTTPD.conf so you will not see the change the next second.
 
Thanks. But how can I install node.js in order to be able to run "npm run build" when package.json is in the public_html folder?
I have done the followong settings in "Setup Node.js app":
  1. Application root: domains/example.com
  2. Application URL: example.com
  3. Application startup file: index.php
After that I run "npm run build" from the path that is suggested and get error that package.json can not be found in example.com. How do I make the system look in example.com/public_html?
 
Back
Top