How to install Laravel on my SiteGround account?
Prior to installing Laravel, you need to ensure that the server meets the requirements below:
- PHP >= 7.1.3
- 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 easily update it via the PHP Version manager in your cPanel. You may find a detailed article 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. We, at SiteGround, have Composer pre-installed on all of our servers.
Now you need to 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/primary, where yourmaindomain.com is the primary domain for your hosting account.
If you want to use an addon domain or subdomain to access the index file directly, you should make sure that the addon/subdomain's document root is the public/ folder, in our case - ~/public_html/blog/public.
If you want to connect your Laravel framework to a database, you should first create 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:
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!
You find this article useful? Click here to learn more about SiteGround web hosting experts and what else we can do for you!