Home >Backend Development >PHP Tutorial >Installation tutorial for PHP and MySQL in Red Hat environment
Installing PHP and MySQL in a Red Hat environment is one of the basic steps to build a Web development environment. This article will detail the specific steps to install PHP and MySQL on Red Hat systems and provide corresponding code examples. I hope that through the guidance of this article, you can successfully set up a PHP and MySQL environment and prepare for web development work.
Use the following command to update the system package list:
sudo yum update
Install PHP and related plug-ins:
sudo yum install php php-mysql
After the installation is complete, restart the Apache service:
sudo systemctl restart httpd
Verify whether PHP is successfully installed:
php -v
Install the MySQL database server:
sudo yum install mysql-server
Start the MySQL service and set the boot time:
sudo systemctl start mysqld sudo systemctl enable mysqld
Run the MySQL security script to Improve security:
sudo mysql_secure_installation
Follow the prompts to set the MySQL root password, remove anonymous users, disable root remote login, etc.
Verify whether MySQL is installed successfully:
mysql -u root -p
Enter the root password and successfully log in to mysql, which means the installation is successful.
Create a new PHP file in the Web directory, such as test.php:
sudo vi /var/www/html/test.php
Edit test.php and enter the following code:
<?php $servername = "localhost"; $username = "root"; $password = "your_password"; $conn = new mysqli($servername, $username, $password); if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } echo "Connected successfully!"; ?>
Through the above steps, you have successfully installed PHP and MySQL on the Red Hat system and established the connection between them. This will provide a stable environment for your web development work. Hope this article can be helpful to you.
The above is the detailed content of Installation tutorial for PHP and MySQL in Red Hat environment. For more information, please follow other related articles on the PHP Chinese website!