Instal·lar PHPMyadmin a ubuntu

Install PhpMyAdmin, Apache2 And MySQL On Ubuntu 18.04 LTS Server

I have recently been testing Ubuntu 18.04 LTS installed on my VMware Workstation as a guest machine… In this test I learn how to install phpMyAdmin.

phpMyAdmin is a web-based tool that allows users to easily manage MySQL or MariaDB databases. If you’re not comfortable managing databases via Linux command line , you may want to use phpMyAdmin web interface to manage your databases instead.

phpMyAdmin relies on the LAMP stack to function. LAMP is a combination of open source software that enable dynamic websites and applications to function. So before getting phpMyAdmin to function, lets get LAMP installed.

This brief tutorial shows students and new users how to install phpMyAdmin with Apache2, MySQL and PHP support on Ubuntu 18.04 LTS. This post should be short and easy to follow.

To get started, continue with the steps below:

Step 1: Install MySQL Database Server

Run the commands below to install MySQL database server

sudo apt update
sudo apt install mysql-server mysql-client

During the installation, you’ll be prompted to create and confirm MySQL root password.. please do.

Step 2: Install Apache2 HTTP Server

Next, run the commands below to install Apache2 HTTP Web Server

sudo apt install apache2

Step 3: Configure Apache2

Now run the commands below to configure Apache2 basic settings. These are the basics.. and more advanced configurations can be done later.

First, confirm that your Ubuntu server configuration has Apache2 DirectoryIndex directives for php defined. To run PHP based apps, Apache2 must have index.php as a directory index in its dir.conf file.

sudo nano /etc/apache2/mods-enabled/dir.conf

Make sure index.php is defined as a DirectoryIndex in the dir.conf file…

<IfModule mod_dir.c>
DirectoryIndex index.html index.php index.xhtml index.htm

Next, configure your domain or server name for your site… Open Apache2 default site config file by running the commands below.

sudo nano /etc/apache2/sites-enabled/000-default.conf

Then add the ServerName and ServerAlias to match your domain name… and save the file.

 <VirtualHost *:80>
     DocumentRoot /var/www/html/

     ErrorLog ${APACHE_LOG_DIR}/error.log
     CustomLog ${APACHE_LOG_DIR}/access.log combined

After that restart Apache2.

sudo systemctl restart apache2.service

Step 4: Install PHP And Related Modules

Run the commands below to install PHP and related PHP modules.

sudo apt-get install php php-cgi libapache2-mod-php php-common php-pear php-mbstring

Step 5: Configure Apache2 To Use PHP

After install PHP and other related scripts, run the commands below to enable Apache2 to use PHP.

sudo a2enconf php7.2-cgi

Reload Apache2

sudo systemctl reload apache2.service

Step 6: Install PhpMyAdmin

Now that Apache2 and PHP are installed the final step is to install phpMyAdmin and configure. To do that, run the commands below

sudo apt-get install phpmyadmin php-gettext

When prompted to choose the webserver, selecat apache2 and continue.

+------------------------+ Configuring phpmyadmin +-------------------------+
 | Please choose the web server that should be automatically configured to   |
 | run phpMyAdmin.                                                           |
 |                                                                           |
 | Web server to reconfigure automatically:                                  |
 |                                                                           |
 |    [*] apache2                                                            |
 |    [ ] lighttpd                                                           |
 |                                                                           |
 |                                                                           |
 |                                 <ok>                                      |
 |                                                                           |

When prompted again to allow debconfig-common to install a database and configure select No.

 +------------------------+ Configuring phpmyadmin +-------------------------+
 |                                                                           |
 | The phpmyadmin package must have a database installed and configured      |
 | before it can be used.  This can be optionally handled with               |
 | dbconfig-common.                                                          |
 |                                                                           |
 | If you are an advanced database administrator and know that you want to   |
 | perform this configuration manually, or if your database has already      |
 | been installed and configured, you should refuse this option.  Details    |
 | on what needs to be done should most likely be provided in                |
 | /usr/share/doc/phpmyadmin.                                                |
 |                                                                           |
 | Otherwise, you should probably choose this option.                        |
 |                                                                           |
 | Configure database for phpmyadmin with dbconfig-common?                   |
 |                                                                           |
 |                  <Yes>                   <No>                             |
 |                                                                           |

After installing, run the commands below to logon to the database server to enable phpMyAdmin root logon.

Now, open your web browser and login to the server hostname or IP address followed by phpmyadmin


