Home > Article > Operation and Maintenance > How to build PHP and MySQL databases under Linux
In web development, database and PHP are two very important components. On the Linux operating system, it is also very easy to build PHP and MySQL. This article will introduce how to build PHP and MySQL databases under Linux systems.
Step 1: Install the Apache server
On the Linux system, before setting up PHP and MySQL, you need to install the Apache server first. Apache is a popular web server that is required by many web applications to serve it. You can use the following command to install:
sudo apt-get install apache2
After installation, you need to start the Apache server. Use the following command:
sudo systemctl start apache2
Step 2: Install MySQL
MySQL is a popular relational database management system commonly used for data storage in web applications. Use the following command to install MySQL:
sudo apt-get install mysql-server
During the installation process, you will be prompted to enter the password of the root user. You must set a strong password for the database to ensure security. After installation is complete, you can use the following command to start the MySQL service:
sudo systemctl start mysql
Step 3: Install PHP
PHP is a popular Web programming language that is commonly used for Embed dynamic content in web applications. Use the following command to install PHP:
sudo apt-get install php libapache2-mod-php
The installation of PHP will automatically enable the mod_php module on the Apache server. You need to restart the Apache server for PHP support to take full effect. Please use the following command to restart the Apache server:
sudo systemctl restart apache2
Step 4: Test PHP and MySQL
After completing the above steps, you should configure it on your Linux server Apache server, MySQL and PHP. Now, you need to test whether they work properly.
Create a file called info.php and add the following content to the file:
bc4474c4eeebd01323eb678c5726cfb5
Place the info.php file in the web server root directory /var/www/html/ Down.
Now you can open a web browser and visit the following URL: http://your-server-ip-address/info.php
(Please replace "your-server-ip -address" is the actual IP address of your Linux server). If you see the PHP configuration information page, PHP has been successfully installed and enabled.
To test whether MySQL is working properly, you can log in to MySQL using the following command:
mysql -u root -p
Enter the MySQL password you set for the root user and log in to the MySQL console.
Now, enter the following command to test whether the database can be created:
CREATE DATABASE testdb;
If the command is executed successfully without any errors, it means that MySQL has been successfully installed and enabled.
Conclusion
It is very easy to build PHP and MySQL on a Linux system. You only need to install the Apache server, MySQL and PHP, and then perform simple configuration. Through the steps in this article, you can easily set up a PHP and MySQL development environment to provide powerful support for your web applications.
The above is the detailed content of How to build PHP and MySQL databases under Linux. For more information, please follow other related articles on the PHP Chinese website!