banner



How To Install Packages In Centos 7

Introduction

A LEMP software stack is a group of open source software that is typically installed together to enable a server to host dynamic websites and web apps. This term is really an acronym which represents the Fiftyinux operating system, with the ENginx web server (which replaces the Apache component of a LAMP stack). The site data is stored in a YardySQL-based database, and dynamic content is processed by PHP.

In this guide, we'll get a LEMP stack with PHP seven.4 installed on a CentOS 7 server, using MariaDB equally the database management arrangement. MariaDB works as a driblet-in replacement for the original MySQL server, which in do ways you tin switch to MariaDB without having to make any configuration or code changes in your application.

Prerequisites

Before you begin with this guide, you should accept a separate, non-root user account set upward on your server. Yous can learn how to exercise this by completing steps 1-four in the initial server setup for CentOS 7.

Step 1 — Installing Nginx

In order to display web pages to our site visitors, we are going to employ Nginx, a high-performance web server. To get the latest Nginx version, we'll offset install the EPEL repository, which contains additional software for the CentOS 7 operating system.

To add the CentOS 7 EPEL repository, run the following control:

                      
  1. sudo yum install epel-release

Since we are using a sudo control, these operations go executed with root privileges. It will ask you for your regular user'south countersign to verify that you have permission to run commands with root privileges. You'll besides be prompted to ostend installation, so printing Y to proceed.

At present that the EPEL repository is installed on your server, install Nginx using the following yum command:

                      
  1. sudo yum install nginx

One time the installation is finished, start the Nginx service with:

                      
  1. sudo systemctl outset nginx

You can do a spot check correct away to verify that everything went every bit planned by visiting your server'due south public IP accost in your web browser (see the note under the side by side heading to find out what your public IP address is if you exercise not have this information already):

                      

Open in a web browser:

http://server_domain_name_or_IP/

You will see the default CentOS 7 Nginx web folio, which is there for informational and testing purposes. It should look something like this:

CentOS 7 Nginx Default

If you see this page, and so your web server is now correctly installed.

To enable Nginx to start on boot, run the following command:

                      
  1. sudo systemctl enable nginx

How To Find Your Server'southward Public IP Address

If yous do not know what your server'southward public IP address is, in that location are a number of means you can find it. Usually, this is the address you lot utilize to connect to your server through SSH.

From the control line, you can discover this a few ways. First, y'all tin can utilise the iproute2 tools to go your address by typing this:

                      
  1. ip addr bear witness eth0 | grep inet | awk '{ print $2; }' | sed 's/\/.*$//'

This will give you lot ane or two lines back. They are both correct addresses, only your computer may only exist able to use one of them, so experience free to try each one.

An alternative method is to use an outside party to tell you how it sees your server. You can exercise this by asking a specific server what your IP accost is:

                      
  1. roll http://icanhazip.com

Regardless of the method you use to get your IP accost, you lot can blazon it into your web browser's accost bar to get to your server.

Step two — Installing MariaDB

Now that we have our web server up and running, it is time to install MariaDB, a MySQL drop-in replacement. MariaDB is a community-developed fork of the MySQL relational database management system.

Again, nosotros can use yum to acquire and install our software. This fourth dimension, we'll also install some other helper packages that will assist us in getting our components to communicate with each other:

                      
  1. sudo yum install mariadb-server mariadb

When the installation is complete, nosotros need to start MariaDB with the post-obit command:

                      
  1. sudo systemctl start mariadb

At present that our MariaDB database is running, we want to run a security script that will remove some dangerous defaults and lock downwardly admission to our database. Start the interactive script by running:

                      
  1. sudo mysql_secure_installation

The prompt will ask yous for your electric current root MariaDB countersign. Since yous just installed MariaDB, you most likely won't have one, so leave it blank by pressing enter. And then the prompt will ask you if you lot desire to set a root countersign. Become ahead and enter Y, and follow the instructions:

                      

mysql_secure_installation prompts:

Enter current password for root (enter for none): OK, successfully used password, moving on... Setting the root countersign ensures that nobody can log into the MariaDB root user without the proper authorization. Set up root password? [Y/n] y New password: Re-enter new password: Countersign updated successfully! Reloading privilege tables.. ... Success!

