Home > Backend Development > PHP Tutorial > CentOS7 installs LNMP (Linux+Nginx+MySQL+PHP)

CentOS7 installs LNMP (Linux+Nginx+MySQL+PHP)

WBOY
Release: 2016-08-08 09:20:45
Original
893 people have browsed it

Due to work needs, I need to learn PHP. I originally wanted to install lamp, but considering that the nginx server has good performance and is widely used. Here I decided to build a web server under Linux (CentOS7+Nginx+MySQL+PHP).
1. Install httpd.
yum install -y httpd
After the installation is complete, use the following command to start the httpd service:
systemctl start httpd.service #Start apache <br> systemctl stop httpd.service #Stop apache <br> systemctl restart httpd.service #Restart apache <br> systemctl enable httpd.service #Set apache to start at boot
You can enter the IP of the host where the server is located in the browser to see the apache welcome interface. To achieve this kind of access on another host, you need to turn off the system's firewall.
In CentOS7, the mechanism for modifying the firewall has been modified. In CentOS 6.x system, you can use the following command:
service iptables stop <br> chkconfig iptables off // Disable startup at boot
In CentOS7, you can only use the following command. If you use the above command, no error will be reported, but it will not have the effect of turning off the firewall:
systemctl stop firewalld.service <br> systemctl disable firewalld.service //Disable the firewall from starting
Close SeLinux:
Use the getenforce command to check the status of SeLinux. SeLinux has three statuses: enforcing, permissive and disabled. Since our server is only used internally, we choose to turn it off completely (disabled) here. The specific method is to modify the /etc/sysconfig/selinux file. For specific operations, please refer to the instructions inside.
The effect of successfully installing httpd (apache) is:
2. Install the MySQL database.
MySQL database, the new version has been renamed Mariadb, so Mariadb needs to be installed here. You can use the following command to install it:
yum install -y mariadb
After the installation is complete, use the following command to start the database service:
systemctl start mariadb.service #Start MariaDB <br> systemctl stop mariadb.service #Stop MariaDB <br> systemctl restart mariadb.service #Restart MariaDB <br> systemctl enable mariadb.service #Set up startup
3. Install PHP.
PHP can be installed using the following command:
yum -y install php
Use the following commands to install PHP support for MariaDB:
yum install php-mysql php-gd libjpeg* php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-bcmath php-mhash
Use the following command to restart Mariadb and httpd services:
systemctl restart mariadb.service #Restart MariaDB <br> systemctl restart httpd.service #Restart apache
4. Install nginx.
nginx is used here as a reverse proxy to proxy the .php content requested by the client through port 80 to the apache server.
Install nginx using the following command:
yum install -y nginx
If you want to use nginx as a reverse proxy, you need to modify the configuration files of Apache's httpd and nginx to listen to different ports. Here we use nginx to listen to port 80 and Apache to listen to port 8080. Here we configure the configurations of Apache and nginx respectively. file, the modification results are as follows:
(1) Apache configuration file: /etc/httpd/conf/httpd.conf

(2) The nginx configuration is as follows:
In this way, when the user accesses the server in the browser, files ending in .php will be proxied to the Apache server listening on port 8080. Examples are as follows:
(1) Access without specifying port 8080:

(2) Specify access port 8080.

Copyright statement: This article is an original article by the blogger and may not be reproduced without the blogger's permission.

The above introduces the installation of LNMP (Linux+Nginx+MySQL+PHP) on CentOS7, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

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