Install MySQL 8 & phpMyAdmin on CentOS 8
This post would provide a tutorial to install MySQL 8 and phpMyAdmin 5 on CentOS 8. Please note that you have to install the PHP and Apache before starting the installation for phpMyAdmin, you could also refer to this post I wrote before to finish the installation for PHP and Apache.
Install MySQL 8.
We could install MySQL directly using the version on AppStream of CentOS8.
1 |
$ sudo dnf install mysql-server |
Start MySQL and set it start automatically.
1 2 |
$ sudo systemctl start mysqld $ sudo systemctl enable mysqld |
Find out the default passwords of MySQL.
We had already started MySQL in Step 2, so MySQL should produce a temporary passwords. Therefore, you could find out the randomly temporary passwords in the log file of MySQL.
1 2 |
$ sudo grep "temporary password" /var/log/mysqld.log [Note] A temporary password is generated for root@localhost: xxxxxxukj5+t783 |
Change passwords of root.
If you want to change passwords and the security level as well, you could choose this program to help you.
1 |
$ mysql_secure_installation |
Once if you just want to change root’s passwords, you could use these command under below.
In the CLI mode of MySQL, you could use command
exit;
to terminate.
1 2 3 |
$ mysql -u root -p mysql> FLUSH PRIVILEGES; mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'YOUR NEW PASSWORDS'; |
Finally, you could re-login MySQL to check root’s new passwords was changed correctly.
1 |
$ mysql -u root -p |
Download and install phpMyAdmin.
You’d better download 4.9 or higher version of phpMyAdmin that can support MySQL 8. Then decompress zip file and put the folder you unpacked to the path you want. In this post, I assumed that the root path of website is located at “/var/www”.
If you’re not sure which version of phpMyAdmin, then you could refer to this page created by phpMyAdmin official, and there is some recommendation for you.
Before you start Step 1, there is another thing you have to do is to install
weget
andzip
. And theunzip
will be added into related packages whenzip
is installed.
1 2 3 |
[andy@www ~]$ wget https://files.phpmyadmin.net/phpMyAdmin/5.0.1/phpMyAdmin-5.0.1-all-languages.zip [andy@www ~]$ unzip phpMyAdmin-5.0.1-all-languages.zip [andy@www ~]$ cp phpMyAdmin-5.0.1-all-languages /var/www/phpMyAdmin |
Edit config of Apache.
Let’s edit the configuration file.
1 |
[andy@www ~]$ sudo vim /etc/httpd/conf/httpd.conf |
However, there are two different use cases that will affect the way for your modification.
- Your phpMyAdmin is attached to an exists website which is an independent domain.
All you need to do is copy the settings under below and paste them into the block of your website, and that means before the tag</VirtualHost>
of your website’s settings. Through these settings, you could visit phpMyAdmin by the URL like this “http://YourDomain/AliasNameForPHPMyadmin”.
123456789101112131415161718Alias /AliasNameForPHPMyadmin "/var/www/phpmyadmin/"<Directory /var/www/phpmyadmin>Options FollowSymLinks MultiViewsAllowOverride AllOrder Allow,DenyAllow from all</Directory><Directory /var/www/phpmyadmin/libraries>Options FollowSymLinks MultiViewsOrder Deny,AllowDeny from AllAllow from None</Directory><Directory /var/www/phpmyadmin/templates>Order Deny,AllowDeny from AllAllow from None</Directory> - Your phpMyAdmin is an independent website and owns its domain name.
This way would need you to copy the whole block of settings to your configuration file. Of course, you could visit phpMyAdmin through the domain name that you setup.
1234567891011<VirtualHost *:80>DocumentRoot "/var/www/phpmyadmin"ServerName YourDomainNameForPHPmyAdminServerAlias YourDomainNameForPHPmyAdmin<Directory /var/www/phpmyadmin/>Options FollowSymLinksAllowOverride AllOrder allow,denyAllow from all</Directory></VirtualHost>
Permission setting.
You have to permit these folders to be able to access by Apache.
1 2 |
$ sudo chown -R apache:apache /var/www/phpmyadmin/ $ sudo chcon -R --type=httpd_sys_rw_content_t /var/www/phpmyadmin/ |
Finally, it’s not doubtable that you have to restart Apache to make these adjustments be activated.
1 |
$ sudo systemctl restart httpd |
Pingback:CentOS 8 安裝與設定 MySQL 8, phpMyAdmin 4.9 - BrilliantCode.net