Home > Database > Mysql Tutorial > body text

How to build PHP and MySQL databases under Linux

PHPz
Release: 2023-06-02 22:38:39
forward
906 people have browsed it

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
Copy after login

After installation, you need to start the Apache server. Use the following command:

sudo systemctl start apache2
Copy after login

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
Copy after login

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
Copy after login

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
Copy after login

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
Copy after login

Step 4: Test PHP and MySQL

After completing the above operations, your Linux server should have been successfully configured 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:

Copy after login

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
Copy after login

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;
Copy after login

If the command is executed successfully without any errors, it means that MySQL has been successfully installed and enabled.

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!

Related labels:
source:yisu.com
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 [email protected]
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!