The world of programming requires applications that adapt to its dynamism, complexity and daily scalability, offering solutions that integrate parameters such as compatibility, support, simplicity, but robustness of use and versatility.
There are several options for the different programming languages where one of the most used and outstanding worldwide is PHP and for this we have a framework that will further boost the use and possibilities that PHP offers and is Laravel..
TechnoWikis will explain in detail how to install Laravel on CentOS 7 in order to have a powerful tool to execute and implement PHP.
What is Laravel
Laravel has been developed as a web application framework which has an expressive, simple and modern syntax since it allows traditional programming tasks such as authentication, routing, sessions and caching, to be something simple to use centrally covering every aspect so that none fails.
Laravel combines the best of other existing frameworks that include those that are special for other programming languages ​​such as Ruby on Rails, ASP.NET MVC and Sinatra. By using Larevel, we have a framework that gives us all the tools necessary to create and manage large and robust applications as it has control containers, an expressive migration system and a new integrated unit test support to facilitate the construction of Any application required..
Laravel features
Among the most outstanding features of Laravel we find:
- Authentication: Laravel has a simple built-in authentication that can be easily integrated into any Laravel application by running some basic commands.
- Caching: Caching is used to store data temporarily for a while to be able to recover it quickly, so that by using caching you can reduce the load on the database server. Laravel has an expressive and unified API in order to interact with the various caching backends such as Memcached and Redis.
- Logic of application. When using Laravel, the application logic is written in Controllers or directly on the routes.
- Automatic paging: Laravel has built-in pages that eliminate the process of writing code for assigned paging records.
- Dependency Method or Injection: Laravel service containers have a tool designed to manage class dependencies and perform dependency injections in the application.
- Routing: When we use Laravel, routing is used to attach application URLs to a specific controller action or view.
Some additional features are:
- It supports a simple authentication mechanism.
- Supports the transmission of events in real time.
- It has a unified API in multiple queue backends where Amazon SQS and Redis are integrated and more, for session and cache storage.
- Compatible with independent database migrations and schema generator.
- Supports background job processing.
Server requirements
To install Laravel correctly, it will be necessary to meet the following requirements:
Now let's see how to install Laravel on CentOS 7.
1. Configure Yum repositories in CentOS 7 and RedHat
The first step to take is to enable the REMI and EPEL repositories in CentOS in order to have updated packages such as PHP, Nginx, MariaDB, and more, for this we will use the following commands:
2. Install Nginx on CentOS 7 and RedHat
Now we are going to install a LEMP work environment in CentOS 7, in case we don't have it, we will install it by executing the following commands:
yum install nginx
Note
LEMP is a group of software in which dynamic web pages and web applications can be hosted. It is an acronym that describes a Linux operating system, with a Nginx web server, the backend data is stored in the MySQL database and the dynamic processing is handled by PHP.
Enter the letter y to confirm the download and installation of Nginx. Once Nginx is installed, we will start the web server and configure it to run when the operating system starts up and then give this, we will verify the status with the following commands:
In CentOS / RHEL 7
systemctl start nginx systemctl enable nginx systemctl status nginx
In CentOS / RHEL 6
In order to have access to Nginx from a public network, it will be necessary to open port 80 on the CentOS 7 firewall in order to receive external requests, to perform this port enablement, we will execute the following.
service nginx start chkconfig nginx on service nginx status
In CentOS / RHEL 7
firewall-cmd --permanent --add-port = 80 / tcp firewall-cmd --reload
In CentOS / RHEL 6
iptables -A INPUT -p tcp --dport 80 -j ACCEPT service iptables restart
3. Install MySQL on CentOS 7 and RedHat
Step 1
The next step to take will be the installation of MySQL for database management, for this we will execute the following commands:
yum install mariadb-server php-mysql
Step 2
Enter the letter and to confirm the download and installation. We proceed to start the MySQL service:
systemctl start mariadb.service
Step 3
We ensure the installation of MySQL. There we answer the questions based on need, but usually all are affirmative.
/ usr / bin / mysql_secure_installation
4. Install PHP on CentOS 7 and RedHat
Step 1
Now, we are going to install the PHP language in CentOS 7 and for this we execute the following commands in their order:
yum install yum-utils yum-config-manager --enable remi-php72 yum install php php-fpm php-common php-xml php-mbstring php-json php-zip
Step 2
Enter the letter
and to accept the download and installation. Now, we will enable and configure PHP to run on CentOS 7 startup:
In CentOS / RHEL 7
systemctl start php-fpm systemctl enable php-fpm systemctl status php-fpm
In CentOS / RHEL 6
service php-fpm start chkconfig php-fpm on service php-fpm status
5. Install Composer and Laravel PHP Framework on CentOS 7 and RedHat
Step 1
Now we are going to install Composer next to the PHP and Laravel dependencies by executing the following commands:
curl -sS https://getcomposer.org/installer | php mv composer.phar / usr / local / bin / composer chmod + x / usr / local / bin / composer
Step 2
Once Composer has been installed, we will install Laravel by executing the composer's "create-project" command like this:
cd / var / www / html / sudo composer create-project --prefer-dist laravel / laravel testsite
Step 3
Now, when we are going to verify the test directory "testsite" and verify that it must exist there, containing the Laravel files, for this we execute:
ls -l / var / www / html / testsite
6. Configure the installation of Laravel on CentOS 7 and RedHat
Step 1
Now we are going to configure the appropriate permissions both in the files and in the directory created like this:
chmod -R 775 / var / www / html / testsite chown -R apache.apache / var / www / html / testsite chmod -R 777 / var / www / html / testsite / storage /
Step 2
Also, if SELinux is enabled, it will be necessary to update the security context of the storage and boot / cache directories with the following commands:
Semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/html/testsite/bootstrap/cache(/.*))?' Semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/html/testsite/storage(/.*)?' restorecon -Rv '/ usr / share / nginx / html / testapp'
Step 2
Now, we are going to create an environment file for the application, we execute the following syntax:
cp .env. example .env
Step 3
After this, Laravel makes use of an application key in order to secure user sessions and other encrypted data, it will be necessary to generate and set the application key in a random chain using the following command:
php artisan key: generate
7. Configure the Nginx server block for Laravel on CentOS 7 and RedHat
Step 1
This must be created to configure a Nginx server block for the test site created, in order to access it from a web browser, for this we will create a .conf file in the /etc/nginx/conf.d directory / using the desired editor like this:
nano /etc/nginx/conf.d/testsite.conf
Step 2
There we will paste the following:
server { listen 80; server_name (domain_name.com); root / var / www / html / testsite / public; index index.php; charset utf-8; gzip on; gzip_types text / css application / javascript text / javascript application / x-javascript image / svg + xml text / plain text / xsd text / xsl text / xml image / x-icon; location / { try_files $ uri $ uri / /index.php?$query_string; } location ~ \ .php { include fastcgi.conf; fastcgi_split_path_info ^ (. + \. php) (/.+) $; fastcgi_pass unix: /var/run/php/php7.2-fpm.sock; } location ~ /\.ht { deny all; } }
Step 3
We save the changes using the following key combination:
+ O Ctrl + O
We leave the editor using:
+ X Ctrl + X
Step 4
We restart the Nginx service:
systemctl restart nginx Access to Larevel
Step 5
Now we can go to a browser and enter the domain name or IP address of CentOS 7 to access the Larevel information. From there we can access the documentation, news and others.
Thus, we have configured Larevel for a complete PHP management in CentOS 7..