Install LNMP on CentOS7 (Linux + Nginx + MySQL + PHP)

Source: Internet
Author: User

Install LNMP on CentOS7 (Linux + Nginx + MySQL + PHP)

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, run the following command to start the httpd service:
Systemctl start httpd. service # start apache
Systemctl stop httpd. service # stop apache
Systemctl restart httpd. service # restart apache
Systemctl enable httpd. service # Set apache startup
You can enter the IP address of the server host in the browser to view the welcome page of apache. To implement such access on another host, you need to disable the system firewall.
In CentOS 7, the firewall modification mechanism has been modified. In CentOS 6. x, run the following command:
Service iptables stop
Chkconfig iptables off // boot prohibited

In CentOS7, you can only use the following command. If you use the command above, no error is reported, but the firewall cannot be disabled:
Systemctl stop firewalld. service
Systemctl disable firewalld. service // disable firewall startup
Disable SeLinux:
Use the getenforce command to view the status of SeLinux. SeLinux has three states: enforcing, permissive, and disabled. Because our server is only used internally, we choose to disable it completely ). The specific method is to modify/Etc/sysconfig/selinuxFile. For more information, see the description.

If httpd (apache) is successfully installed:
2. Install the MySQL database.

MySQL database, the new version has been renamed to Mariadb, so Mariadb needs to be installed here, you can use the following command to install:
yum install -y mariadb
After the installation is complete, use the following command to enable the Database Service:
Systemctl start mariadb. service # start MariaDB
Systemctl stop mariadb. service # stop MariaDB
Systemctl restart mariadb. service # restart MariaDB
Systemctl enable mariadb. service # Set startup

3. install PHP.

Run the following command to install PHP:
yum -y install php
Run the following command 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
Run the following command to restart the Mariadb and httpd services:
Systemctl restart mariadb. service # restart MariaDB
Systemctl restart httpd. service # restart apache

4. Install nginx.

Nginx is used as the reverse proxy to proxy The. php content requested by its client through port 80 to the apache server.
Run the following command to install nginx:
Yum install-y nginx
To use nginx for reverse proxy, You need to modify the httpd and nginx configuration files of Apache 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 configuration files for Apache and nginx respectively. The Modification result is as follows:
(1) Apache configuration file:/etc/httpd/conf/httpd. conf

(2) nginx configuration is as follows:

In this way, when the user accesses the file related to. php on the server in the browser, the agent will be directed to the Apache server listening to port 8080. Example:

(1) access from port 8080 is not specified:

(2) access port 8080.
 
 

You may also like the following LNMP (Linux + Nginx + MySQL + PHP) articles:

Ubuntu 14.04 LTS install LNMP Nginx \ PHP5 (PHP-FPM) \ MySQL

Install the LAMP \ Vsftpd \ Webmin \ phpMyAdmin service and settings in Ubuntu 13.04

Build and install the LNMP production environment in CentOS 6.4

Practical Production Environment-LNMP architecture compilation and installation + SSL encryption implementation

LNMP full-featured compilation and installation for CentOS 6.3 notes

Install LNMP in CentOS 6.3 (PHP 5.4, MyySQL5.6)

Nginx startup failure occurs during LNMP deployment.

Ubuntu install Nginx php5-fpm MySQL (LNMP environment setup)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.