Tag Archives: MySQL

How To Install phpMyAdmin on CentOS 7

In this tutorial, we will go through the steps to installing and configuring phpMyAdmin in CentOS 7.

All commands – without sudo

yum update -y 
yum install epel-release -y 
yum install phpmyadmin -y 

All commands – with sudo

sudo yum update -y 
sudo yum install epel-release -y
sudo yum install phpmyadmin -y

Introduction

phpMyAdmin is an open source tool for managing and interacting with MySQL databases. phpMyAdmin uses a web-based management interface which allows users to interact with databases through web browser. It allows us to manage database users and privileges, import and export databases, execute database queries and more.

Prerequisites

Step 1. Update your system

Start by updating the system. You can use the below command.

yum update -y 

Step2. Add Repo

Since phpMyAdmin is not available in CentOS 7’s default repository, we need to add the Extra Packages for Enterprise Linux (EPEL) repo by executing the below command.

yum install epel-release -y 

Step 3. Install phpMyAdmin

After adding the repo, you can install phpMyAdmin using the yum package by typing the below command:

yum install phpmyadmin -y 

For phpMyAdmin to work properly, we need to make some changes to the configuration file. Open the configuration file using your text editor.

vi /etc/httpd/conf.d/phpMyAdmin.conf

By default the configuration is set up to access the connection only from localhost. In order to work remotely, you will need to specify the addresses in the configuration file.

Add your remote IP to the respective lines on the configuration as shown below.

Require ip your_ip_address
Allow from your_ip_address

Restart Apache to apply the modifications.

systemctl restart httpd

Now you can access phpMyAdmin using the URL below.

http://server_domian_or_ip/phpmyadmin
How To Install phpMyAdmin in CentOS 7

How To Install phpMyAdmin in CentOS 7

To login, use a valid username and password of a MariaDB user. You can the root user and MariaDB administrative pass to login by default. You can then access the administrative interface:

How To Install phpMyAdmin in CentOS 7

How To Install phpMyAdmin in CentOS 7

Conclusion

You’ve successfully installed phpMyAdmin on your CentOS 7 machine. Now you can manage your databases through a web interface. You can manage databases, users, and tables, perform various other MySQL queries and operations.

How to Install NGINX, MySQL, PHP v7 (LEMP) on CentOS 7

In this guide we go through the steps for building the LEMP stack on CentOS 7.

All Commands – without sudo

yum update -y
yum install epel-release -y 
yum install nginx -y
systemctl start nginx
systemctl enable nginx
firewall-cmd --permanent --add-service=http
firewall-cmd --permanent --add-service=https
firewall-cmd --reload
yum install mariadb-server mariadb -y
systemctl start mariadb
systemctl enable mariadb 
mysql_secure_installation
yum install yum-utils http://rpms.remirepo.net/enterprise/remi-release-7.rpm -y
yum-config-manager –enable remi-php73 
yum install php php-mysql php-fpm -y 
sed -i '12s#.*#listen = /run/php-fpm/www.sock#' /etc/php-fpm.d/www.conf 
sed -i '31s#.*#listen.owner = nginx#' /etc/php-fpm.d/www.conf
sed -i '32s#.*#listen.group = nginx#' /etc/php-fpm.d/www.conf
sed -i '39s#.*#user = nginx#' /etc/php-fpm.d/www.conf
sed -i '41s#.*#group = nginx#' /etc/php-fpm.d/www.conf 
chown -R root:nginx /var/lib/php 
systemctl start php-fpm 
systemctl enable php-fpm 
echo -e "\nserver {\n\tlisten 80;\n\tserver_name your_server_ip;\n\n\troot /usr/share/nginx/html;\n\tindex index.php index.html index.htm;\n\n\tlocation / {\n\t\ttry_files \$uri \$uri/ =404;\n\t}\n\terror_page 404 /404.html;\n\terror_page 500 502 503 504 /50x.html;\n\tlocation = /50x.html {\n\t\troot /usr/share/nginx/html;\n\t}\n\n\tlocation ~ \.php$ {\n\\t\ttry_files \$uri =404;\n\t\tfastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;\n\t\tfastcgi_index index.php;\n\t\tfastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;\n\t\t include fastcgi_params;\n\t}\n}" | tee /etc/nginx/conf.d/default.conf
systemctl restart nginx

All Commands  – with sudo

