This document serves as a comprehensive guide to deploying a MySQL database service on the Oracle Cloud platform. The deployment includes setting up an interactive web interface using Apache/HTTPd and PHP designed to facilitate essential database operations, such as INSERT, DELETE, UPDATE, and SELECT.
Sample scripts in this document comes from Order Management Portal.
You can interact with the database using the following link: http://150.136.153.174/order-management-portal/index.html.
-
An Oracle Cloud Infrastructure Free Tier account or similar;
-
A MacOS, Linux, or Windows computer with
ssh
support installed.
The operating system (image) deployed in the Oracle Cloud environment is CentOS-7-2022.04.26-0.
Using hostnamectl
command on CentOS:
Static hostname: oraclevm4
Icon name: computer-vm
Chassis: vm
...
Virtualization: kvm
Operating System: CentOS Linux 7 (Core)
CPE OS Name: cpe:/o:centos:centos:7
Kernel: Linux 3.10.0-1160.62.1.el7.x86_64
Architecture: x86-64
-
Install Apache/HTTPd service:
$ yum install httpd
-
Start web service:
$ sudo systemctl start httpd
-
Check internet connections:
$ netstat -lntp
/var/www/html
is the typical/default location for web server files in Linux distributions.
MySQL is not pre-installed in the default CentOS 7 repositories.
-
Enable the MySQL 5.7 repository:
$ sudo yum localinstall https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
If
"No package mysql-community-server available"
pops up, try:$ sudo rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
-
Install MySQL 5.7 package with yum:
$ sudo yum install mysql-community-server
-
Start MySQL
$ sudo systemctl start mysqld
-
Locate temporary password
$ sudo grep 'temporary password' /var/log/mysqld.log
2024-01-08T02:43:21.036079Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: %7Fp2N9/bOrT
-
Run the security script and set up new password for root user
$ sudo mysql_secure_installation
Note: You should answer
"y" (yes)
to all questions.
- To login into the MySQL server as the root user:
$ mysql -u root -p
Login as root user:
- Create user:
mysql> CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';
- Grant privileges:
mysql> GRANT ALL PRIVILEGES ON database_name.* TO 'username'@'localhost';
If Authentication plugin 'caching_sha2_password' cannot be loaded
pops up, try:
mysql> ALTER USER 'username'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
Adding the below chunk into vi /etc/my.cnf
:
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
[mysqld]
collation-server = utf8_unicode_ci
character-set-server = utf8
default_authentication_plugin = mysql_native_password
-
Configure the Oracle Linux package repos to use PHP 7:
$ sudo yum install -y oracle-php-release-el7
-
Install PHP 7:
$ sudo yum install -y php
-
Restart Apache:
$ sudo systemctl restart httpd
-
Verify installation:
$ php -v
Add a PHP test file:
$ sudo vi /var/www/html/info.php
Input the following text and
wq
:<?php phpinfo(); ?>
Connect to
http://<your-public-ip-address>/info.php
, which will produce a listing of PHP configuration on your instance.
- Install MySQLi using yum:
$ sudo yum install php-mysqli
- Restart Apache:
$ sudo systemctl restart httpd
Add the following lines at the beginning of your PHP script to display errors, which might help identify any issues:
ini_set('display_errors', 1);
error_reporting(E_ALL);
- Install Apache and PHP on an Oracle Linux Instance
- How to solve "Fatal error: Class 'MySQLi' not found"?
leeklee0427
Last Edited on: 01/08/2024
Go to Top