Home
/
Other Applications
/
How to install Laravel on my SiteGround account?

How to install Laravel on my SiteGround account?

Prior to installing Laravel, ensure that the server meets the requirements below:

  • PHP >= 7.4.28
  • OpenSSL PHP Extension
  • PDO PHP Extension
  • Mbstring PHP Extension
  • Tokenizer PHP Extension
  • XML PHP Extension
  • Ctype PHP Extension
  • JSON PHP Extension

If your account is currently using a lower PHP version, you may update it via the PHP Manager in your Site Tools. You may find a detailed article on how to do that here.

Our servers meet the above requirements and you can install Laravel on your SiteGround account. You should also make sure that Composer is installed on the server as Laravel utilizes Composer to manage its dependencies. Composer is pre-installed on all of our servers.

Connect to your account via SSH. Navigate to the folder where you want to create the Laravel directory and run the command below:

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

where blog is the name of the folder that would be created by Composer and that will contain the framework files. Running the above command in your ~/public_html/ directory will install a new Laravel framework located in the ~/public_html/blog folder of your account.

Laravel’s front controller is the index.php file located in the public/ folder of the application. This means that if you have installed the framework in the ~/public_html/blog directory, the front controller for all HTTP requests would be the ~/public_html/blog/public/index.php file. Thus the URL you should visit to preview the installation is http://yourmaindomain.com/blog/public, where yourmaindomain.com is the primary domain for your hosting account.

If you want to use a subdomain to access the index file directly, make sure that the subdomain’s document root is the public/ folder, in our case – ~/public_html/blog/public.

To connect your Laravel framework to a database, first, create a new MySQL database and user. Then add the MySQL details in the .env file. In our case, the exact location of the file would be ~/public_html/blog/.env. Open the file for editing and find the section below:

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=myDatabase
DB_USERNAME=myUser
DB_PASSWORD=secret

The next step is to substitute the myDatabase string with the actual name of the database you created, myUser with the MySQL user and substitute secret with the user’s password.

This is it – your Laravel framework is installed and ready to start building your website with it!

Share This Article