sudo yum update -y 
sudo yum install epel-release -y  
sudo yum install nginx -y 
sudo systemctl start nginx 
sudo systemctl enable nginx 
sudo firewall-cmd --permanent --add-service=http 
sudo firewall-cmd --permanent --add-service=https 
sudo firewall-cmd --reload 
sudo yum install mariadb-server mariadb -y 
sudo systemctl start mariadb 
sudo systemctl enable mariadb  
sudo mysql_secure_installation 
sudo yum install yum-utils http://rpms.remirepo.net/enterprise/remi-release-7.rpm -y 
sudo yum-config-manager –enable remi-php73  
sudo yum install php php-mysql php-fpm -y 
sudo sed -i '12s#.*#listen = /run/php-fpm/www.sock#' /etc/php-fpm.d/www.conf 
sudo sed -i '31s#.*#listen.owner = nginx#' /etc/php-fpm.d/www.conf
sudo sed -i '32s#.*#listen.group = nginx#' /etc/php-fpm.d/www.conf
sudo sed -i '39s#.*#user = nginx#' /etc/php-fpm.d/www.conf
sudo sed -i '41s#.*#group = nginx#' /etc/php-fpm.d/www.conf
sudo chown -R root:nginx /var/lib/php  
sudo systemctl start php-fpm  
sudo systemctl enable php-fpm  
echo -e "\nserver {\n\tlisten 80;\n\tserver_name your_server_ip;\n\n\troot /usr/share/nginx/html;\n\tindex index.php index.html index.htm;\n\n\tlocation / {\n\t\ttry_files \$uri \$uri/ =404;\n\t}\n\terror_page 404 /404.html;\n\terror_page 500 502 503 504 /50x.html;\n\tlocation = /50x.html {\n\t\troot /usr/share/nginx/html;\n\t}\n\n\tlocation ~ \.php$ {\n\\t\ttry_files \$uri =404;\n\t\tfastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;\n\t\tfastcgi_index index.php;\n\t\tfastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;\n\t\t include fastcgi_params;\n\t}\n}" | sudo tee /etc/nginx/conf.d/default.conf
sudo systemctl restart nginx

LEMP stack is a group of open source software that is installed on a server so that we can host dynamic web applications and sites. LEMP stack is an another variation of the LAMP stack. LEMP is an acronym which consists of Linux as the operating system, NGINX as the web server, MySQL/MariaDB as the relational database management system and PHP as the server-side scripting language. 

Prerequisites

  • A CentOS 7 VPS
  • Root access to the server
  • An SSH client (PuTTY for example)

Step 1: Update Your System

Log in as a sudo user and then update your system using the following  command,

yum update -y

Step 2: Installing NGINX

Nginx is not available on the default CentOS 7 repositories, so add the Extra Packages for Enterprise Linux (EPEL) repository by executing the command below.

yum install epel-release -y

Now that the (EPEL) repository repository is installed on your server, let’s install the NGINX Web Server using the command below.

yum install nginx -y

After the installation, start and enable NGINX.

systemctl start nginx
systemctl enable nginx

Configure the system firewall for NGINX to allow 80 and 443 inbound to the server.

firewall-cmd --permanent --add-service=http

firewall-cmd --permanent --add-service=https

firewall-cmd --reload

To verify if NGINX is running, visit your IP address via the browser.

http://server_domain_name_or_IP/

You should see the default NGINX page as shown below.

Step 3: Installing MariaDB

MariaDB – a drop in replacement of MySQL, is the default database management system in CentOS 7. It is a community-developed fork of the MySQL relational database management system.

MariaDB comes with default CentOS repositories, thus run the following command to install it.

yum install mariadb-server mariadb -y

After the installation is complete, start and enable the service.

systemctl start maridb

systemctl enable mariadb

Run the following command to prevent all unauthorized accesses and remove some dangerous defaults in your database configuration.

mysql_secure_installation

You will be prompted with an option to change the MariaDB root password, remove anonymous user accounts, disable root logins outside of localhost, remove test databases and reload privileges. It is recommended that you answer ‘yes’ to these options to secure the database server.

Step 4: Installing PHP

PHP is a widely used scripting language suited for web development. By default PHP 5.4 is available in the CentOS 7 Yum repositories. It is now outdated and no longer supported. We recommend that you install the latest stable version of PHP 7.x as it has many improvements and new features.

To install the latest PHP version we need to add REMI repository. Lets start by installing the package “yum-utils” for configuring yum repositories and install the REMI repository.

yum install yum-utils http://rpms.remirepo.net/enterprise/remi-release-7.rpm -y