phpmyadmin logon page on ubuntu

Logon with MySQL root account you created earlier…

That’s it!

Extret d’aquesta pàgina

Install phpMyAdmin, Apache2 and MySQL on Ubuntu 18.04 LTS Server

Resetejar contrasenya MYSQL


Reset by using mysql_secure_installation

The simplest approach to reset MySQL database root password is to execute mysql_secure_installationprogram and when prompted entering your new root MySQL password:

$ sudo mysql_secure_installation
Please set the password for root here.

New password: 
Re-enter new password:

Reset by using skip-grant-tables

If from some reason the above method fails follow the step below to use --skip-grant-tables to reset MySQL root password.

Let’s start by stopping the currently running MySQL database:

$ sudo service mysql stop

Next, create a /var/run/mysqld directory to be used by MySQL process to store and access socket file:

$ sudo mkdir -p /var/run/mysqld
$ sudo chown mysql:mysql /var/run/mysqld

Once ready manually start MySQL with the following linux command and options:

$ sudo /usr/sbin/mysqld --skip-grant-tables --skip-networking &
$ [1] 2708

Confirm that the process is running as expected:

$ jobs
[1]+  Running     sudo /usr/sbin/mysqld --skip-grant-tables --skip-networking &

At this stage we are able to access MySQL database without password:

$ mysql -u root
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.20-1ubuntu1 (Ubuntu)

Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.


Using the MySQL session first flush privileges:

Query OK, 0 rows affected (0.00 sec)

Next, reset root password. The following commands will reset MySQL root password to

mysql> USE mysql; 
Database changed
mysql> UPDATE user SET authentication_string=PASSWORD("") WHERE User='root';
Query OK, 0 rows affected, 1 warning (0.00 sec)
Rows matched: 1  Changed: 0  Warnings: 1

mysql> UPDATE user SET plugin="mysql_native_password" WHERE User='root';
Query OK, 0 rows affected (0.00 sec)
Rows matched: 1  Changed: 0  Warnings: 0

Quit MySQL session:

mysql> quit                                                                                                                                                                                    

Gracefully terminate current mysqld process:

$ sudo pkill mysqld                                                                                                                                                        
linuxconfig@ubuntu:~$ jobs                                                                                                                                                                     
[1]+  Done       sudo /usr/sbin/mysqld --skip-grant-tables --skip-networking

Lastly, start MYSQL database:

$ sudo service mysql start

If all went well you should now be able to login to your MySQL database with a root password:

$ mysql -u root                                                                                                                                 
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.20-1ubuntu1 (Ubuntu)

Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.


Muntar un USB a Linux

Detecting USB hard drive

After you plug in your USB device to your USB port, Linux system adds a new block device into /dev/ directory. At this stage, you are not able to use this device as the USB filesystem needs to be mouted before you can retrieve or store any data. To find out what name your block device file have you can run fdisk -l command.

NOTE:fdisk command required administrative privileges to access the required information, thus from this reason the commands needs to be executed as a root user or with sudo prefix:

# fdisk -l 
$ sudo fdisk -l

Upon executing the above command you will get an output similar to the one below:

Disk /dev/sdc: 7.4 GiB, 7948206080 bytes, 15523840 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x00000000

Device     Boot Start      End  Sectors  Size Id Type
/dev/sdc1  *     8192 15523839 15515648  7.4G  b W95 FAT32

The above output will most likely list multiple disks attached to your system. Look for your USB drive based on its size and filesystem. Once ready, take a note of the block device name of the partition you intent to mount. For example in our case that will be /dev/sdc1 with FAT32 filesystem.

Create mount point

Before we are able to use mount command to mount the USB partition, we need to create a mount point. Mount point can be any new or existing directory within your host filesystem. Use mkdircommand to create a new mount point directory where you want to mount your USB device:

# mkdir /media/usb-drive

Mount USB Drive

At this stage we are ready to mount our USB’s partition /dev/sdc1 into /media/usb-drive mount point:

# mount /dev/sdc1 /media/usb-drive/

To check whether your USB drive has been mounted correctly execute mount command again without any arguments and use grep to search for USB block device name:

# mount | grep sdc1
/dev/sdc1 on /media/usb-drive type vfat (rw,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=utf8,shortname=mixed,errors=remount-ro

If no output has been produced by the above mount command your USB partition is not mounted. Alternatively, double-check whether you have used a correct block device name in the above command.