{"id":121208,"date":"2022-07-20T03:19:05","date_gmt":"2022-07-20T00:19:05","guid":{"rendered":"https:\/\/computingforgeeks.com\/?p=121208"},"modified":"2024-02-29T09:14:52","modified_gmt":"2024-02-29T06:14:52","slug":"install-apache-mariadb-php-on-rocky-linux","status":"publish","type":"post","link":"https:\/\/computingforgeeks.com\/install-apache-mariadb-php-on-rocky-linux\/","title":{"rendered":"Install Apache, MariaDB, PHP (LAMP) on Rocky Linux 9"},"content":{"rendered":"\n<p>For general web development and hosting, you need a Programming language, a database, and a web server. The<strong> LAMP stack <\/strong>is a collection of open-source Linux tools that include Apache, MySQL\/MariaDB, and PHP. These tools work closely together to enable a server to host and run modern and dynamic web applications.<\/p>\n\n\n\n<p>The components of the LAMP stack are well elaborated below:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Apache<\/strong>: This is an open-source cross-platform web server that runs 67% of all websites in the world. This software is developed and maintained by the Apache Software Foundation.<\/li>\n\n\n\n<li><strong>MariaDB<\/strong>: This is a relational database management system developed by the original developers of MySQL and guaranteed to stay open source.<\/li>\n\n\n\n<li><strong>PHP<\/strong>: This is an abbreviation of <strong><em>Hypertext Pre-processor<\/em><\/strong>. This is an open-source general scripting language that serves as a backend programming language for Web applications. Moreso, this language can also be used with HTML when creating web applications. The main difference between PHP and other languages such as JavaScript is that the codes are executed on the server, and HTML scripts are generated and sent to the client.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">How does LAMP Stack work?<\/h3>\n\n\n\n<p>The Apache web server receives requests for web pages for the browser. If a PHP file is requested, then it passes the request to PHP which then loads and executes the code contained in the file. PHP also links with the database(MySQL\/MariaDB) to obtain any referenced data in the code.<\/p>\n\n\n\n<p>The PHP code and data fetched from the database are then used to generate HTML scripts that are used to display the web pages. The LAMP stack is effective when handling both static and dynamic web pages where data changes from time to time when loaded.<\/p>\n\n\n\n<p>PHP then passes these results back to the Apache Web server which then sends them back to the browser.<\/p>\n\n\n\n<p>In this guide, we will install and use Apache, MariaDB, and PHP (LAMP) on Rocky Linux 9.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">1. Install Apache web server<\/h2>\n\n\n\n<p>The first component to be installed here is the Apache Web server. This software is provided as <code>httpd<\/code> in the Rocky Linux repositories. To install it, execute the command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo dnf install httpd<\/code><\/pre>\n\n\n\n<p>Dependency Tree:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Transaction Summary\n================================================================================\nInstall  10 Packages\n\nTotal download size: 1.9 M\nInstalled size: 5.9 M\nIs this ok &#91;y\/N]:<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-luminous-vivid-orange-color\"> y<\/mark><\/code><\/pre>\n\n\n\n<p>Once installed, start and enable the service:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo systemctl enable --now httpd<\/code><\/pre>\n\n\n\n<p>Check the status of the service:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-pale-pink-color\">systemctl status httpd<\/mark>\n\u25cf httpd.service - The Apache HTTP Server\n     Loaded: loaded (\/usr\/lib\/systemd\/system\/httpd.service; enabled; vendor preset: disabled)\n     Active: <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-green-cyan-color\">active (running)<\/mark> since Thu 2024-02-29 05:57:25 UTC; 4s ago\n       Docs: man:httpd.service(8)\n   Main PID: 2287 (httpd)\n     Status: \"Total requests: 0; Idle\/Busy workers 100\/0;Requests\/sec: 0; Bytes served\/sec:   0 B\/sec\"\n      Tasks: 213 (limit: 23441)\n     Memory: 35.0M\n        CPU: 64ms\n     CGroup: \/system.slice\/httpd.service\n             \u251c\u25002287 \/usr\/sbin\/httpd -DFOREGROUND\n             \u251c\u25002288 \/usr\/sbin\/httpd -DFOREGROUND\n             \u251c\u25002289 \/usr\/sbin\/httpd -DFOREGROUND\n             \u251c\u25002290 \/usr\/sbin\/httpd -DFOREGROUND\n             \u2514\u25002291 \/usr\/sbin\/httpd -DFOREGROUND<\/code><\/pre>\n\n\n\n<p>You can also verify if Apache is running by accessing the default page on a browser. First, allow the HTTP traffic through the firewall:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo firewall-cmd --add-service=http --permanent\nsudo firewall-cmd --reload<\/code><\/pre>\n\n\n\n<p>Access the web page using the URL<a href=\"http:\/\/IP_Address\" target=\"_blank\" rel=\"noreferrer noopener\"> http:\/\/IP_Address<\/a> or <a href=\"http:\/\/domain_name\" target=\"_blank\" rel=\"noreferrer noopener\">http:\/\/domain_name<\/a><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"862\" height=\"841\" src=\"https:\/\/computingforgeeks.com\/wp-content\/uploads\/2022\/07\/Apache-MariaDB-PHP-LAMP-on-Rocky-Linux-9.png\" alt=\"\" class=\"wp-image-121227\" title=\"\" srcset=\"https:\/\/computingforgeeks.com\/wp-content\/uploads\/2022\/07\/Apache-MariaDB-PHP-LAMP-on-Rocky-Linux-9.png 862w, https:\/\/computingforgeeks.com\/wp-content\/uploads\/2022\/07\/Apache-MariaDB-PHP-LAMP-on-Rocky-Linux-9-300x293.png 300w, https:\/\/computingforgeeks.com\/wp-content\/uploads\/2022\/07\/Apache-MariaDB-PHP-LAMP-on-Rocky-Linux-9-768x749.png 768w, https:\/\/computingforgeeks.com\/wp-content\/uploads\/2022\/07\/Apache-MariaDB-PHP-LAMP-on-Rocky-Linux-9-696x679.png 696w, https:\/\/computingforgeeks.com\/wp-content\/uploads\/2022\/07\/Apache-MariaDB-PHP-LAMP-on-Rocky-Linux-9-430x420.png 430w\" sizes=\"auto, (max-width: 862px) 100vw, 862px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">2. Install MariaDB Database Server<\/h2>\n\n\n\n<p>We need a database server for web hosting. There are two options here, MySQL or the MariaDB database. In this guide, we will opt for the <strong>MariaDB<\/strong> database due to its high-performance storage engines, faster and safer replication, and compatibility with MySQL.<\/p>\n\n\n\n<p>Rocky Linux 9 provides<strong> MariaDB 10<\/strong> in the default repository. This can be installed using the command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo dnf install mariadb-server mariadb<\/code><\/pre>\n\n\n\n<p>Once installed, start and enable the MariaDB service:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo systemctl enable --now mariadb<\/code><\/pre>\n\n\n\n<p>Verify if the service is running:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-pale-pink-color\">systemctl status mariadb<\/mark>\n\u25cf mariadb.service - MariaDB 10.5 database server\n     Loaded: loaded (\/usr\/lib\/systemd\/system\/mariadb.service; enabled; vendor preset: disabled)\n     Active: <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-green-cyan-color\">active (running)<\/mark> since Thu 2024-02-29 05:58:26 UTC; 2s ago\n       Docs: man:mariadbd(8)\n             https:&#47;&#47;mariadb.com\/kb\/en\/library\/systemd\/\n    Process: 3609 ExecStartPre=\/usr\/libexec\/mariadb-check-socket (code=exited, status=0\/SUCCESS)\n    Process: 3631 ExecStartPre=\/usr\/libexec\/mariadb-prepare-db-dir mariadb.service (code=exited, status=0\/SUCCESS)\n    Process: 3724 ExecStartPost=\/usr\/libexec\/mariadb-check-upgrade (code=exited, status=0\/SUCCESS)\n   Main PID: 3711 (mariadbd)\n     Status: \"Taking your SQL requests now...\"\n      Tasks: 12 (limit: 23441)\n     Memory: 70.8M\n        CPU: 254ms\n     CGroup: \/system.slice\/mariadb.service\n             \u2514\u25003711 \/usr\/libexec\/mariadbd --basedir=\/usr<\/code><\/pre>\n\n\n\n<p>By default, the MariaDB is not secure and this might cause vulnerabilities. To secure it, proceed as shown:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-pale-pink-color\">sudo mysql_secure_installation<\/mark>\n....\nEnter current password for root (enter for none): Just press Enter\n......\nSwitch to unix_socket authentication &#91;Y\/n] <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-luminous-vivid-orange-color\">Y<\/mark>\n.....\nChange the root password? &#91;Y\/n] <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-luminous-vivid-orange-color\">Y<\/mark>\nNew password:  New-root-password\nRe-enter new password: Re-enter New-root-password\n....\nRemove anonymous users? &#91;Y\/n] <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-luminous-vivid-orange-color\">Y<\/mark>\n....\nDisallow root login remotely? &#91;Y\/n] <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-luminous-vivid-orange-color\">Y<\/mark>\n.....\nRemove test database and access to it? &#91;Y\/n] <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-luminous-vivid-orange-color\">Y<\/mark>\n......\nReload privilege tables now? &#91;Y\/n] <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-luminous-vivid-orange-color\">Y<\/mark>\n...\nThanks for using MariaDB!<\/code><\/pre>\n\n\n\n<p>Verify if you can log in using the created password:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-pale-pink-color\">mysql -u root -p<\/mark>\nEnter password: \nWelcome to the MariaDB monitor.  Commands end with ; or \\g.\nYour MariaDB connection id is 13\nServer version: 10.5.22-MariaDB MariaDB Server\n\nCopyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.\n\nType 'help;' or '\\h' for help. Type '\\c' to clear the current input statement.\n\nMariaDB &#91;(none)]> <em><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-luminous-vivid-amber-color\">SELECT VERSION();<\/mark><\/em>\n+-----------------+\n| VERSION()       |\n+-----------------+\n| 10.5.22-MariaDB |\n+-----------------+\n1 row in set (0.000 sec)\n\nMariaDB &#91;(none)]> <em><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-luminous-vivid-amber-color\">QUIT<\/mark><\/em>\nBye<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">3. Install PHP and Extensions<\/h2>\n\n\n\n<p>The default PHP version available in the Rocky Linux 9 repositories is <strong>PHP 8.0<\/strong>. This version comes with bug fixes and enhancements, including the use of structured metadata syntax, newly named arguments that are order-independent, and improved performance for Just-In-Time compilation.<\/p>\n\n\n\n<p>Install PHP 8.0 and its dependencies using the command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo dnf install php-{common,gmp,fpm,curl,intl,pdo,mbstring,gd,xml,cli,zip,mysqli}<\/code><\/pre>\n\n\n\n<p>Check the PVH version:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-luminous-vivid-amber-color\">php --version<\/mark>\nPHP 8.0.30 (cli) (built: Aug  3 2023 17:13:08) ( NTS gcc x86_64 )\nCopyright (c) The PHP Group\nZend Engine v4.0.30, Copyright (c) Zend Technologies<\/code><\/pre>\n\n\n\n<p>It is also possible to install other PHP versions. This can be done by adding the Remi and EPEL repositories:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo dnf install -y https:\/\/rpms.remirepo.net\/enterprise\/remi-release-9.rpm <\/code><\/pre>\n\n\n\n<p>Once added, list the PHP versions available:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-luminous-vivid-amber-color\">sudo dnf module list php<\/mark>\nLast metadata expiration check: 0:00:30 ago on Thu 29 Feb 2024 06:07:00 AM UTC.\nRocky Linux 9 - AppStream\nName                                   Stream                                     Profiles                                                     Summary\nphp                                    8.1                                        common &#91;d], devel, minimal                                   PHP scripting language\n\nRemi's Modular repository for Enterprise Linux 9 - x86_64\nName                                   Stream                                     Profiles                                                     Summary\nphp                                    remi-7.4                                   common &#91;d], devel, minimal                                   PHP scripting language\nphp                                    remi-8.0                                   common &#91;d], devel, minimal                                   PHP scripting language\nphp                                    remi-8.1                                   common &#91;d], devel, minimal                                   PHP scripting language\nphp                                    remi-8.2                                   common &#91;d], devel, minimal                                   PHP scripting language\nphp                                    remi-8.3                                   common &#91;d], devel, minimal                                   PHP scripting language\n\nHint: &#91;d]efault, &#91;e]nabled, &#91;x]disabled, &#91;i]nstalled<\/code><\/pre>\n\n\n\n<p>Enable and install the preferred version, say PHP<strong> 8.1 <\/strong>as shown<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo dnf module enable php:remi-8.1 -y<\/code><\/pre>\n\n\n\n<p>Now install the PHP and its dependencies:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo dnf install php-{common,gmp,fpm,curl,intl,pdo,mbstring,gd,xml,cli,zip,mysqli}<\/code><\/pre>\n\n\n\n<p>Verify the installation.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-luminous-vivid-amber-color\">php --version<\/mark>\nPHP 8.1.27 (cli) (built: Dec 19 2023 20:35:55) (NTS gcc x86_64)\nCopyright (c) The PHP Group\nZend Engine v4.1.27, Copyright (c) Zend Technologies<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">4. Configure PHP for Apache<\/h2>\n\n\n\n<p>To configure PHP, open the file below:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo vi \/etc\/php.ini<\/code><\/pre>\n\n\n\n<p>In the file, make the desired settings. For example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>max_execution_time = 300\nupload_max_filesize = 100M\npost_max_size = 128M\ndate.timezone = Africa\/Nairobi<\/code><\/pre>\n\n\n\n<p>After making the desired changes, allow Apache to load PHP files:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-luminous-vivid-amber-color\">sudo vi \/etc\/httpd\/conf\/httpd.conf<\/mark>\n# LoadModule foo_module modules\/mod_foo.so\n<em><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-purple-color\">AddHandler php-script .php<\/mark><\/em><\/code><\/pre>\n\n\n\n<p>You can also check the PHP version by creating a test PHP file using the command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo vi \/var\/www\/html\/info.php<\/code><\/pre>\n\n\n\n<p>Add the below lines to the file:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\nphpinfo();\n?&gt;<\/code><\/pre>\n\n\n\n<p>Save the file and restart Apache and PHP-FPM:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo systemctl restart php-fpm\nsudo systemctl restart httpd<\/code><\/pre>\n\n\n\n<p>Access the page that displays the PHP parameters using the URL <a href=\"http:\/\/IP_Address\/info.php\" target=\"_blank\" rel=\"noreferrer noopener\">http:\/\/IP_Address\/info.php<\/a><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"931\" height=\"904\" src=\"https:\/\/computingforgeeks.com\/wp-content\/uploads\/2022\/07\/Apache-MariaDB-PHP-LAMP-on-Rocky-Linux-9-1.png\" alt=\"\" class=\"wp-image-121228\" title=\"\" srcset=\"https:\/\/computingforgeeks.com\/wp-content\/uploads\/2022\/07\/Apache-MariaDB-PHP-LAMP-on-Rocky-Linux-9-1.png 931w, https:\/\/computingforgeeks.com\/wp-content\/uploads\/2022\/07\/Apache-MariaDB-PHP-LAMP-on-Rocky-Linux-9-1-300x291.png 300w, https:\/\/computingforgeeks.com\/wp-content\/uploads\/2022\/07\/Apache-MariaDB-PHP-LAMP-on-Rocky-Linux-9-1-768x746.png 768w, https:\/\/computingforgeeks.com\/wp-content\/uploads\/2022\/07\/Apache-MariaDB-PHP-LAMP-on-Rocky-Linux-9-1-696x676.png 696w, https:\/\/computingforgeeks.com\/wp-content\/uploads\/2022\/07\/Apache-MariaDB-PHP-LAMP-on-Rocky-Linux-9-1-433x420.png 433w\" sizes=\"auto, (max-width: 931px) 100vw, 931px\" \/><\/figure>\n\n\n\n<p>Delete test script:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo rm \/var\/www\/html\/info.php<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">5. Creating Apache Virtual Host file<\/h2>\n\n\n\n<p>For you to be able to access a site via the browser, you need to create a virtual host file for the site. In this guide, we will configure Apache to serve a sample page as shown.<\/p>\n\n\n\n<p>Create the virtual host file:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo vi \/etc\/httpd\/conf.d\/<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-pale-cyan-blue-color\">yourdomain.conf<\/mark><\/code><\/pre>\n\n\n\n<p>In the file, add the lines below:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;VirtualHost *:80&gt;\n    ServerName <em><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-purple-color\">test.example.com<\/mark><\/em>\n    DocumentRoot \/var\/www\/html\/\n    ErrorLog \/var\/log\/httpd\/error.log\n    CustomLog \/var\/log\/httpd\/requests.log combined\n&lt;\/VirtualHost&gt;<\/code><\/pre>\n\n\n\n<p>Create the file in the document root specified:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo vi \/var\/www\/html\/index.html<\/code><\/pre>\n\n\n\n<p>Add the lines:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;html&gt;\n  &lt;head&gt;\n    &lt;title&gt;This is a test page&lt;\/title&gt;\n  &lt;\/head&gt;\n  &lt;body&gt;\n    &lt;h1&gt;LAMP Stack is working perfectly on Rocky Linux 9!&lt;\/h1&gt;\n  &lt;\/body&gt;\n&lt;\/html&gt;<\/code><\/pre>\n\n\n\n<p>Restart Apache:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo systemctl restart httpd<\/code><\/pre>\n\n\n\n<p>Now access the web page using the URL <a href=\"http:\/\/IP_address\" target=\"_blank\" rel=\"noreferrer noopener\">http:\/\/IP_address<\/a> or <a href=\"http:\/\/domain_name\" target=\"_blank\" rel=\"noreferrer noopener\">http:\/\/domain_name<\/a><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"826\" height=\"378\" src=\"https:\/\/computingforgeeks.com\/wp-content\/uploads\/2022\/07\/Apache-MariaDB-PHP-LAMP-on-Rocky-Linux-9-2.png\" alt=\"\" class=\"wp-image-121230\" title=\"\" srcset=\"https:\/\/computingforgeeks.com\/wp-content\/uploads\/2022\/07\/Apache-MariaDB-PHP-LAMP-on-Rocky-Linux-9-2.png 826w, https:\/\/computingforgeeks.com\/wp-content\/uploads\/2022\/07\/Apache-MariaDB-PHP-LAMP-on-Rocky-Linux-9-2-300x137.png 300w, https:\/\/computingforgeeks.com\/wp-content\/uploads\/2022\/07\/Apache-MariaDB-PHP-LAMP-on-Rocky-Linux-9-2-768x351.png 768w, https:\/\/computingforgeeks.com\/wp-content\/uploads\/2022\/07\/Apache-MariaDB-PHP-LAMP-on-Rocky-Linux-9-2-696x319.png 696w\" sizes=\"auto, (max-width: 826px) 100vw, 826px\" \/><\/figure>\n\n\n\n<p>Remove test page:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo rm \/var\/www\/html\/index.html<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">6. Host PHP Application with Database<\/h2>\n\n\n\n<p>To test the better working of the LAMP stack, we will configure the PHP Websites to connect to the  MySQL database. The below steps are used.<\/p>\n\n\n\n<p>Begin by creating a database.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mysql -u root -p<\/code><\/pre>\n\n\n\n<p>Create a database with the below table<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE DATABASE db_contact;\nUSE db_contact;\nCREATE TABLE tbl_contact (Id INT,fldName VARCHAR(50), fldEmail VARCHAR(30), fldPhone VARCHAR(15),fldMessage VARCHAR(1000));\nEXIT<\/code><\/pre>\n\n\n\n<p>Create an HTML form for connecting to the database:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo mkdir \/var\/www\/html\/contacts\nsudo vi \/var\/www\/html\/contacts\/contact.html<\/code><\/pre>\n\n\n\n<p>Add the below lines to the file:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!DOCTYPE html&gt;\n&lt;html xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\"&gt;\n&lt;head&gt;\n&lt;meta http-equiv=\"Content-Type\" content=\"text\/html; charset=utf-8\" \/&gt;\n&lt;title&gt;Contact Form - PHP\/MySQL Demo Code&lt;\/title&gt;\n&lt;\/head&gt;\n\n&lt;body&gt;\n&lt;fieldset&gt;\n&lt;legend&gt;Contact Form&lt;\/legend&gt;\n&lt;form name=\"frmContact\" method=\"post\" action=\"contact.php\"&gt;\n&lt;p&gt;\n&lt;label for=\"Name\"&gt;Name &lt;\/label&gt;\n&lt;input type=\"text\" name=\"txtName\" id=\"txtName\"&gt;\n&lt;\/p&gt;\n&lt;p&gt;\n&lt;label for=\"email\"&gt;Email&lt;\/label&gt;\n&lt;input type=\"text\" name=\"txtEmail\" id=\"txtEmail\"&gt;\n&lt;\/p&gt;\n&lt;p&gt;\n&lt;label for=\"phone\"&gt;Phone&lt;\/label&gt;\n&lt;input type=\"text\" name=\"txtPhone\" id=\"txtPhone\"&gt;\n&lt;\/p&gt;\n&lt;p&gt;\n&lt;label for=\"message\"&gt;Message&lt;\/label&gt;\n&lt;textarea name=\"txtMessage\" id=\"txtMessage\"&gt;&lt;\/textarea&gt;\n&lt;\/p&gt;\n&lt;p&gt;&amp;nbsp;&lt;\/p&gt;\n&lt;p&gt;\n&lt;input type=\"submit\" name=\"Submit\" id=\"Submit\" value=\"Submit\"&gt;\n&lt;\/p&gt;\n&lt;\/form&gt;\n&lt;\/fieldset&gt;\n&lt;\/body&gt;\n&lt;\/html&gt;<\/code><\/pre>\n\n\n\n<p>Now create a PHP script to save data from HTML form to your database:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo vi \/var\/www\/html\/contacts\/contact.php<\/code><\/pre>\n\n\n\n<p>Add the below lines to it:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\n\/\/ database connection code\n\/\/ $con = mysqli_connect('localhost', 'database_user', 'database_password','database');\n\n$con = mysqli_connect('localhost', 'root', '<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-cyan-blue-color\">root_password<\/mark>','<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-cyan-blue-color\">db_contact<\/mark>');\n\n\/\/ get the post records\n$txtName = $_POST&#91;'txtName'];\n$txtEmail = $_POST&#91;'txtEmail'];\n$txtPhone = $_POST&#91;'txtPhone'];\n$txtMessage = $_POST&#91;'txtMessage'];\n\n\/\/ database insert SQL code\n$sql = \"INSERT INTO `tbl_contact` (`Id`, `fldName`, `fldEmail`, `fldPhone`, `fldMessage`) VALUES ('0', '$txtName', '$txtEmail', '$txtPhone', '$txtMessage')\";\n\n\/\/ insert in database \n$rs = mysqli_query($con, $sql);\n\nif($rs)\n{\n\techo \"Contact Records Inserted\";\n}\n\n?&gt;<\/code><\/pre>\n\n\n\n<p>Remember to replace the<strong><em> root_password<\/em><\/strong> and <strong>db_contact<\/strong> with the database name. Once the files have been saved, load the page using the URL <a href=\"http:\/\/domain_name\/contacts\/contact.html\" target=\"_blank\" rel=\"noreferrer noopener\">http:\/\/domain_name\/contacts\/contact.html<\/a><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"693\" height=\"376\" src=\"https:\/\/computingforgeeks.com\/wp-content\/uploads\/2022\/07\/Apache-MariaDB-PHP-LAMP-on-Rocky-Linux-9-3-1.png\" alt=\"\" class=\"wp-image-121231\" title=\"\" srcset=\"https:\/\/computingforgeeks.com\/wp-content\/uploads\/2022\/07\/Apache-MariaDB-PHP-LAMP-on-Rocky-Linux-9-3-1.png 693w, https:\/\/computingforgeeks.com\/wp-content\/uploads\/2022\/07\/Apache-MariaDB-PHP-LAMP-on-Rocky-Linux-9-3-1-300x163.png 300w\" sizes=\"auto, (max-width: 693px) 100vw, 693px\" \/><\/figure>\n\n\n\n<p>Fill in the form and submit the changes<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"667\" height=\"279\" src=\"https:\/\/computingforgeeks.com\/wp-content\/uploads\/2022\/07\/Apache-MariaDB-PHP-LAMP-on-Rocky-Linux-9-4.png\" alt=\"\" class=\"wp-image-121232\" title=\"\" srcset=\"https:\/\/computingforgeeks.com\/wp-content\/uploads\/2022\/07\/Apache-MariaDB-PHP-LAMP-on-Rocky-Linux-9-4.png 667w, https:\/\/computingforgeeks.com\/wp-content\/uploads\/2022\/07\/Apache-MariaDB-PHP-LAMP-on-Rocky-Linux-9-4-300x125.png 300w\" sizes=\"auto, (max-width: 667px) 100vw, 667px\" \/><\/figure>\n\n\n\n<p>Verify if data has been added to the database:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-pale-pink-color\">mysql -u root -p<\/mark>\nEnter password: \nMariaDB &#91;(none)]&gt; <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-luminous-vivid-amber-color\">SELECT * FROM  db_contact. tbl_contact;<\/mark><\/code><\/pre>\n\n\n\n<p>Sample Output:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"719\" height=\"167\" src=\"https:\/\/computingforgeeks.com\/wp-content\/uploads\/2022\/07\/Apache-MariaDB-PHP-LAMP-on-Rocky-Linux-9-5.png\" alt=\"\" class=\"wp-image-121233\" title=\"\" srcset=\"https:\/\/computingforgeeks.com\/wp-content\/uploads\/2022\/07\/Apache-MariaDB-PHP-LAMP-on-Rocky-Linux-9-5.png 719w, https:\/\/computingforgeeks.com\/wp-content\/uploads\/2022\/07\/Apache-MariaDB-PHP-LAMP-on-Rocky-Linux-9-5-300x70.png 300w, https:\/\/computingforgeeks.com\/wp-content\/uploads\/2022\/07\/Apache-MariaDB-PHP-LAMP-on-Rocky-Linux-9-5-696x162.png 696w\" sizes=\"auto, (max-width: 719px) 100vw, 719px\" \/><\/figure>\n\n\n\n<p>That is it!. We can now clean up the test:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo rm -rf \/var\/www\/html\/contacts<\/code><\/pre>\n\n\n\n<p><strong><em>Recommended books to read:<\/em><\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/computingforgeeks.com\/best-books-to-learn-magento-ecommerce-development\/\" target=\"_blank\" rel=\"noreferrer noopener\">Best Books to learn Web Development &#8211; PHP, HTML, CSS, JavaScript and jQuery<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/computingforgeeks.com\/best-books-to-master-web-design\/\" target=\"_blank\" rel=\"noreferrer noopener\">Best Books To Master Web Design<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/computingforgeeks.com\/best-books-to-learn-css-css3\/\" target=\"_blank\" rel=\"noreferrer noopener\">Best Books To Learn CSS &amp; CSS3<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/computingforgeeks.com\/best-books-to-learn-html-html5\/\" target=\"_blank\" rel=\"noreferrer noopener\">Best Books To Learn HTML &amp; HTML5<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/computingforgeeks.com\/best-books-to-learn-kafka-and-apache-spark\/\" target=\"_blank\" rel=\"noreferrer noopener\">Best Apache and Nginx reference Books<\/a><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Closing Thoughts<\/h2>\n\n\n\n<p>That marks the end of this guide on how to install Apache, MariaDB, and PHP (LAMP) on Rocky Linux 9. I hope this was significant to you.<\/p>\n\n\n\n<p>See more:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/computingforgeeks.com\/setup-lemp-stack-for-wordpress-using-ansible\/\" target=\"_blank\" rel=\"noreferrer noopener\">How To Setup LEMP stack for WordPress using Ansible<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/computingforgeeks.com\/manage-users-and-groups-on-linux-using-ansible\/\" target=\"_blank\" rel=\"noreferrer noopener\">Manage WordPress Website on Linux using WordOps<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/computingforgeeks.com\/how-to-install-php-on-ubuntu-2\/\" target=\"_blank\" rel=\"noreferrer noopener\">How To Install PHP 8.0 on Ubuntu<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>For general web development and hosting, you need a Programming language, a database, and a web server. The LAMP stack is a collection of open-source Linux tools that include Apache, MySQL\/MariaDB, and PHP. These tools work closely together to enable a server to host and run modern and dynamic web applications. The components of the &#8230; <a title=\"Install Apache, MariaDB, PHP (LAMP) on Rocky Linux 9\" class=\"read-more\" href=\"https:\/\/computingforgeeks.com\/install-apache-mariadb-php-on-rocky-linux\/\" aria-label=\"Read more about Install Apache, MariaDB, PHP (LAMP) on Rocky Linux 9\">Read more<\/a><\/p>\n","protected":false},"author":21,"featured_media":121228,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[299,50,35910,349],"tags":[37627,37626,37629,37628],"class_list":["post-121208","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-how-to","category-linux-tutorials","category-rocky-linux","category-web-hosting","tag-apache-on-rocky-linux-9","tag-lamp-on-rocky-linux-9","tag-mariadb-on-rocky-linux-9","tag-php-on-rocky-linux-9"],"_links":{"self":[{"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/posts\/121208","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/users\/21"}],"replies":[{"embeddable":true,"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/comments?post=121208"}],"version-history":[{"count":0,"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/posts\/121208\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/media\/121228"}],"wp:attachment":[{"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/media?parent=121208"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/categories?post=121208"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/tags?post=121208"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}