Ensuring Robust Disaster Recovery for PHP Applications on IBM i with MariaDB
In the world of web applications, no system is entirely immune to unexpected disruptions. This is equally true for PHP applications operating on the IBM i platform. Whether it’s due to hardware malfunctions, human errors, or other critical failures, it’s imperative for IT teams to quickly recover lost data and restore the normal functionality of PHP IBM i applications. This article delves into the essential considerations for developing a disaster recovery strategy for PHP applications on IBM i, particularly through the use of database redundancy. Moreover, we will explore why coupling PHP with MariaDB databases presents a compelling choice for IBM i teams. We will also introduce new disaster recovery features from ZendHQ and provide a detailed guide on configuring ZendHQ and MariaDB on IBM i.
Understanding IBM i Disaster Recovery with PHP and MariaDB
Creating a robust disaster recovery plan for IBM i is crucial to minimize downtime and data loss. A well-thought-out plan involves implementing database redundancy, which means keeping backup data in one or more secondary locations. These backups can be stored in databases like MariaDB, PostgreSQL, or others. In the event of a disaster, these backups can be used to recover any lost data effectively.
To build an effective disaster recovery plan, consider the following questions:
- What system components require regular backups?
- Which PHP or other applications are involved, and what environments do they operate in?
- How is your data organized?
- Which database, such as MariaDB, do you use for data storage?
- Who on your team is responsible for specific disaster recovery steps, and are they well-trained?
- Are the necessary licenses for software reinstallations readily available?
The Advantages of Using PHP with MariaDB
PHP and MariaDB together offer many advantages for IBM i teams developing a disaster recovery plan. Both technologies are easy to integrate, feature straightforward syntaxes, and are supported by most web hosting providers. This makes PHP and MariaDB accessible for developers of varying skill levels. Furthermore, MariaDB can handle substantial traffic, aiding in scaling IBM i PHP applications to meet evolving business requirements.
Being open-source, both PHP and MariaDB benefit from extensive community support, eliminating licensing costs and freeing up resources for other uses.
Choosing the Right Database for PHP
While PHP and MariaDB are a powerful combination, the optimal database for your PHP IBM i application may depend on your team’s expertise, available resources, and business objectives. Besides MariaDB, other databases to consider include PostgreSQL and SQLite, among others.
Introducing New ZendHQ Disaster Recovery Features for IBM i
ZendPHP runtimes, combined with the advanced ZendHQ extension, provide impressive performance for IBM i PHP applications. With a recent database expansion, ZendHQ now offers built-in features to help users regain or migrate ZendHQ data, safeguarding it in the event of a database corruption, crash, or other failures.
Previously, ZendHQ relied solely on SQLite, which posed challenges for database redundancy in disaster recovery. The new features allow teams to use MariaDB and PostgreSQL to create backups for ZendHQ. This enables your IBM i team to establish a primary server and one or more replicas. If the primary server fails, a replica can be promoted to regain lost ZendHQ data.
How to Configure ZendHQ and MariaDB on IBM i
IBM i – Access Client Solution (ACS)
IBM i ACS is the recommended method for installing open-source software on an IBM i server and is necessary for configuring ZendHQ and MariaDB. Start by updating to the latest version of IBM i ACS. IBM suggests using the bash shell for SSH connections:
- SSH sessions run the bash shell
- QP2TERM uses the sh shell
- Change the default IBM i shell to bash
Use the following command for setting the PASE shell info:
<br /> CALL QSYS2.SET_PASE_SHELL_INFO('*DEFAULT','/QOpenSys/pkgs/bin/bash')<br />
You can also change the shell using the chsh package:
<br /> $ /QOpenSys/pkgs/bin/chsh -s /QOpenSys/pkgs/bin/bash<br />
Refer to IBM i documentation for troubleshooting bash settings.Installing MariaDB Using ACS or yum Command
Access the command line and use SSH terminal tools like QP2Term, MobaXterm, or PuTTY:
<br /> $ yum list available mariadb*<br /> $ /Qopensys/pkgs/bin/yum install mariadb-10.6 mariadb-10.6-server<br />
Launch IBM i ACS and select "Open Source Package Management." Locate "mariadb-10.6" and "mariadb-10.6-server" options and click "Install."Configuring the MariaDB Server
Create and initialize the MariaDB database. For first-time installations, run the following command:
<br /> $ /QOpenSys/pkgs/bin/mysql_install_db<br />
Modify the MariaDB server configuration file to set the IP binding address and TCP port:
<br /> $ WRKLNK ‘/QOpenSys/etc/mariadb/my.cnf’<br /> [mysqld]<br /> bind-address=0.0.0.0<br /> port=3306<br />
After completing these steps, start the MariaDB server daemon:
<br /> $ cd /QOpenSys/pkgs<br /> $ /QOpenSys/pkgs/bin/mysqld_safe --datadir=/QOpenSys/var/lib/mariadb/data<br />
Use the following command to submit a job:
<br /> $ SBMJOB CMD(CALL PGM(QP2SHELL) PARM('/QOpenSys/pkgs/bin/mysqld_safe' '--datadir=/QOpenSys/var/lib/mariadb/data')) JOB(MariaDB) JOBD(QGPL/QINTER)<br />
The terminal session will be locked when starting the MariaDB mysqld daemon server from an SSH terminal. Use CTRL-C to exit. The MariaDB mysqld daemon JOBS will remain active in SBS QUSRWRK after you exit the SSH session.Verifying MariaDB Processes
To see active MariaDB processes, use the ps utility or WRKACTJOB:
<br /> $ ps ax | grep mariadb<br /> $ WRKACTJOB SBS(QUSRWRK)<br />
Verify the server is listening on port 3306:
<br /> $ *NETSTAT CNN<br />
Setting the Root User Password
After the first use of MariaDB, set the root user password using the mysqladmin tool:
<br /> $ /QOpenSys/pkgs/bin/mysqladmin -u root password MyPassword<br />
Alternatively, use:
<br /> $ /QOpenSys/pkgs/bin/mariadb-secure-installation<br />
If prompted, answer "NO" to enabling unix_socket authentication. On IBM i, this is disabled due to PASE limitations.Configuring Remote Access
By default, MariaDB listens on localhost (127.0.0.1), allowing access only to native IBM i users and apps. To enable remote access, use the mariadb or mysql command:
<br /> $ mariadb -u root –p<br /> $ mysql -u root –p<br /> $ GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'MyPassword' WITH GRANT OPTION;<br />
To stop the MariaDB server daemon:
<br /> $ /QOpenSys/pkgs/bin/mysqladmin --no-defaults --user=root --password=mypassword shutdown<br />
Configuring MariaDB for ZendHQ
Create the MariaDB ZendHQ database and user. Log into MariaDB:
<br /> $ mariadb -u root –p<br />
Create a new database and user:
<br /> MariaDB > CREATE DATABASE zendhq;<br /> MariaDB > CREATE USER 'zendhq'@'localhost' IDENTIFIED BY 'zendhq';<br /> MariaDB > GRANT ALL PRIVILEGES ON zendhq.* TO 'zendhq'@'localhost' IDENTIFIED BY 'YourPassword';<br />
Switching from SQLite to MariaDB
To switch from SQLite to MariaDB for ZendHQ, update the /opt/zend/zendphp/etc/zendhqd.ini file. Comment out SQLite and uncomment MySQL/MariaDB:
“`include = zendhqd_sqlite.ini
include = zendhqd_mysql.ini
<br /> Modify host/port/user/password/socket path:<br />
zendhqd.database.hostname = localhost
zendhqd.database.port = 3306
zendhqd.database.username = zendhq
zendhqd.database.password = zendhq
zendhqd.database.connect_options = UNIX_SOCKET=/qopensys/var/lib/mysql/mysql.sock
“`
Restart the ZendHQ daemon to apply changes.Testing and Migrating ZendHQ Databases
Test and migrate the ZendHQ database using zendhqctl database commands. For testing:
<br /> zendhqctl database test [-t|--table-prefix prefix]<br />
For migration:
<br /> zendhqctl database migrate [-y|--yes] [-k|--keep-migration-file] FROM [TO]<br />
Final Thoughts
Configuring ZendHQ and MariaDB on IBM i offers significant advantages, boosting disaster recovery capabilities and simplifying deployments. The combination of PHP and MariaDB, alongside ZendPHP and ZendHQ, unlocks advanced data management and orchestration tools for IBM i applications.
For more detailed guidance, consider exploring professional services from Zend, which can assist in managing your IBM i PHP applications efficiently.
For further resources, visit Zend’s website.
This comprehensive guide should assist your team in leveraging PHP and MariaDB effectively to ensure robust disaster recovery and enhanced application performance on the IBM i platform.
For more Information, Refer to this article.