Warning
This article is old, and some of the information may be outdated or no longer valid today.
If you have any questions or need to confirm any details, we recommend contacting our support team for up-to-date information and personalized assistance.
A default VestaCP installation cannot host web projects developed with the Laravel framework. However, by making some changes to the VestaCP configuration, you can host a Laravel website.
Below, we show you in detail the steps to follow to host a Laravel website and verify that it is working correctly.
Create a new template for using Laravel in VestaCP
To work with Laravel, we need to create templates for Apache and Nginx. To do this, we need to navigate to the following path, where the templates with the Apache2 configurations used when creating or editing a domain hosted in our VestaCP are stored:
# cd /usr/local/vesta/data/templates/web/apache2And we create the following files:
# touch laravel.{tpl,stpl}
We edit laravel.tpl:
# vi laravel.tplAnd we add the following content:
<VirtualHost %ip%:%web_port%>
ServerName %domain_idn%
%alias_string%
ServerAdmin %email%
DocumentRoot %docroot%/public/
ScriptAlias /cgi-bin/ %home%/%user%/web/%domain%/cgi-bin/
Alias /vstats/ %home%/%user%/web/%domain%/stats/
Alias /error/ %home%/%user%/web/%domain%/document_errors/
#SuexecUserGroup %user% %group%
CustomLog /var/log/%web_system%/domains/%domain%.bytes bytes
CustomLog /var/log/%web_system%/domains/%domain%.log combined
ErrorLog /var/log/%web_system%/domains/%domain%.error.log
<Directory %docroot%/public/>
AllowOverride All
Options +Includes -Indexes +ExecCGI
</Directory>
<Directory %home%/%user%/web/%domain%/stats>
AllowOverride All
</Directory>
<IfModule mod_ruid2.c>
RMode config
RUidGid %user% %group%
RGroups www-data
</IfModule>
<IfModule itk.c>
AssignUserID %user% %group%
</IfModule>
IncludeOptional %home%/%user%/conf/web/%web_system%.%domain%.conf*
</VirtualHost> We edit laravel.stpl:
# vi laravel.stplAnd we add the following content:
<VirtualHost %ip%:%web_ssl_port%>
ServerName %domain_idn%
%alias_string%
ServerAdmin %email%
DocumentRoot %sdocroot%/public/
ScriptAlias /cgi-bin/ %home%/%user%/web/%domain%/cgi-bin/
Alias /vstats/ %home%/%user%/web/%domain%/stats/
Alias /error/ %home%/%user%/web/%domain%/document_errors/
#SuexecUserGroup %user% %group%
CustomLog /var/log/%web_system%/domains/%domain%.bytes bytes
CustomLog /var/log/%web_system%/domains/%domain%.log combined
ErrorLog /var/log/%web_system%/domains/%domain%.error.log
<Directory %sdocroot%/public/>
AllowOverride All
SSLRequireSSL
Options +Includes -Indexes +ExecCGI
</Directory>
<Directory %home%/%user%/web/%domain%/stats>
AllowOverride All
</Directory>
SSLEngine on
SSLVerifyClient none
SSLCertificateFile %ssl_crt%
SSLCertificateKeyFile %ssl_key%
%ssl_ca_str%SSLCertificateChainFile %ssl_ca%
<IfModule mod_ruid2.c>
RMode config
RUidGid %user% %group%
RGroups www-data
</IfModule>
<IfModule itk.c>
AssignUserID %user% %group%
</IfModule>
IncludeOptional %home%/%user%/conf/web/s%web_system%.%domain%.conf*
</VirtualHost>
Now we need to create the templates for Nginx, so we navigate to:
# cd /usr/local/vesta/data/templates/web/nginxAnd we create the following files:
# touch laravel.tpl
# touch laravel.stpl
We edit laravel.tpl:
# vi laravel.tplAnd we add the following content:
server {
listen %ip%:%proxy_port%;
server_name %domain_idn% %alias_idn%;
error_log /var/log/%web_system%/domains/%domain%.error.log error;
location / {
proxy_pass http://%ip%:%web_port%;
location ~* ^.+\.(%proxy_extentions%)$ {
root %docroot%/public/;
access_log /var/log/%web_system%/domains/%domain%.log combined;
access_log /var/log/%web_system%/domains/%domain%.bytes bytes;
expires max;
try_files $uri @fallback;
}
}
location /error/ {
alias %home%/%user%/web/%domain%/document_errors/;
}
location @fallback {
proxy_pass http://%ip%:%web_port%;
}
location ~ /\.ht {return 404;}
location ~ /\.svn/ {return 404;}
location ~ /\.git/ {return 404;}
location ~ /\.hg/ {return 404;}
location ~ /\.bzr/ {return 404;}
include %home%/%user%/conf/web/nginx.%domain%.conf*;
} We edit laravel.stpl:
# vi laravel.stplAnd we add the following content:
server {
listen %ip%:%proxy_ssl_port%;
server_name %domain_idn% %alias_idn%;
ssl on;
ssl_certificate %ssl_pem%;
ssl_certificate_key %ssl_key%;
error_log /var/log/%web_system%/domains/%domain%.error.log error;
location / {
proxy_pass https://%ip%:%web_ssl_port%;
location ~* ^.+\.(%proxy_extentions%)$ {
root %sdocroot%/public/;
access_log /var/log/%web_system%/domains/%domain%.log combined;
access_log /var/log/%web_system%/domains/%domain%.bytes bytes;
expires max;
try_files $uri @fallback;
}
}
location /error/ {
alias %home%/%user%/web/%domain%/document_errors/;
}
location @fallback {
proxy_pass https://%ip%:%web_ssl_port%;
}
location ~ /\.ht {return 404;}
location ~ /\.svn/ {return 404;}
location ~ /\.git/ {return 404;}
location ~ /\.hg/ {return 404;}
location ~ /\.bzr/ {return 404;}
include %home%/%user%/conf/web/snginx.%domain%.conf*;
}At this point, we have created the templates for working with Laravel. To check that the templates we created are available, we open the VestaCP administration panel and edit the domain that we want to use Laravel.
In plantilla web(Apache2) and plantilla proxy(Nginx), we need to select the "Laravel" template we created and click guardar to apply the changes.
With these steps, we have seen how to create the templates needed for Laravel in VestaCP.
Test that Laravel works correctly with the MaguttiCMS CMS
Once VestaCP is ready to work with Laravel, it is important to check that it works correctly. Below, as an example, we will host the MaguttiCMS CMS, which is developed with Laravel 7 and Bootstrap 4.5 .
The first step we need to take to work with Laravel is to install Composer, which will help us install Laravel:
# apt-get install composerNext, we download the Laravel installer with Composer:
# composer global require laravel/installer
Using version ^3.2 for laravel/installer
./composer.json has been created
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 19 installs, 0 updates, 0 removals
- Installing symfony/polyfill-php80 (v1.17.1): Downloading (100%)
- Installing symfony/process (v5.1.2): Downloading (100%)
- Installing symfony/polyfill-ctype (v1.17.1): Downloading (100%)
- Installing symfony/filesystem (v5.1.2): Downloading (100%)
- Installing symfony/polyfill-mbstring (v1.17.1): Downloading (100%)
- Installing symfony/polyfill-intl-normalizer (v1.17.1): Downloading (100%)
- Installing symfony/polyfill-intl-grapheme (v1.17.1): Downloading (100%)
- Installing symfony/string (v5.1.2): Downloading (100%)
- Installing psr/container (1.0.0): Downloading (100%)
- Installing symfony/service-contracts (v2.1.3): Downloading (100%)
- Installing symfony/polyfill-php73 (v1.17.1): Downloading (100%)
- Installing symfony/console (v5.1.2): Downloading (100%)
- Installing psr/http-message (1.0.1): Downloading (100%)
- Installing psr/http-client (1.0.1): Downloading (100%)
- Installing ralouphie/getallheaders (3.0.3): Downloading (100%)
- Installing guzzlehttp/psr7 (1.6.1): Downloading (100%)
- Installing guzzlehttp/promises (v1.3.1): Downloading (100%)
- Installing guzzlehttp/guzzle (7.0.1): Downloading (100%)
- Installing laravel/installer (v3.2.0): Downloading (100%)
symfony/service-contracts suggests installing symfony/service-implementation ()
symfony/console suggests installing symfony/event-dispatcher ()
symfony/console suggests installing symfony/lock ()
symfony/console suggests installing psr/log (For using the console logger)
guzzlehttp/psr7 suggests installing zendframework/zend-httphandlerrunner (Emit PSR-7 responses)
guzzlehttp/guzzle suggests installing psr/log (Required for using the Log middleware)
Writing lock file
Generating autoload filesWe go to our website's public_html directory. Our website's document root is the public folder of the Laravel project, as we can see in the templates created earlier:
# cd /home/admin/web/prueba.com/public_html/We download the Magutti CMS from its Github repository:
# git clone https://github.com/marcoax/maguttiCms.gitWe access the directory "maguttiCms":
# cd maguttiCms
For it to work with the templates created for Laravel, we need to move the contents of the folder "maguttiCms" to the "public_html" folder
# mv * .* ../
# cd ..We assign the correct permissions and owner to the files and directories:
# find ./ -type f -exec chmod 644 {} ";"
# find ./ -type d -exec chmod 755 {} ";"
# chown -R admin:admin ./Now we need to copy the .env.example file to .env to edit the environment variables. In this case, to configure the database connection:
# cp .env.example .envBefore starting to edit the .env file, we will need to create a database. To do this, we access the VestaCP administration panel at https://ip_publica:8083 and go to bases de datos > añadir.
Now we assign a name to the database, a username and password, and click añadir. In this example, we use "maguttiCMS".
Keep in mind that VestaCP adds the "admin_" prefix to the database name and username.
We now return to the command line and run the following command to edit the environment variables:
# vi .envIn this file, we need to edit the Mysql connection configuration that MaguttiCMS will use:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=admin_maguttiCms
DB_USERNAME=admin_maguttiCms
DB_PASSWORD=maguttiCms
Next, we proceed to install the CMS with the following command:
# composer installOnce it is installed, we need to generate the keys:
# php artisan key:generateThe last remaining step is to import the MaguttiCMS database, which is located inside the "db" folder:
# cd db
# mysql -u root -p admin_maguttiCms < framework_base.sqlNow we access our CMS "http://nombre_dominio" and see that the CMS is already available.
Information
Sometimes you may see an error indicating that the Key has not been generated. In that case, we run the following again:
# php artisan key:generate
To access the administration panel, we go to the URL "http://nombre_dominio/admin" with username "cmsadmin@magutti.com" and password "password".
With these final steps, we have verified that our VestaCP is ready to work with Laravel.