CentOS yum by LNMP environment to build

EDITORIAL

This paper describes the lnmp environment to build, the article may have many shortcomings, please understand, welcome Gangster comments.

As used herein, the thing

  1. CentOS 7
  2. Nginx 1.16.1
  3. Mysql 5.6.46
  4. PHP 7.2.24

1.LNMP Profile

L: Linux computer operating system
N: Nginx high performance HTTP server and reverse proxy
M: Mysql relational database system
P: the PHP scripting language embedded

2. Install Nginx

1. Enter the following command to install Nginx

yum install -y nginx

If you do not see the situation of available packages yum install package prompts not available

2. Start

//启动Nginx
sudo systemctl start nginx.service

//设置开机自动运行
sudo systemctl enable nginx.service

3. Verify that
your browser and enter the address of the host you can show " welcome nginx" interface can, and sometimes will show " welcome of CentOS" because nginx index.html in the directory pointed to welcome of CentOS html file by default.
Here Insert Picture Description
nginx installing, the specific configuration not described in detail here

3. Install Mysql

1. Enter the following three commands in sequence command to install Mysql, installation will replace mariadb

wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm

yum -y install mysql-community-release-el7-5.noarch.rpm

yum -y install mysql-community-server

2. Start

//启动mysql
systemctl start  mysqld.service

//查看运行状态
systemctl status  mysqld.service

Here Insert Picture Description

3. Add the boot from the start
to see if mysql has the boot from the start

//查看开机自启
systemctl list-unit-files|grep enabled

Here Insert Picture Description
If you do not boot from the start by entering the following command to add

sudo systemctl enable mysql.service
sudo systemctl enable mysqld.service

4. Check password

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

5. Change Password

I am here appeared log file without a password, if there is no password, just press Enter to skip while waiting to enter the password

//登录mysql,输入刚才查看到的密码
mysql -uroot -p

//修改密码
set password for root@localhost = password('361654768');

6. Allow all ip access

//让防火墙通过mysql的3306端口
sudo firewall-cmd --zone=public --add-port=3306/tcp --permanent

//重启防火墙生效配置
service firewalld restart

//修改权限
grant all privileges on *.* to root@'%' identified by 'root';

//使修改生效
FLUSH PRIVILEGES;

4. Install PHP

1. Install

//添加php的源
yum localinstall https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

//安装php及其插件
yum -y install php72w php72w-cli php72w-common php72w-devel php72w-embedded php72w-fpm php72w-gd php72w-mbstring php72w-mysqlnd php72w-opcache php72w-pdo php72w-xml

2. Start

//启动php
systemctl start php-fpm

//查看版本
php -v

//添加开机自启动
sudo systemctl enable php-fpm.service

5.Nginx proxy PHP

1. " /etc/nginx/conf.d" create a directory " php.conf" file, add the following

server {
        listen 80;
        server_name php.nineya.com;
        index index.php;
        root /usr/share/nginx/php;
        location ~ \.php$ {
                fastcgi_pass  127.0.0.1:9000;
                fastcgi_index  index.php;
                fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
                include fastcgi_params;
    }
}

Here Insert Picture Description

2. Restart nginx configuration to take effect

//验证配置的正确性
nginx -t

//重启nginx
sudo systemctl restart nginx.service

Here Insert Picture Description

3. " /usr/share/nginx" create a directory " php" directory, in the " php" New directory " index.php" file, add the following to the file.

<?php phpinfo(); ?>

4. open firewall port 80

//让防火墙通过mysql的3306端口
sudo firewall-cmd --zone=public --add-port=80/tcp --permanent

//重启防火墙生效配置
service firewalld restart

5. If you make more than centOS operations on a virtual machine, you need to modify the device to access the web page of the hosts file, so that the domain name specified point to the virtual machine ip

//修改hosts文件
vim /etc/hosts

//添加以下内容
虚拟机ip php.conf中设置的域名

如:
192.168.138.9 php.nineya.com

Here Insert Picture Description

6. Summary

About LNMP environment to build on the description here, more general steps might not detailed enough in some places, there will be some weird problem when the actual installation, there are any questions Comments are welcome, see I would reply. This article is over, what are deficiencies please feel free to correct me.

Published 38 original articles · won praise 17 · views 1219

Guess you like

Origin blog.csdn.net/nineya_com/article/details/103605872
Recommended