Configure the repository for installing PHP 7.3 (or the latest stable version) using the following command. If there is a later version then simply modify the command by changing the version numbers in the command to match the release you wish to install.

yum-config-manager --enable remi-php73

We can now install PHP 7.3 along with its common dependencies with the command below,

yum install php php-mysql php-fpm -y 

Check the PHP version with the command below,

php -v

The output should look similar to what show below,

PHP 7.3.2 (cli) (built: Feb 5 2019 13:10:03) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.2, Copyright (c) 1998-2018 Zend Technologies

By default PHP-FPM is configured to user “apache” on port 9000. W’ll need to change the user to nginx.

To do so edit the PHP-FPM configuration file at “/etc/php-fpm.d/www.conf” to what’s shown below.

...
user = nginx
...
group = nginx
...
listen = /run/php-fpm/www.sock
...
listen.owner = nginx
listen.group = nginx

Save the file and change the ownership of the directory “/var/lib/php” from “apache” to “nginx”.

chown -R root:nginx /var/lib/php

Start and enable PHP-FPM.

systemctl start php-fpm
systemctl enable php-fpm

Step 5: Configuring Nginx to Process PHP Pages

Create a new NGINX configuration file with the following command.

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

Paste the syntax below on to the newly created configuration file.

server {
    listen   80;
    server_name  your_server_ip;

    # note that these lines are originally from the "location /" block
    root   /usr/share/nginx/html;
    index index.php index.html index.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;
    }
}

Note: Replace “your_server_ip” with your actual server IP.

Save the file and restart NGINX for the changes to take effect.

systemctl restart nginx

Conclusion

Now that you have successfully installed LEMP stack, you are now ready to host any type of dynamic website/software applications. 

How to Install MariaDB/MySQL on CentOS 7

In this guide we’ll go through the steps for installing the latest version of MariaDB on CentOS 7.

All Commands – without sudo

yum update -y
echo -e "[mariadb]\nname=MariaDB Repository\nbaseurl=http://yum.mariadb.org/10.3/centos7-amd64\ngpgcheck=1\ngpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB" | tee /etc/yum.repos.d/MariaDB.repo
yum install mariadb-server mariadb-client -y
systemctl start mariadb 
systemctl enable mariadb
mysql_secure_installation

All Commands – with sudo

sudo yum update -y
sudo yum install mariadb-server mariadb-client -y
echo -e "[mariadb]\nname=MariaDB Repository\nbaseurl=http://yum.mariadb.org/10.3/centos7-amd64\ngpgcheck=1\ngpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB" | sudo tee /etc/yum.repos.d/MariaDB.repo 
sudo systemctl start mariadb 
sudo systemctl enable mariadb
sudo mysql_secure_installation

 

MariaDB is the default database management system in CentOS 7 and is a drop-in replacement for MySQL. It is an opensource relational database that uses the Structured Query Language (SQL) to manage its data. 

Prerequisites

  • A CentOS 7 VPS
  • Sudo access

Update Your System

Log in as a sudo user and then update your system.

yum update -y

Install MariaDB

At the time of writing this article, the latest version of MariaDB is version 10.3. If you want a different version of MariaDB, go to the official MariaDB repositories page and generate a repository file for the specific MariaDB version you require.

To enable the MariaDB repository, create a repository file named MariaDB.repo and add the following content in /etc/yum.repos.d/MariaDB.repo

