Home  >  Article  >  Backend Development  >  How to correctly install PHP and MySQL in Red Hat?

How to correctly install PHP and MySQL in Red Hat?

PHPz
PHPzOriginal
2024-03-06 16:15:05781browse

Red Hat中如何正确安装PHP和MySQL?

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

  1. Log in to the system as root user:
sudo su
  1. Update the system:
yum update
  1. Install PHP and related extensions:
yum install php php-mysql php-common php-gd php-xml php-mbstring
  1. Check the PHP version:
php -v
  1. Start PHP:
systemctl start php-fpm
  1. Set PHP to start automatically at boot:
systemctl enable php-fpm

Step 2: Install MySQL

  1. Install MySQL database server:
yum install mysql-server
  1. Start MySQL:
service mysqld start
  1. Set MySQL to start automatically at boot:
chkconfig mysqld on
  1. Use the MySQL security script to set up MySQL Security:
mysql_secure_installation

Next, some setting options will appear, which can be selected according to your needs.

Step 3: Test PHP and MySQL connections

  1. Create a test file test.php:
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);
?>
  1. Enter the address of the test PHP file in the browser, such as http://yourdomain/test.php. If "Connected successfully" is displayed, it means that the connection between PHP and MySQL is normal.

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn