Guides and tutorials

Hundreds of tutorials and step by step guides carefully written by our support team.

Installing Laravel in Cloud with Debian 10

Contract Cloud One with Debian Buster 10

First of all, you must have a Cloud server, for example a Cloud One A1. The Cloud can be contracted from our web or, if you are already a SW Hosting client, from your account SW Panel

SSH connection

At the time of registering the server, both from the web and from the SW Panel, an email will be sent to your email account with the SSH access credentials (IP and port) to your Cloud server for the administrator user (Root). With these credentials you can access your server and start the Laravel installation process.

Create a user

In SW Hosting, we recommend creating a user with elevated permissions and not using the root user for these purposes. To create a user, you can do it using the following commands.

apt install sudo
adduser swtest
usermod -aG sudo swtest
su - swtest

enter image description here

Now we have a system user with sudo privileges and we should no longer use root directly

Minimum packages required

We start by adding the PHP 7.4 repositories:

sudo wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg

echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/php.list

enter image description here

Once the repository has been added, we will proceed to update the list of packages and the Cloud.

sudo apt update
sudo apt upgrade

enter image description here

Once updated, we install the following essential packages:

sudo apt install lsb-release apt-transport-https ca-certificates git zip unzip

enter image description here

LAMP: Install Apache, MariaDB and PHP 7.4

To start, we installed the Apache service:

sudo apt install apache2

enter image description here

To verify the correct operation of the service, you can do it with the following command:

sudo service apache2 status

enter image description here

You can also check with the browser, using the IP of your Cloud.

enter image description here

Once the correct operation has been verified, we install the PHP 7.4 service and the mbstring and xml modules:

sudo apt install php7.4 php7.4-fpm php7.4-mbstring php7.4-xml libapache2-mod-php7.4

enter image description here

We can verify the correct operation of PHP by creating a small PHP script in /var/www/html, for this we will do the following:

cd /var/www/html
sudo nano info.php

The content of the file must be as follows:

<?php  

// Show all information, by default INFO_ALL
phpinfo();  

// Show only module information.
// phpinfo(8) does exactly the same.
phpinfo(INFO_MODULES);  

?>

Official file: https://www.php.net/manual/es/function.phpinfo.php

Once the file is saved, we run it from the browser with the following URL: http://ipdelservidor/info.php

enter image description here

You can also check that it works correctly with the following command:

service php7.4-fpm status

enter image description here

Once PHP 7.4 and its modules are installed, we will proceed to install the MariaDB database as a service (Server) and its PHP module:

sudo apt install mariadb-server php7.4-mysql

enter image description here

To perform the service check you can do it with the following commands:

service mariadb status

enter image description here

mariadb -p

enter image description here

Create Virtualhost in Apache

We will use manuals.sw as an example. To start, let's create the configuration file. To do this, we must first access the path, and, once you are in the directory, create the configuration file manuals.conf.

cd /etc/apache2/sites-available
sudo nano manuales.conf

In the configuration file, we define the following configuration:

<VirtualHost *:80>
    ServerName manuales.sw
    DocumentRoot "/var/www/manuales/public"
</VirtualHost>

Once the configuration file has been created, we activate the site with the following commands:

sudo a2ensite manuales
sudo systemctl reload apache2

Creating VirtualHost configurations on your Apache server does not magically create DNS entries for those host names. You must have the DNS names, resolving to your IP address, or no one else will be able to see your website.

If your domain, in its DNS zone, is not pointing to the Cloud, to carry out the tests, you can edit the hosts file.

Remember that this configuration is only available on the computer where the hosts file has been modified, the others are not, unless the file is configured.

Modify our hosts file

You can follow the following manual to edit the hosts file:

Manual de hosts

In the hosts file, we will add a line:

IP-del-Cloud manuales.sw

Composer

Composer is a package management system for programming in PHP, which provides the standard formats necessary to manage dependencies and libraries of this.

To get started, we will install Composer:

sudo php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"

sudo php -r "if (hash_file('sha384', 'composer-setup.php') === 'e5325b19b381bfd88ce90a5ddb7823406b2a38cff6bb704b0acc289a09c8128d4a8ce2bbafcd1fcbdc38666422fe2806') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"

sudo php composer-setup.php

sudo php -r "unlink('composer-setup.php');"

sudo mv composer.phar /usr/bin/composer

enter image description here You can check more information in the Official Website of Composer.

To verify the correct operation of the Composer, we will execute the following command:

composer

enter image description here

Laravel

Once the requirements to run Laravel are installed, we proceed to the deployment of the Framework. To do this, we run the following commands:

First, we access the following directory:

cd /var/www

Once inside, we execute the deployment using the Composer. With Composer you can display different Frameworks that you can find on the official website, in the "Browse Packages" section. We are going to use the laravel/laravel package and we are going to define it with the name of manuals. When executing the command, it will download different dependencies and will create the manuals folder in the current directory (in our case /var/www), where we will find the entire project.

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

enter image description here

Folder privileges

Once the project is created, we will enter the manuals folder and then grant the necessary permissions for its execution:

cd manuales
sudo chown www-data:www-data storage/ -R
sudo chown www-data:www-data bootstrap/cache/ -R

enter image description here

For more information on the installation of Laravel, you can consult the Official Website of Laravel

We can verify the correct operation of Laravel with the browser http://manuales.sw

enter image description here

You can continue configuring the Laravel parameters: Connection to the database, cache, sessions, etc.

More than 2000 m² of own facilities and Data Centers in Spain
Your privacy is important for us
We use our own cookies for the proper functioning of the site. In addition, third-party cookies are used for analytical purposes only. This information is not associated with any person so that personal identifying data is not stored, but is only information that is collected to identify the session, with the aim of facilitating the analysis of the website. You can change your preferences at any time by entering this website again. For more information about our cookie policy you can visit our Cookies. You can press the "Accept and close" button to give us your consent or you can access more detailed information and manage cookies.
More than 2000 m² of own facilities and Data Centers in Spain
Your privacy is important for us
We use our own cookies for the proper functioning of the site. In addition, third-party cookies are used for analytical purposes only. This information is not associated with any person so that personal identifying data is not stored, but is only information that is collected to identify the session, with the aim of facilitating the analysis of the website. You can change your preferences at any time by entering this website again. For more information about our cookie policy you can visit our Cookies. You can press the "Accept and close" button to give us your consent or you can access more detailed information and manage cookies.