CENTOS7 mounting Lnmp (Linux+nginx+mysql+php+phpmyadmin+apache)

Source: Internet
Author: User
Tags install php learn php access database nginx server phpmyadmin

CENTOS7 installation Lnmp (linux+nginx+mysql+php) and Apache

Nginx is a very lightweight HTTP server written by the Russians, Nginx is a high-performance HTTP and reverse proxy server, Nginx beyond the performance and stability of Apache, so that the domestic use of Nginx as a Web server site is more and more,

We learn PHP, as well as build our own LNMP environment, it is advisable to try to learn on this machine, below we step-by-step to complete the installation of LNMP (linux+nginx+mysql+php) and Apache under CentOS7.

View ports that are already open
Firewall-cmd--list-ports
View the Open service
Firewall-cmd--list-services

Open port
Firewall-cmd--zone=public--add-port=80/tcp--permanent

Firewall-cmd--zone=public--add-port=3306/tcp--permanent

Firewall-cmd--zone=public--add-port=8080/tcp--permanent
Command meaning:
–zone #作用域
–add-port=80/tcp #添加端口 in the format: Port/Communication protocol
–permanent #永久生效, fail after reboot without this parameter
Restarting the firewall
Firewall-cmd--reload #重启firewall
Systemctl Stop Firewalld.service #停止firewall
Systemctl Disable Firewalld.service #禁止firewall开机启动

Turn off SELinux
Vi/etc/selinux/config
Comment out the following two sentences, add the last item
\ #SELINUX =enforcing #注释掉
\ #SELINUXTYPE =targeted #注释掉
Selinux=disabled #增加
: wq! Save exit
Enter the following command
Setenforce 0 #使配置立即生效

Getenforce View

Sestatus

Setenforce 0

Yum usage occurs during Yum setup:

Rm-f/var/run/yum.pid

First, install the httpd

sudo su-

Yum Install-y httpd

Second, start httpd service
After the installation is complete, start the HTTPD service with the following command:

#启动apache

Systemctl Start Httpd.service

#设置apache开机启动

Systemctl Enable Httpd.service

You can see the Apache welcome interface by entering the IP of the host where the server resides in the browser.

To implement this access on another host, you need to shut down the system's firewall.

You can only use the following command in CentOS7, if you use the above command and do not report any errors, but do not have the effect of shutting down the firewall:

Prevent firewall from booting up



Firewall open ports and services



Firewall-cmd--reload

Firewall-cmd--list-all
Third, install MySQL database

MySQL database, the new version has been renamed to MARIADB, so you need to install MARIADB, you can use the following command to install:

Yum install-y mariadb Mariadb-server
Iv. Opening the database service

1. After the installation is complete, use the following command to open the database service:
#启动MariaDB

Systemctl Start Mariadb.service

#重启MariaDB

Systemctl Restart Mariadb.service

#设置开机启动

Systemctl Enable Mariadb.service  

2. Configuring the MARIADB Character Set

Vim/etc/my.cnf.d/server.cnf

Add under the [Mysqld] tab
init_connect= ' SET collation_connection = Utf8_unicode_ci '
init_connect= ' SET NAMES UTF8 '
Character-set-server=utf8
Collation-server=utf8_unicode_ci
Skip-character-set-client-handshake

File/etc/my.cnf.d/client.cnf
Vi/etc/my.cnf.d/client.cnf

Add in [client]
Default-character-set=utf8
File/etc/my.cnf.d/mysql-clients.cnf
Vi/etc/my.cnf.d/mysql-clients.cnf
Add in [MySQL]
Default-character-set=utf8
Complete configuration, restart MARIADB
Systemctl Restart MARIADB
Then enter MARIADB to view the character set

Mysql-uroot-p Enter

Mysql> Show variables like "%character%", show variables like "%collation%";
The character set configuration is complete.

3. Add users, set permissions
Create user command
mysql>create user [email protected] identified by ' password ';
Direct creation of user and authorized commands
Mysql>grant all on * * to [e-mail protected] identified by ' password ';
Grant access to the extranet
Mysql>grant all privileges on * * to [e-mail protected] '% ' identified by ' password ';
Grant permissions and can authorize
Mysql>grant all privileges on * * to [e-mail protected] ' hostname ' identified by ' password ' with GRANT option;

Simple user and permission configuration is basically the case.
Where only partial permissions are granted to change all privileges or all to Select,insert,update,delete,create,drop,index,alter,grant,references,reload, Shutdown,process,file part of it.
Set the root account password
Mysql_secure_installation
Then enter y as you go.
After setting the root password, restart mariadb effective
Systemctl Restart Mariadb.service
Test Access database:
Mysql-uroot-p
show databases;
Fallback command:
Exit

V. Installation of PHP


Use 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

All the way "Y"

PHP--version

V. Restart MARIADB and HTTPD services:

Use the following command to restart the MARIADB and httpd services:

#重启MariaDB

#重启apache



vim/var/www/html/index.php, Content: <?php phpinfo (); ? >
Vi. installation of Nginx

To install Nginx on a CentOS system, you'll need to add a repository, like this:

Use the VIM command to open the/etc/yum.repos.d/nginx.repo, if the Nginx.repo does not exist, it will go to create a file like this, open the next click on the small I key, enter the editing mode, and then copy and paste the following lines of code, after the completion of pressing the ESC key to exit , then enter: Wq (save and exit)

[Nginx]name=nginx repobaseurl=http://nginx.org/packages/centos/$releasever/$basearch/gpgcheck=0enabled=1

When we're done, we can use the Yum command to install Nginx, like this:

Yum-y Install Nginx
由于安装了Httpd服务,所以要先停止,关闭apache之后再次启动nginx。

Stop httpd

Systemctl Stop Httpd.service

Test the Nginx service:

Systemctl Status Httpd.service

Test the Nginx configuration file:

Nginx-t

Return

Nginx:the configuration file/etc/nginx/nginx.conf syntax is oknginx:configuration file/etc/nginx/nginx.conf test is su Ccessful   

Description configuration file Successful!

Start Service:systemctl start Nginx.service

Boot start: Systemctl enable Nginx.service

Seven, configuration services

This is used by Nginx to do the reverse proxy, its client through the 80 port request of the. PHP content proxy to the Apache server.

To use Nginx to do reverse proxy, you need to modify the Apache httpd and nginx configuration files, so that they listen to different ports, here we use Nginx listening 80 port,

Using Apache listening 8080 port, here we configure the Apache and Nginx configuration files, the results are as follows:

(1) Apache configuration file:/etc/httpd/conf/httpd.conf

#Listen 12.34.56.78:80listen 8080

(2) Nginx configuration is as follows:/etc/nginx/conf.d/default.conf

# Proxy The PHP scripts to Apache listening in 127.0.0.1:80    # location    ~ \.php$ {      Proxy_pass   http://127.0. 0.1:8080;    }

(3) Do not specify 8080 ports to access the Nginx server:

http://localhost

(4) Specify 8080 ports to access the Apache server:

http://localhost:8080

(5) Specify 8080 ports to access mysql->mariadb under Apache server

Http://locahost:8080/phpmyadmin

Reference: http://www.kimsom.com/article/138

Http://www.jb51.net/article/68026.htm

Add Nginx Service:

Http://www.cnblogs.com/riverdubu/p/6426852.html

Centos7 Installing LNMP (Linux+nginx+mysql+php+phpmyadmin+apache)

Related Article

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.