Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to build LNMP environment in CentOS7

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

In this article, the editor introduces in detail "how to build the LNMP environment in CentOS7". The content is detailed, the steps are clear, and the details are handled properly. I hope this article "how to build the LNMP environment in CentOS7" can help you solve your doubts.

After entering the command line, use the su command to switch to root permissions.

First configure the firewall

Centos 7.0 uses firewall as the firewall by default

1. Turn off firewall:

Systemctl stop firewalld.service # stop firewall systemctl disable firewalld.service # disable firewall boot

two。 Turn off selinux:

Vi / etc/selinux/config

# selinux=enforcing # comment out

Selinux=disabled # increased

: wq! # Save exit

Setenforce 0 # makes the configuration effective immediately

3. Install priorities and wget

Yum install yum-priorities-y yum- y install wget

1. Install mysql

Download the mysql source installation package

The copy code is as follows:

Wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm

Install the mysql source

The copy code is as follows:

Yum localinstall mysql57-community-release-el7-8.noarch.rpm

Check whether the MySQL source is installed successfully and pay attention to the period in the command.

The copy code is as follows:

Yum repolist enabled | grep "mysql.-community."

Install mysql

The copy code is as follows:

Yum install mysql-community-server

When you start the mysql service, it may be slower to start the service, due to different computer configurations.

The copy code is as follows:

Systemctl start mysqld

Check the startup status of mysql

The copy code is as follows:

Systemctl status mysqld

Boot up

Systemctl enable mysqld systemctl daemon-reload

Check the root local login password (this command will find out the default random password set by mysql, as shown below, my random password is t3e4woyyi=:y)

Grep 'temporary password' / var/log/mysqld.log

Log in to mysql through a random password (random passwords are difficult to read, more than a few times, I succeeded because I tried to read the wrong password twice)

Mysql-u root-p

Change the mysql login password (be careful not to leave out the semicolon, this is the statement of mysql, use exit to exit and log in again after modification)

Set password for 'root'@'localhost'= "chen123456."; exit

Note: mysql5.7 installs the password Security check plug-in (validate_password) by default. The default password check policy requires that passwords must contain uppercase and lowercase letters, numbers and special symbols, and must be no less than 8 digits in length. Otherwise, it prompts error 1819 (hy000): your password does not satisfy the current policy requirements error, as shown below:

Alter user 'root'@'localhost' identified by' mynewpass4percent'

Set password for 'root'@'localhost'=password (' mynewpass4percent')

You can view information about password policies through the msyql environment variable:

Mysql > show variables like'% password%'

If the above method cannot be modified, you can use the following security mode to modify root:

Shut down the service

Systemctl stop mysqld.service

Vi / etc/my.cnf

Add skip-grant-tables save to mysqld to exit the startup service

Systemctl start mysqld.service

Mysql-u root enter directly without a password.

Use mysql

Update user set authentication_string=password ('root-123') where user='root'and host='localhost'

Flush privileges

Exit

Vi / etc/my.cnf delete skip-grant-tables, save, exit and restart the mysql service

Systemctl restart mysqld.service

Just log in again.

Mysql-u root- proot-123

If you do this, the following prompt appears:

You must reset your password using alter user statement before executing thisstatement.

Just set the password again.

Set password = password ('root-123')

Open port 3306 (allows you to connect to the mysql server from any host using the username root password root-123456)

Mysql > grant all on root.* to root@'%' identified by'vmrootbacks: 456 vmrootbacks: MySQL > flush privileges;mysql > exit

Turn on external access to firewall mysql port 3306

Firewall-cmd-- zone=public-add-port=3306/tcp-permanentfirewall-cmd--reload

Configure the default encoding as utf8

Vi / etc/my.cnf

Modify the / etc/my.cnf configuration file and add the encoding configuration under [mysqld], as follows:

[mysqld] character_set_server=utf8init_connect='set names utf8'

Default profile path:

Configuration file: / etc/my.cnf

Log file: / var/log//var/log/mysqld.log

Service startup script: / usr/lib/systemd/system/mysqld.service

Socket file: / var/run/mysqld/mysqld.pid

If you want to use a firewall, it is recommended that you configure it using the following methods:

