Home >Backend Development >PHP Problem >How to install Nginx, PHP and MySQL under Linux system

How to install Nginx, PHP and MySQL under Linux system

PHPz
PHPzOriginal
2023-04-05 14:34:551264browse

In Linux systems, Nginx is a common web server software, while PHP and MySQL are the main components of application servers and database services. Using the three of them together can provide powerful web application support. In this article, we will introduce how to install Nginx, PHP and MySQL under Linux system.

1. Install Nginx

First, we need to install Nginx. In most Linux distributions, Nginx can be installed through package management tools. For example, in a Debian or Ubuntu system, you can use the following command to install:

sudo apt-get update
sudo apt-get install nginx

In a CentOS or RHEL system, you can use the following command to install:

sudo yum install epel-release //如果没有epel仓库需要安装,否则忽略这一步
sudo yum install nginx

After the installation is complete, you can use the following command Start the Nginx service:

sudo systemctl start nginx

In order to ensure that Nginx starts automatically every time the system starts, you can use the following command to enable the self-start function:

sudo systemctl enable nginx

Now, we can open the server in the browser IP address to test whether Nginx has been successfully installed. If installed successfully, you should be able to see the Nginx welcome page.

2. Install MySQL

Next, we need to install MySQL. In Linux systems, you can use package management tools to install MySQL. For example, in a Debian or Ubuntu system, you can use the following command to install:

sudo apt-get update
sudo apt-get install mysql-server

In a CentOS or RHEL system, you can use the following command to install:

sudo yum install mysql-server

After the installation is complete, you can use the following command Start the MySQL service:

sudo systemctl start mysqld

In order to ensure that MySQL starts automatically every time the system starts, you can use the following command to turn on the self-start function:

sudo systemctl enable mysqld

Now, we need to perform some basic security on MySQL Setup, including setting the root password and deleting the default test database. During the security setup process, you can use the following command to complete:

sudo mysql_secure_installation

After completing the above steps, MySQL has been successfully installed and based on security settings.

3. Install PHP

Finally, we need to install PHP support. In Linux systems, PHP can be installed through package management tools. For example, in a Debian or Ubuntu system, you can use the following command to install:

sudo apt-get install php

In a CentOS or RHEL system, you can use the following command to install:

sudo yum install php

After the installation is complete, you can use the following command Restart Nginx and PHP services:

sudo systemctl restart nginx
sudo systemctl restart php-fpm

Now we can test whether PHP was successfully installed. You can use the following command to create a test.php file in the /var/www/html directory:

sudo nano /var/www/html/test.php

In the test.php file, enter the following:

<?php
phpinfo();
?>

Save the file and exit editing device. Now, enter the IP address of the server followed by /test.php in the browser. If you see the PHP version information and some related settings, it means that PHP has been successfully installed.

Summary

In this article, we introduced how to install Nginx, PHP and MySQL in a Linux system. Once installed, we can use these powerful web technologies to build great web applications. Although installation and configuration can sometimes be challenging, mastering the process will provide you with some valuable skills and will give you significant advantages in web development.

The above is the detailed content of How to install Nginx, PHP and MySQL under Linux system. 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