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
Release: 2023-04-05 15:02:02
Original
1269 people have browsed it

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

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

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

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

sudo systemctl start nginx
Copy after login

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

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

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

sudo yum install mysql-server
Copy after login

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

sudo systemctl start mysqld
Copy after login

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

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

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

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

sudo yum install php
Copy after login

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

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

In the test.php file, enter the following:

<?php
phpinfo();
?>
Copy after login

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!

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