Turn off firewall:

Systemctl stop firewalld.service # stop firewallsystemctl disable firewalld.service # disable firewall boot

Install iptables Firewall:

Yum install iptables-services # install sudo vi / etc/sysconfig/iptables # Edit Firewall configuration File

The profile changes are as follows:

# firewall configuration written by system-config-firewall# manual customization of this file is not recommended.*filter:input accept [0:0]: forward accept [0:0]: output accept [0:0]-an input-m state-- state established Related-j accept-an input-p icmp-j accept-an input-I lo-j accept-an input-m state-- state new-m tcp-p tcp-- dport 22-j accept// below is the part added by the editor-an input-m state-- state new-m tcp-p tcp-dport 80-j accept-an input-m state-- state new-m tcp-p tcp-dport 3306-j accept// above is added by the editor-an input- J reject--reject-with icmp-host-prohibited-a forward-j reject--reject-with icmp-host-prohibitedcommit

Then enter: wq save exit, enter the following command in the command window to make it take effect:

Systemctl restart iptables.service # finally restart the firewall to make the configuration effective systemctl enable iptables.service # set the firewall to boot

2. Close selinux

Open the selinux configuration file by entering the following on the command line:

Sudo vi / etc/selinux/config

The modifications are as follows

# selinux=enforcing # comment out # selinuxtype=targeted # comment out selinux=disabled # add

Enter: wqquit # Save exit, and then enter the following on the command line to make it effective

Setenforce 0 # makes the configuration effective immediately

two。 Install php

Yum has a lower version of php installed by default, and this time, we are going to install the php5.6 version, so we need to install the epel library first and then install php.

Yum install epel-releaserpm-ivh http://rpms.famillecollet.com/enterprise/remi-release-7.rpmyum install-enablerepo=remi--enablerepo=remi-php56 php php-opcache php-fpm php-devel php-mbstring php-mcrypt php-mysqlnd php-phpunit-phpunit php-pecl-xdebug php-pecl-xhprof

Typing php-v after the installation is complete will show the version of php, which means that our php installation is complete.

Php-v

3. Install nginx

The copy code is as follows:

Wget http://nginx.org/packages/centos/7/noarch/rpms/nginx-release-centos-7-0.el7.ngx.noarch.rpm

Rpm-ivh nginx-release-centos-7-0.el7.ngx.noarch.rpm

Then start nginx

Systemctl start nginx.service # start nginx systemctl stop nginx.service # stop systemctl restart nginx.service # restart systemctl enable nginx.service # set boot

. Change the nginx port number (according to your own needs)

Cd / etc/nginx/conf.d/

Vim default.conf

Change listen 80 to listen 81

Then restart nginx

Systemctl restart nginx.service # restart nginx

Then we open the browser and visit localhost if there is a welcome to nginx! Then nginx is installed successfully.

The nginx installation is complete, so it's time to configure php-fpm. Let nginx and php link up.

Open the php-fpm configuration file

Sudo vi / etc/php-fpm.d/www.conf

Modify the following (when looking for configuration items here, you can use the slash plus the keyword you want to find, as shown in the following figure)

Listen.owner = nginxlisten.group = nginxlisten.mode = 0666

Finally, after modifying the three parameters: wq exits and then restarts the php-fpm service

Sudo systemctl start php-fpm # Startup php-fpmsudo systemctl enable php-fpm # Boot Startup fpm

Then, let's modify the configuration of nginx, first use the find command to find the location of the configuration file, my configuration file location is shown in the following figure

Find /-name nginx.conf

Then, use the vi command to enter the view, and on the last line, you find that this configuration file introduces other configuration files.

Vi / etc/nginx/nginx.conf

Enter this directory again and find the configuration file as shown below

Modify it using the vi command

Vi default.conf

Add a sibling under localhost, as shown in the following figure

Location ~\ .php$ {root / var/www/html; # specifies the root directory of php, fastcgi_pass 127.0.0.1

After modifying and saving, use the nginx-t command to confirm that the format is correct, and then restart nginx. As shown in the following figure

Nginx-tnginx-s reload

After that, under the php directory you just set up, create a new php file for testing.

Set up index.php in / var/www/html

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report