{"id":13835,"date":"2019-04-06T10:20:28","date_gmt":"2019-04-06T10:20:28","guid":{"rendered":"http:\/\/www.appservgrid.com\/paw92\/?p=13835"},"modified":"2019-04-06T10:20:28","modified_gmt":"2019-04-06T10:20:28","slug":"how-to-install-nginx-1-15-mariadb-10-and-php-7-on-centos-7","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/04\/06\/how-to-install-nginx-1-15-mariadb-10-and-php-7-on-centos-7\/","title":{"rendered":"How to Install Nginx 1.15, MariaDB 10 and PHP 7 on CentOS 7"},"content":{"rendered":"<p>In this article we will explain how to install a\u00a0<strong>LEMP<\/strong>\u00a0stack (<strong>Linux<\/strong>,\u00a0<strong>Nginx<\/strong>,\u00a0<strong>MariaDB<\/strong>,\u00a0<strong>PHP<\/strong>) along with\u00a0<strong>PHP-FPM<\/strong>\u00a0on\u00a0<strong>RHEL\/CentOS 7\/6<\/strong>\u00a0and\u00a0<strong>Fedora 26-29<\/strong>\u00a0servers using\u00a0<a href=\"https:\/\/www.tecmint.com\/20-linux-yum-yellowdog-updater-modified-commands-for-package-mangement\/\" target=\"_blank\" rel=\"noopener\">yum<\/a>\u00a0and\u00a0<a href=\"https:\/\/www.tecmint.com\/dnf-commands-for-fedora-rpm-package-management\/\" target=\"_blank\" rel=\"noopener\">dnf<\/a>\u00a0package manager.<\/p>\n<p>During the process we will install and enable\u00a0<strong>Epel<\/strong>,\u00a0<strong>Remi<\/strong>,\u00a0<strong>Nginx<\/strong>\u00a0and\u00a0<strong>MariaDB<\/strong>\u00a0repositories in order to be able to install the latest versions of these packages.<\/p>\n<p><b>Read Also:<\/b>\u00a0<a href=\"https:\/\/www.tecmint.com\/install-apache-mysql-php-on-redhat-centos-fedora\/\" target=\"_blank\" rel=\"noopener\">Install Apache, MySQL 8 or MariaDB 10 and PHP 7 on CentOS 7<\/a><\/p>\n<h3>Step 1: Installing EPEL and Remi Repository<\/h3>\n<p><strong>EPEL<\/strong>\u00a0(<strong>Extra Packages for Enterprise Linux<\/strong>) is a community based repository offers add-on software packages for RHEL-based Linux distributions.<\/p>\n<p><strong>Remi<\/strong>\u00a0is a repository where you can find the latest versions of the\u00a0<strong>PHP<\/strong>\u00a0stack (full featured) for installation in the Fedora and Enterprise Linux distributions.<\/p>\n<h4>On RHEL\/CentOS 7<\/h4>\n<pre># yum update &amp;&amp; yum install epel-release\r\n# rpm -Uvh http:\/\/rpms.famillecollet.com\/enterprise\/remi-release-7.rpm\r\n\r\n------ <strong>For RHEL 7 Only<\/strong> ------\r\n# subscription-manager repos --enable=rhel-7-server-optional-rpms\r\n<\/pre>\n<h4>On RHEL\/CentOS 6<\/h4>\n<pre># yum update &amp;&amp; yum install epel-release\r\n# rpm -Uvh http:\/\/rpms.famillecollet.com\/enterprise\/remi-release-6.rpm\r\n\r\n------ <strong>For RHEL 6 Only<\/strong> ------\r\n# subscription-manager repos --enable=rhel-6-server-optional-rpms\r\n<\/pre>\n<h4>On Fedora 24-29<\/h4>\n<pre># rpm -Uvh http:\/\/rpms.remirepo.net\/fedora\/remi-release-29.rpm  [<strong>On Fedora 29<\/strong>]\r\n# rpm -Uvh http:\/\/rpms.remirepo.net\/fedora\/remi-release-28.rpm  [<strong>On Fedora 28<\/strong>]\r\n# rpm -Uvh http:\/\/rpms.remirepo.net\/fedora\/remi-release-27.rpm  [<strong>On Fedora 27<\/strong>]\r\n# rpm -Uvh http:\/\/rpms.remirepo.net\/fedora\/remi-release-26.rpm  [<strong>On Fedora 26<\/strong>]\r\n# rpm -Uvh http:\/\/rpms.remirepo.net\/fedora\/remi-release-25.rpm  [<strong>On Fedora 25<\/strong>]\r\n# rpm -Uvh http:\/\/rpms.remirepo.net\/fedora\/remi-release-24.rpm  [<strong>On Fedora 24<\/strong>]\r\n<\/pre>\n<h3>Step 2: Installing Nginx and MariaDB Repositories<\/h3>\n<p>The Nginx repository is only needed in\u00a0<strong>RHEL<\/strong>\u00a0and\u00a0<strong>CentOS<\/strong>\u00a0distributions. Create a file called\u00a0<strong>\/etc\/yum.repos.d\/nginx.repo<\/strong>\u00a0and add the following lines to it.<\/p>\n<h4>For RHEL 7\/6:<\/h4>\n<pre>[nginx] \r\nname=nginx repo \r\nbaseurl=http:\/\/nginx.org\/packages\/rhel\/$releasever\/$basearch\/ \r\ngpgcheck=0 \r\nenabled=1 \r\n<\/pre>\n<h4>For CentOS 7\/6:<\/h4>\n<pre>[nginx] \r\nname=nginx repo \r\nbaseurl=http:\/\/nginx.org\/packages\/centos\/$releasever\/$basearch\/ \r\ngpgcheck=0 \r\nenabled=1 \r\n<\/pre>\n<p>To enable the\u00a0<strong>MariaDB<\/strong>\u00a0repository, create a file named\u00a0<strong>\/etc\/yum.repos.d\/mariadb.repo<\/strong>\u00a0with the following contents:<\/p>\n<pre>[mariadb] \r\nname = MariaDB \r\nbaseurl = http:\/\/yum.mariadb.org\/10.1\/centos7-amd64 \r\ngpgkey=https:\/\/yum.mariadb.org\/RPM-GPG-KEY-MariaDB \r\ngpgcheck=1 \r\n<\/pre>\n<h3>Step 4: Installing Ngnix and MariaDB<\/h3>\n<p><strong>Nginx<\/strong>\u00a0(<strong>Engine X<\/strong>) is open source, robust, lightweight and high performance Web server, reverse proxy sever and also mail proxy server for HTTP, SMTP, POP3 and IMAP protocols. For further details, visit\u00a0<a href=\"https:\/\/www.nginx.com\/resources\/wiki\/\" target=\"_blank\" rel=\"noopener\">http:\/\/wiki.nginx.org\/Overview<\/a>.<\/p>\n<p><strong>MariaDB<\/strong>\u00a0is a fork of the well-known MySQL, one of the world\u2019s most popular Relational Database Management System (RDBMS). It is entirely developed by the community and as such it is intended to remain FOSS and compatible with the GPL.<\/p>\n<p>To install\u00a0<strong>Ngnix<\/strong>\u00a0and\u00a0<strong>MariaDB<\/strong>, run the following commands.<\/p>\n<pre>----------- <strong>Installing on RHEL\/CentOS 7\/6<\/strong> ----------- \r\n# yum --enablerepo=remi install nginx MariaDB-client MariaDB-server php php-common php-fpm \r\n\r\n----------- <strong>Installing on Fedora<\/strong> ----------- \r\n# dnf --enablerepo=remi install nginx MariaDB-client MariaDB-server php php-common php-fpm \r\n<\/pre>\n<h3>Step 3: Installing PHP Using Remi Repository<\/h3>\n<p><strong>PHP<\/strong>\u00a0(<strong>Hypertext Preprocessor<\/strong>) is a Free and Open Source server-side scripting language that is best suited for web development. It can be used to produce dynamic web pages for a website and is most frequently found in *nix servers. One of the advantages of PHP is that it is easily extensible through the use of a wide variety of modules.<\/p>\n<p>To install\u00a0<strong>PHP<\/strong>, first you need to enable\u00a0<strong>Remi<\/strong>\u00a0repository by installing\u00a0<code>yum-utils<\/code>, a collection of useful programs for managing yum repositories and packages.<\/p>\n<pre># yum install yum-utils\r\n<\/pre>\n<p>Once installed, you can use\u00a0<strong>yum-config-manager<\/strong>\u00a0provided by\u00a0<code>yum-utils<\/code>\u00a0to enable Remi repository as the default repository for installing different PHP versions as shown.<\/p>\n<p>For example, to install\u00a0<strong>PHP 7.x<\/strong>\u00a0version, use the following command.<\/p>\n<pre><strong>------------- On CentOS &amp; RHEL -------------<\/strong> \r\n# yum-config-manager --enable remi-php70 &amp;&amp; yum install php       [<strong>Install PHP 7.0<\/strong>]\r\n# yum-config-manager --enable remi-php71 &amp;&amp; yum install php       [<strong>Install PHP 7.1<\/strong>]\r\n# yum-config-manager --enable remi-php72 &amp;&amp; yum install php       [<strong>Install PHP 7.2<\/strong>]\r\n# yum-config-manager --enable remi-php73 &amp;&amp; yum install php       [<strong>Install PHP 7.3<\/strong>]\r\n\r\n<strong>------------- On Fedora -------------<\/strong> \r\n# dnf --enablerepo=remi install php70      [<strong>Install PHP 7.0<\/strong>]\r\n# dnf --enablerepo=remi install php71      [<strong>Install PHP 7.1<\/strong>]\r\n# dnf --enablerepo=remi install php72      [<strong>Install PHP 7.2<\/strong>]\r\n# dnf --enablerepo=remi install php73      [<strong>Install PHP 7.3<\/strong>]\r\n<\/pre>\n<p>Next, we are going to install all these following PHP modules.<\/p>\n<pre>------ <strong>On RHEL\/CentOS 7\/6<\/strong> ------\r\n# yum --enablerepo=remi install php-mysqlnd php-pgsql php-fpm php-pecl-mongo php-pdo php-pecl-memcache php-pecl-memcached php-gd php-xml php-mbstring php-mcrypt php-pecl-apcu php-cli php-pear\r\n\r\n------ <strong>On Fedora<\/strong> ------\r\n# dnf --enablerepo=remi install php-mysqlnd php-pgsql php-fpm php-pecl-mongo php-pdo php-pecl-memcache php-pecl-memcached php-gd php-xml php-mbstring php-mcrypt php-pecl-apcu php-cli php-pear\r\n<\/pre>\n<h3>Step 6: Stopping and Disabling Apache Service<\/h3>\n<p>By default,\u00a0<strong>Apache<\/strong>\u00a0and\u00a0<strong>Nginx<\/strong>\u00a0listen in same port (TCP\u00a0<strong>80<\/strong>). For that reason, if Apache is installed in your server, you need to stop it and disable \/ mask it (a stronger version of disable that links the service to\u00a0<strong>\/dev\/null<\/strong>) in order to use Nginx, or you can remove it if you\u2019re not planning on using it anymore.<\/p>\n<pre># systemctl stop httpd \r\n# systemctl disable httpd \r\nor \r\n# systemctl mask httpd \r\n<\/pre>\n<h3>Step 7: Starting\/Stopping Nginx, MariaDB and PHP-FPM<\/h3>\n<pre>----------- <strong>Enable Nginx, MariaDB and PHP-FPM on Boot<\/strong> ----------- \r\n# systemctl enable nginx \r\n# systemctl enable mariadb \r\n# systemctl enable php-fpm \r\n \r\n----------- <strong>Start Nginx, MariaDB and PHP-FPM<\/strong> ----------- \r\n# systemctl start nginx \r\n# systemctl start mariadb \r\n# systemctl start php-fpm \r\n<\/pre>\n<h3>Step 8: Configuring Nginx and PHP-FPM<\/h3>\n<p>Let us now create a directory structure for your website (a virtual host, or server block as it is called in Nginx) under\u00a0<strong>\/srv\/www\/<\/strong>. In this example we will use\u00a0<code>www.tecmint.com<\/code>, but feel free to choose another domain and main directory if you want.<\/p>\n<pre># mkdir -p \/srv\/www\/tecmint\/public_html \r\n# mkdir \/srv\/www\/tecmint\/logs \r\n# chown -R nginx:nginx \/srv\/www\/tecmint  \r\n<\/pre>\n<h3>Step 9: Configuring Nginx Virtual Host Directories<\/h3>\n<p>As you know, the ability of running several sites from the same machine is one of the distinguishing features of major web servers. Let us now proceed to create the directories to store our server blocks (known as virtual hosts in Apache) under\u00a0<strong>\/etc\/nginx<\/strong>.<\/p>\n<pre># mkdir \/etc\/nginx\/sites-available \r\n# mkdir \/etc\/nginx\/sites-enabled \r\n<\/pre>\n<p>The following line of code, which must be inserted before closing the http block in\u00a0<strong>\/etc\/nginx\/nginx.conf<\/strong>, will ensure that configuration files inside the\u00a0<strong>\/etc\/nginx\/sites-enabled<\/strong>\u00a0directory will be taken into account when Nginx is running:<\/p>\n<pre>## Load virtual host conf files. ## \r\n<strong>include \/etc\/nginx\/sites-enabled\/*;<\/strong> \r\n<\/pre>\n<div id=\"attachment_20885\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2013\/01\/Configuring-Nginx-VirtualHost.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-20885\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2013\/01\/Configuring-Nginx-VirtualHost.png\" alt=\"Configuring Nginx VirtualHost\" width=\"622\" height=\"350\" aria-describedby=\"caption-attachment-20885\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-20885\" class=\"wp-caption-text\">Configuring Nginx VirtualHost<\/p>\n<\/div>\n<p>To create the server block for\u00a0<code>tecmint.com<\/code>, add the following lines of code to\u00a0<strong>\/etc\/nginx\/sites-available\/tecmint<\/strong>\u00a0(this file will be created when you enter the full path to start your preferred text editor). This is a basic virtual host config file.<\/p>\n<pre>server { \r\n\tlisten 80 default; \r\n\tserver_name tecmint; \r\n\taccess_log \/srv\/www\/tecmint\/logs\/access.log; \r\n\terror_log \/srv\/www\/tecmint\/logs\/error.log; \r\n\troot \/srv\/www\/tecmint\/public_html; \r\n\tlocation ~* \\.php$ { \r\n\tfastcgi_index   index.php; \r\n\tfastcgi_pass    127.0.0.1:9000; \r\n\tinclude         fastcgi_params; \r\n\tfastcgi_param   SCRIPT_FILENAME    $document_root$fastcgi_script_name; \r\n\tfastcgi_param   SCRIPT_NAME        $fastcgi_script_name; \r\n\t} \r\n} \r\n<\/pre>\n<p>The process of \u201c<strong>activating<\/strong>\u201d a virtual host consists of creating a symbolic link from the definition of the\u00a0<code>tecmint<\/code>\u00a0virtual host to\u00a0<strong>\/etc\/nginx\/sites-enabled<\/strong>.<\/p>\n<pre># ln -s \/etc\/nginx\/sites-available\/tecmint \/etc\/nginx\/sites-enabled\/tecmint \r\n<\/pre>\n<p>In order to actually apply the changes we have been doing, we now need to restart Nginx. It is sometimes useful to check the configuration files for syntax errors before doing so:<\/p>\n<pre># nginx -t \r\n# systemctl restart nginx \r\n# systemctl status nginx \r\n<\/pre>\n<div id=\"attachment_20886\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2013\/01\/Restart-Nginx-and-Verify-Status.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-20886\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2013\/01\/Restart-Nginx-and-Verify-Status.png\" sizes=\"auto, (max-width: 839px) 100vw, 839px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2013\/01\/Restart-Nginx-and-Verify-Status.png 839w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2013\/01\/Restart-Nginx-and-Verify-Status-768x367.png 768w\" alt=\"Restart Nginx and Verify Status\" width=\"839\" height=\"401\" aria-describedby=\"caption-attachment-20886\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-20886\" class=\"wp-caption-text\">Restart Nginx and Verify Status<\/p>\n<\/div>\n<p>To access your newly created virtual host, you need to add the following line to\u00a0<strong>\/etc\/hosts<\/strong>\u00a0as a basic method of domain name resolution.<\/p>\n<pre>192.168.0.18\twww.tecmint.com tecmint.com \r\n<\/pre>\n<h3>Step 10: Testing Nginx, MySQL, PHP and PHP-FPM<\/h3>\n<p>Let\u2019s stick with the classic way of testing PHP. Create a file called\u00a0<code>test.php<\/code>\u00a0under\u00a0<strong>\/srv\/www\/tecmint\/public_html\/<\/strong>\u00a0and add the following lines of code to it.<\/p>\n<p>The\u00a0<code>phpinfo()<\/code>\u00a0function shows a great deal of information about the current PHP installation:<\/p>\n<pre>&lt;?php \r\n\tphpinfo(); \r\n?&gt; \r\n<\/pre>\n<p>Now point your web browser to\u00a0<code>http:\/\/tecmint\/test.php<\/code>\u00a0and check the presence of the installed modules and additional software:<\/p>\n<p>Congratulations! You now have a working installation of a\u00a0<strong>LEMP<\/strong>\u00a0stack. If something did not go as expected, feel free to contact us using the form below. Questions and suggestions are also welcome.<\/p>\n<p><a href=\"https:\/\/www.tecmint.com\/install-nginx-mariadb-php-rhel-centos-fedora\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this article we will explain how to install a\u00a0LEMP\u00a0stack (Linux,\u00a0Nginx,\u00a0MariaDB,\u00a0PHP) along with\u00a0PHP-FPM\u00a0on\u00a0RHEL\/CentOS 7\/6\u00a0and\u00a0Fedora 26-29\u00a0servers using\u00a0yum\u00a0and\u00a0dnf\u00a0package manager. During the process we will install and enable\u00a0Epel,\u00a0Remi,\u00a0Nginx\u00a0and\u00a0MariaDB\u00a0repositories in order to be able to install the latest versions of these packages. Read Also:\u00a0Install Apache, MySQL 8 or MariaDB 10 and PHP 7 on CentOS 7 Step 1: Installing &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/04\/06\/how-to-install-nginx-1-15-mariadb-10-and-php-7-on-centos-7\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;How to Install Nginx 1.15, MariaDB 10 and PHP 7 on CentOS 7&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-13835","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/13835","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=13835"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/13835\/revisions"}],"predecessor-version":[{"id":13836,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/13835\/revisions\/13836"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=13835"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=13835"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=13835"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}