Red Hat is a commonly used Linux operating system, and many websites and applications run on Red Hat systems. It is very important to install PHP and MySQL correctly in a Red Hat system because they are the basis of many web applications. This article will introduce how to correctly install PHP and MySQL in Red Hat systems and provide detailed code examples.
Step one: Install PHP
sudo su
yum update
yum install php php-mysql php-common php-gd php-xml php-mbstring
php -v
systemctl start php-fpm
systemctl enable php-fpm
Step 2: Install MySQL
yum install mysql-server
service mysqld start
chkconfig mysqld on
mysql_secure_installation
Next, some setting options will appear, which can be selected according to your needs.
Step 3: Test PHP and MySQL connections
vim /var/www/html/test.php
Write the following content in the file:
<?php $con = mysqli_connect("localhost", "root", "password"); if (!$con) { die('Could not connect: ' . mysqli_error($con)); } echo 'Connected successfully'; mysqli_close($con); ?>
Summary:
Through the above steps, we successfully installed PHP and MySQL in the Red Hat system and tested their connections. During the installation process, pay attention to the output of the monitoring console to ensure that there are no errors during the installation process. Proper installation and configuration of PHP and MySQL can provide powerful database support for websites and applications so that they can run normally.
The above is the detailed content of How to correctly install PHP and MySQL in Red Hat?. For more information, please follow other related articles on the PHP Chinese website!