For the rest of the questions, yous should hitting the "ENTER" central through each prompt to have the default values. This will remove some sample users and databases, disable remote root logins, and load these new rules and so that MySQL immediately respects the changes we have fabricated.

The last thing you volition desire to do is enable MariaDB to first on kicking. Use the following control to do so:

                      
  1. sudo systemctl enable mariadb

At this point, your database system is now set and nosotros can move on.

Step three — Installing PHP

PHP is the component of our setup that will process code to display dynamic content. It can run scripts, connect to our MySQL databases to get information, and hand the processed content over to our web server to brandish.

The PHP version available by default within CentOS 7 servers is outdated, and for that reason, we'll need to install a third-party bundle repository in order to obtain PHP vii+ and get it installed on your CentOS vii server. Remi is a popular bundle repository providing the nearly up-to-date PHP releases for CentOS servers.

To install the Remi repository for CentOS 7, run:

                      
  1. sudo yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm

Afterwards the installation is done, you'll need to run a command to enable the repository containing your preferred version of PHP. To check which PHP 7+ releases are bachelor in the Remi repository, run:

                      
  1. yum --disablerepo= "*" --enablerepo= "remi-rubber" list php[ vii-9] [ 0-ix].x86_64

Y'all'll meet output like this:

                      

Output

Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * remi-prophylactic: mirrors.ukfast.co.uk Bachelor Packages php70.x86_64 2.0-i.el7.remi remi-safe php71.x86_64 2.0-one.el7.remi remi-safe php72.x86_64 2.0-1.el7.remi remi-safety php73.x86_64 2.0-one.el7.remi remi-safe php74.x86_64 1.0-3.el7.remi remi-condom php80.x86_64 i.0-3.el7.remi remi-safe

In this guide, nosotros'll install PHP seven.4, which is currently the most updated stable version of PHP. To enable the correct Remi packet to get PHP seven.iv installed, run:

                      
  1. sudo yum-config-manager --enable remi-php74

Now we can keep to use yum for installing PHP as usual. The post-obit command will install all the required packages to get PHP seven.4 set up upwards inside Nginx and let it to connect to MySQL-based databases:

                      
  1. sudo yum install php php-mysqlnd php-fpm

To ostend that PHP is available every bit your called version, run:

                      
  1. php --version

Y'all'll see output like this:

                      

Output

PHP vii.4.5 (cli) (congenital: April 14 2022 12:54:33) ( NTS ) Copyright (c) The PHP Group Zend Engine v3.four.0, Copyright (c) Zend Technologies

PHP is now successfully installed on your system. Next, we need to make a few adjustments to the default configuration. To facilitate editing files on CentOS, we'll first install nano, a more user-friendly text editor than half-dozen:

                      
  1. sudo yum install nano

Open the /etc/php-fpm.d/www.conf configuration file using nano or your editor of option:

                      
  1. sudo nano /etc/php-fpm.d/world wide web.conf

Now look for the user and group directives. If you are using nano, you tin can hitting CTRL+West to search for these terms inside the open file.

/etc/php-fpm.d/world wide web.conf

          … ; Unix user/group of processes ; Notation: The user is mandatory. If the group is not set up, the default user's group ;       will be used. ; RPM: apache user called to provide access to the aforementioned directories equally httpd user =            apache            ; RPM: Go along a group immune to write in log dir. group =            apache        

You lot'll notice that both the user and group variables are set to apache. We need to change these to nginx:

/etc/php-fpm.d/www.conf

          … ; RPM: apache user called to provide access to the aforementioned directories every bit httpd user =            nginx            ; RPM: Keep a group allowed to write in log dir. group =            nginx        

Next, locate the listen directive. By default, php-fpm will listen on a specific host and port over TCP. We desire to modify this setting so it listens on a local socket file, since this improves the overall performance of the server. Change the line containing the listen directive to the post-obit:

/etc/php-fpm.d/www.conf

          listen =            /var/run/php-fpm/php-fpm.sock;                  

Finally, we'll need to change the owner and group settings for the socket file we only divers inside the listen directive. Locate the heed.owner, listen.group and listen.mode directives. These lines are commented out by default. Uncomment them by removing the preceding ; sign at the beginning of the line. And then, change the owner and grouping to nginx:

