Installation tutorial for PHP and MySQL in Red Hat environment

WBOY
Release: 2024-03-06 15:22:01
Original
751 people have browsed it

Red Hat环境下PHP和MySQL的安装教程

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.

1. Install PHP

  1. Log in to the Red Hat system and open the terminal.
  2. Use the following command to update the system package list:

    sudo yum update
    Copy after login
  3. Install PHP and related plug-ins:

    sudo yum install php php-mysql
    Copy after login
  4. After the installation is complete, restart the Apache service:

    sudo systemctl restart httpd
    Copy after login
  5. Verify whether PHP is successfully installed:

    php -v
    Copy after login

2. Install MySQL

  1. Install the MySQL database server:

    sudo yum install mysql-server
    Copy after login
  2. Start the MySQL service and set the boot time:

    sudo systemctl start mysqld
    sudo systemctl enable mysqld
    Copy after login
  3. Run the MySQL security script to Improve security:

    sudo mysql_secure_installation
    Copy after login

    Follow the prompts to set the MySQL root password, remove anonymous users, disable root remote login, etc.

  4. Verify whether MySQL is installed successfully:

    mysql -u root -p
    Copy after login

    Enter the root password and successfully log in to mysql, which means the installation is successful.

3. Connect PHP to MySQL

  1. Create a new PHP file in the Web directory, such as test.php:

    sudo vi /var/www/html/test.php
    Copy after login
  2. Edit test.php and enter the following code:

    connect_error) {
      die("Connection failed: " . $conn->connect_error);
    }
    echo "Connected successfully!";
    ?>
    Copy after login
  3. Save and exit the editor, then visit http://localhost/test.php to check whether the connection is successful to the MySQL database.

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!