Linux phpMyAdmin Installation And Configuration

Install and Config phpMyAdmin in Linux

phpMyAdmin is a popular web-based tool for managing MySQL and MariaDB databases. This tutorial will guide you through the process of installing and configuring phpMyAdmin on a Linux system using package managers like apt (for Debian/Ubuntu-based distributions) and yum or dnf (for CentOS/RHEL-based distributions).

  • Install LAMP/LEMP Stack

Before installing phpMyAdmin, you need to have a web server, PHP, and MySQL/MariaDB installed. This is often referred to as a LAMP (Linux, Apache, MySQL, PHP) or LEMP (Linux, Nginx, MySQL, PHP) stack. If you don't have this set up yet, follow a tutorial for installing LAMP or LEMP stack on your Linux distribution.

  • Install phpMyAdmin

Once you have the LAMP or LEMP stack installed, you can proceed with installing phpMyAdmin:

  • For Debian/Ubuntu-based distributions, use:
sudo apt update sudo apt install phpmyadmin 
  • For CentOS/RHEL-based distributions, you need to enable the EPEL repository first:
sudo yum install epel-release 

or

sudo dnf install epel-release 

Then, install phpMyAdmin:

sudo yum install phpmyadmin 

or

sudo dnf install phpmyadmin 
  • Configure Web Server for phpMyAdmin
  • For Apache (LAMP stack):

Debian/Ubuntu-based distributions automatically configure Apache for phpMyAdmin. For CentOS/RHEL-based distributions, add the following configuration to your Apache configuration file (usually located at /etc/httpd/conf.d/phpMyAdmin.conf or /etc/httpd/conf/httpd.conf):

Alias /phpmyadmin /usr/share/phpmyadmin <Directory /usr/share/phpmyadmin> Options FollowSymLinks DirectoryIndex index.php <IfModule mod_authz_core.c> # Apache 2.4 <RequireAny> Require ip 127.0.0.1 Require ip ::1 </RequireAny> </IfModule> <IfModule !mod_authz_core.c> # Apache 2.2 Order Deny,Allow Deny from All Allow from 127.0.0.1 Allow from ::1 </IfModule> </Directory> 

After adding the configuration, restart the Apache service:

sudo systemctl restart apache2 

(Debian/Ubuntu) or

sudo systemctl restart httpd 

(CentOS/RHEL)

  • For Nginx (LEMP stack):

Create a new Nginx configuration file for phpMyAdmin (e.g., /etc/nginx/conf.d/phpmyadmin.conf), and add the following configuration:

server { listen 80; server_name phpmyadmin.example.com; root /usr/share/phpmyadmin; location / { index index.php; } location ~ \.php$ { include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_pass unix:/var/run/php/php7.4-fpm.sock; # Modify the PHP version as per your installed version } } 

Replace phpmyadmin.example.com with your desired domain or subdomain, and update the fastcgi_pass directive with the correct PHP-FPM socket path for your installed PHP version.

Then, restart the Nginx service:

sudo systemctl restart nginx 

Examples

  1. Installing phpMyAdmin on Ubuntu/Linux: On Ubuntu, you can install phpMyAdmin using the following commands:

    sudo apt-get update sudo apt-get install phpmyadmin 

    During installation, you will be prompted to choose a web server (e.g., Apache or Nginx) and configure phpMyAdmin.

  2. Step-by-step phpMyAdmin installation on CentOS: For CentOS, you can install phpMyAdmin using yum:

    sudo yum install epel-release sudo yum install phpmyadmin 

    Follow the prompts during installation to configure phpMyAdmin.

  3. phpMyAdmin installation and configuration in Debian: Debian uses apt for package management. Install phpMyAdmin with:

    sudo apt-get update sudo apt-get install phpmyadmin 

    Configure phpMyAdmin during the installation process.

  4. Installing and securing phpMyAdmin on Red Hat Linux: On Red Hat-based systems, you can use yum for installation:

    sudo yum install epel-release sudo yum install phpmyadmin 

    Follow the prompts during installation to configure phpMyAdmin.

    Additionally, secure the phpMyAdmin installation by creating a symbolic link for the phpMyAdmin configuration file:

    sudo ln -s /etc/phpMyAdmin/apache.conf /etc/httpd/conf.d/phpMyAdmin.conf sudo service httpd restart 
  5. Configuring phpMyAdmin for MySQL/MariaDB in Linux: After installation, configure phpMyAdmin to work with your MySQL or MariaDB server. Edit the configuration file to include the database server details:

    sudo nano /etc/phpMyAdmin/config.inc.php 

    Update the $cfg['Servers'][$i]['host'] and other relevant settings.

    Additionally, consider securing phpMyAdmin by restricting access:

    sudo nano /etc/httpd/conf.d/phpMyAdmin.conf 

    Add or update the <Directory> block to include specific IP addresses or enable authentication.

    Finally, restart your web server to apply the changes:

    sudo service apache2 restart # For Apache sudo service nginx restart # For Nginx 

More Tags

word-count python-docx r-markdown class-extensions dllimport php-ini angular-chart palindrome llvm transform

More Programming Guides

Other Guides

More Programming Examples