/etc/php-fpm.d/www.conf

                      listen.owner = nginx            heed.group = nginx            listen.mode = 0660                  

Relieve and shut the file when y'all're done editing. If you are using nano, do so by pressing CTRL + 10, then Y and ENTER.

To enable and beginning the php-fpm service, run:

                      
  1. sudo systemctl start php-fpm

Your PHP environs is now gear up. Next, we'll configure Nginx so that it sends all requests for PHP scripts to be processed past php-fpm.

Step four — Configuring Nginx to Process PHP Pages

Now, nosotros have all of the required components installed. The just configuration alter nosotros notwithstanding demand to do is tell Nginx to employ our PHP processor for dynamic content.

Nginx has a dedicated directory where we can define each hosted website as a carve up configuration file, using a server block. This is like to Apache's virtual hosts.

With the default installation, even so, this directory is empty. We'll create a new file to serve as the default PHP website on this server, which volition override the default server block divers in the /etc/nginx/nginx.conf file.

Beginning, open a new file in the /etc/nginx/conf.d directory:

                      
  1. sudo nano /etc/nginx/conf.d/default.conf

Copy the following PHP server definition block to your configuration file, and don't forget to replace the server_name directive so that information technology points to your server's domain proper name or IP address:

/etc/nginx/conf.d/default.conf

          server {     listen       fourscore;     server_name            server_domain_or_IP;      root   /usr/share/nginx/html;     alphabetize index.php index.html alphabetize.htm;      location / {         try_files $uri $uri/ =404;     }     error_page 404 /404.html;     error_page 500 502 503 504 /50x.html;          location = /50x.html {         root /usr/share/nginx/html;     }      location ~ \.php$ {         try_files $uri =404;         fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;         fastcgi_index index.php;         fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;         include fastcgi_params;     } }                  

Save and close the file when you're done.

Next, restart Nginx to employ the changes:

                      
  1. sudo systemctl restart nginx

Your web server is at present fully set. In the side by side step, nosotros'll test the PHP integration to Nginx.

Step 5 — Testing PHP Processing on your Spider web Server

Now that your spider web server is prepare up, nosotros tin can create a test PHP script to make certain Nginx is correctly handling .php scripts with the help of php-fpm.

Before creating our script, we'll make a change to the default ownership settings on Nginx's document root, and then that our regular sudo user is able to create files in that location.

The post-obit command will change the ownership of the default Nginx certificate root to a user and group chosen sammy, so be sure to supersede the highlighted username and group in this command to reflect your system'southward username and group.

                      
  1. sudo chown -R sammy.sammy /usr/share/nginx/html/

We'll now create a test PHP page to make sure the web server works as expected.

Create a new PHP file called info.php at the /usr/share/nginx/html directory:

                      
  1. nano /usr/share/nginx/html/info.php

The following PHP code volition brandish information about the electric current PHP environment running on the server:

/usr/share/nginx/html/info.php

                                    <?php              phpinfo              (              )              ;                              

When you are finished, save and close the file.

Now we tin test whether our spider web server can correctly display content generated past a PHP script. Get to your browser and admission your server hostname or IP accost, followed by /info.php:

          http://server_host_or_IP/info.php                  

You'll see a page similar to this:

CentOS 7 PHP 7.4 info

After checking the relevant information almost your PHP server through that page, it'due south best to remove the file you created as it contains sensitive data nigh your PHP environment and your CentOS server. You tin can use rm to remove that file:

                      
  1. rm /usr/share/nginx/html/info.php

You can e'er regenerate this file if you lot need it later.

Decision

In this guide, you've built a flexible foundation for serving PHP websites and applications to your visitors, using Nginx as web server and the latest PHP release version. You've set up Nginx to handle PHP requests through php-fpm, and you also set up a MariaDB database to store your website's data.

Source: https://www.digitalocean.com/community/tutorials/how-to-install-linux-nginx-mysql-php-lemp-stack-on-centos-7

Posted by: vegaherity.blogspot.com

0 Response to "How To Install Packages In Centos 7"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel