CentOS7快速部署LNMP

LNMP介绍:
# LNMP代表的就是:Linux系统下Nginx+MySQL+PHP这种网站服务器架构。
# Linux是一类Unix计算机操作系统的统称,是目前最流行的免费操作系统。代表版本有:debian、centos、ubuntu、fedora、gentoo等。
# Nginx是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP代理服务器。
# Mysql是一个小型关系型数据库管理系统。
# PHP是一种在服务器端执行的嵌入HTML文档的脚本语言。
这四种软件均为免费开源软件,组合到一起,成为一个免费、高效、扩展性强的网站服务系统。
LNMP是什么?
是多个服务的一个组合:
L --- linux  
N --- nginx   处理用户的静态请求
M --- mysql   存储数据信息(文字字符)
P --- PHP     处理用户的动态请求
环境:CentOS 7.9   2C2G    10.0.0.10     (这里我选择yum安装整个架构)
1:更新源地址
	yum -y install epel-release && yum update -y
2:安装nginx
	yum -y install nginx
3:安装mysql源
	yum -y localinstall http://dev.mysql.com/get/mysql57-community-release-el7-7.noarch.rpm
4:安装MySQL5.7
	yum -y install mysql-community-server mysql-community-devel
	启动MySQL
	systemctl start mysqld
	systemctl enable mysqld
5:查看mysql的随机密码
	grep 'temporary password' /var/log/mysqld.log
6:进入mysql更改密码
	mysql -uroot -p'&4mq!Vl9N5qa'
	set global validate_password_policy=0;
	set global validate_password_length=1;
	ALTER USER 'root'@'localhost' IDENTIFIED BY 'password';
7:安装PHP源
	rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm 
	rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
8:安装PHP及依赖包
	yum install -y php71w php71w-cli php71w-common php71w-devel php71w-embedded php71w-gd php71w-mcrypt php71w-mbstring php71w-pdo php71w-xml php71w-fpm php71w-mysqlnd php71w-opcache php71w-pecl-memcached php71w-pecl-redis php71w-pecl-mongodb
9:查看PHP版本
	php -v
10:配置PHP
#修改php工作进程由nginx用户启动
vim /etc/php-fpm.d/www.conf

user = nginx
group = nginx

11:配置nginx
cat /etc/nginx/nginx.conf
user  nginx;
worker_processes  1;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    log_format main '$remote_addr - $remote_user [$time_local] "$request" '
                    '$status $body_bytes_sent "$http_referer" '
                    '"$http_user_agent" "$http_x_forwarded_for" ';
    access_log  /var/log/nginx/access.log  main;
    error_log  /var/log/nginx/error.log warn;

    server {
            listen       80;
            server_name  10.0.0.10;
            location / {
                root   html;
                index  index.html index.php;
            }
            location ~ \.php$ {
                root html;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                fastcgi_pass  127.0.0.1:9000;
                include fastcgi_params;
            }
    }
}
12:启动所有服务
systemctl start nginx
systemctl enable nginx

systemctl start php-fpm.service
systemctl enable php-fpm.service

13:测试PHP是否正常
cat << eof>>/usr/share/nginx/html/index.php
<?php
// Show all information, defaults to INFO_ALL
phpinfo();
// Show just the module information.
// phpinfo(8) yields identical results.
phpinfo(INFO_MODULES);
?>
eof

14:访问web测试

image

posted @ 2022-01-14 14:16  Layzer  阅读(71)  评论(0)    收藏  举报