[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.3/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1

Install the MariaDB server and client packages using yum.

yum install mariadb-server mariadb-client -y

Now that MariaDB has installed successfully, run the following command to start and enable the service.

systemctl start mariadb

systemctl enable mariadb

To prevent unauthorized access to your database and remove some dangerous defaults run the following command.

mysql_secure_installation

You will be prompted with an option to change the MariaDB root password, remove anonymous user accounts, disable root logins outside of localhost, remove test databases and reload privileges. It is recommended that you answer ‘yes’ to these options to secure the database server.

Verify the Installation

Run the following to test to get info about the installation of MariaDB.

mysqladmin -u root -p version

You’ll see an output similar to what shown below,

mysqladmin Ver 9.1 Distrib 10.3.13-MariaDB, for Linux on x86_64
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Server version 10.3.13-MariaDB
Protocol version 10
Connection Localhost via UNIX socket
UNIX socket /var/lib/mysql/mysql.sock
Uptime: 35 sec

Threads: 7 Questions: 16 Slow queries: 0 Opens: 18 Flush tables: 1 Open tables: 12 Queries per second avg: 0.457

Conclusion

We’ve successfully installed and secured MariaDB on your CentOS 7 server. If you have any questions, please feel free contact our technical support.

How to Install LAMP (Linux, Apache, MySQL, PHP) on CentOS 7

In this guide we will walk through the steps for installing and configuring LAMP stack on a CentOS 7 VPS.

All commands – without sudo

yum update
yum install httpd -y
systemctl start httpd
systemctl enable httpd
yum install mariadb-server mariadb -y
systemctl start mariadb
systemctl enable mariadb
systemctl mysql_secure_installation
yum install epel-release yum-utils -y
yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm -y
yum-config-manager --enable remi-php73
yum install php php-mysql -y
systemctl restart httpd

All commands – with sudo

sudo yum update -y
sudo yum install httpd -y
sudo systemctl start httpd
sudo systemctl enable httpd
sudo yum install mariadb-server mariadb -y
sudo systemctl start mariadb
sudo systemctl enable mariadb
sudo systemctl mysql_secure_installation
sudo yum install epel-release yum-utils -y
sudo yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm -y
sudo yum-config-manager --enable remi-php73
sudo yum install php php-mysql -y
sudo systemctl restart httpd

LAMP is a set of open source software packages that is used to create websites and web applications. LAMP is an acronym. It consists of Linux as the operating system, Apache as the Web server, MySQL/MariaDB as the relational database management system and PHP as the server-side scripting language. In this document, we will go through the steps necessary for installing the LAMP stack on a CentOS 7 server.

All you require for these operations is a VPS with CentOS 7 installed on it and root/root privileged user access to the server.

Prerequisites

  • A CentOS 7 VPS
  • Root access to the server
  • An SSH client (PuTTY for example)

Step 1: Update your system

Before we start, it is always good to update the system software on the server. This can be done by executing the command below.

 sudo yum update -y

Step 2: Install Apache

The installation of Apache is a simple step and this can be done using the Yum Package Manager.

sudo yum install httpd -y

Start and enable the Apache service with the following command.

sudo systemctl start httpd
sudo systemctl enable httpd

Check whether Apache is running by calling your IP/hostname in the browser. If Apache is running the default CentOS 7 Apache web page will be displayed.

LAMP Installation on CentOS 7 Server

Apache Test Page on CentOS 7 Server

Step 3: Install MariaDB Database

MariaDB is a drop-in replacement for MySQL. It is a reliable SQL server that comes with a rich set of enhancements and features. For dynamic websites, it is always necessary to store data. We can install MariaDB together with additional packages that are required by running the commands below:

sudo yum install mariadb-server mariadb -y

Now that the MariaDB has installed successfully, run the command below to start and enable the service.

sudo systemctl start mariadb
sudo systemctl enable mariadb

To prevent unauthorized access to your database and remove some dangerous defaults run the following command.

sudo mysql_secure_installation

You will be prompted with an option to change the MariaDB root password, remove anonymous user accounts, disable root logins outside of localhost, remove test databases and reload privileges. It is recommended that you answer ‘yes’ to these options to secure the database server.

Step 4: Install PHP

PHP is a widely used scripting language suited for web development. It works with Apache to display the dynamic content for your website. By default, PHP 5.4 is available in the CentOS 7 Yum repositories. We recommend that you install the latest stable version of PHP 7.x as it has many improvements and new features.

To install the latest PHP version we need to add EPEL and REMI repositories. Let’s start by installing the package “yum-utils” for configuring yum repositories and enabling the EPEL repository.

yum install epel-release yum-utils -y

Now, download and install the REMI repository.

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

Configure the repository for installing PHP 7.3 (or the latest stable version) using the following command. If there is a later version then simply modify the command by changing the version numbers in the command to match the release you wish to install.

yum-config-manager --enable remi-php73

We can now install PHP 7.3 along with its SQL dependency using the command below.

yum install php php-mysql -y

After installing PHP, restart the Apache service.

sudo systemctl restart httpd

Conclusion

That’s it. You’ve successfully installed the LAMP platform on your CentOS 7 system which can now run dynamic website and software applications. Depending on your web hosting needs, you might also need to install additional Apache modules and PHP extensions.

We highly recommend checking out OpenLiteSpeed web server as an open-source drop-in replacement for Apache. There can be significant speed increases by running OpenLiteSpeed. We have an article on how to install OpenLiteSpeed to help guide you.