002-CentOS网站搭建(一键搭建lnmp编译环境)

本文介绍了如何在CentOS系统中通过编写lnmp_install.sh脚本来自动化编译安装LNMP环境,包括创建可执行文件、编写脚本、创建nginx配置文件、执行安装脚本及验证安装成功的过程。
摘要由CSDN通过智能技术生成

002-CentOS网站搭建(一键搭建lnmp编译环境)

搭建思路
1、在CentOS中桌面创建一个可执行文件 lnmp_install.sh
2、将lamp编译环境自动化安装脚本编写到 lnmp_install.sh 3、在CentOS中桌面创建一个 nginx.txt 文件 4、将所需内容写入到 nginx.txt 文件中 5、执行lnmp_install.sh 6、检测环境是否安装成功

在CentOS中创建一个可执行文件 lnmp_install.sh

touch 桌面/lnmp_install.sh   在桌面创建 lnmp_install.sh
cd 桌面    将路径切换到桌面
ls   查看  lnmp_install.sh  是否创建成功

请添加图片描述

编写脚本代码到 lnmp_install.sh 中

用 vim 编辑器打开 lnmp_install.sh 文件

vim lnmp_install.sh    在执行此命令之前,先切换到 lnmp_install.sh 所在文件夹下,我这里是桌面

请添加图片描述

把脚本代码写入 lnmp_install.sh 保存好

#! bin/bash
systemctl stop firewalld&&systemctl disable firewalld&&setenforce 0&&(yum -y install  https://repo.ius.io/ius-release-el7.rpm | yum -y install  https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm)&&rpm -Uvh  https://mirror.webtatic.com/yum/el7/webtatic-release.rpm&&yum -y install php70w-devel php70w.x86_64 php70w-cli.x86_64 php70w-common.x86_64 php70w-gd.x86_64 php70w-ldap.x86_64 php70w-mbstring.x86_64 php70w-mcrypt.x86_64  php70w-pdo.x86_64   php70w-mysqlnd  php70w-fpm php70w-opcache php70w-pecl-redis php70w-pecl-mongodb&&yum install epel-release -y&&yum update -y&&yum install nginx -y&& wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm&&rpm -ivh mysql-community-release-el7-5.noarch.rpm&&yum install mysql-community-server -y&&cp  /etc/nginx/nginx.conf   /etc/nginx/nginx.conf.bak&&cat /root/桌面/nginx.txt > /etc/nginx/nginx.conf&&systemctl start nginx&&systemctl enable nginx&& systemctl start php-fpm&&systemctl enable php-fpm&&systemctl restart nginx&&systemctl restart php-fpm&&systemctl restart  mysqld&&mysql_secure_installation

请添加图片描述

在CentOS桌面中创建一个nginx.txt文件

touch 桌面/nginx.txt   在桌面创建 nginx.txt
cd 桌面    将路径切换到桌面
ls   查看  nginx.txt  是否创建成功

请添加图片描述

编写内容到 nginx.txt 中

用 vim 编辑器打开 nginx.txt 文件

vim nginx.txt    在执行此命令之前,先切换到 nginx.txt 所在文件夹下,我这里是桌面

请添加图片描述

把内容写入 nginx.txt 保存好

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;
events {
    worker_connections 1024;
}
http {
    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;
    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 4096;
    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;
    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;
server {
        listen       80;
        listen       [::]:80;
        server_name  _;
        root         /usr/share/nginx/html;
        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;
        location / {
            index index.php index.html index.htm;
        }
        location ~ .php$ {
            root /usr/share/nginx/html;
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_index index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include fastcgi_params;
        }
        error_page 404 /404.html;
        location = /404.html {
        }
        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
        }
    }
}

请添加图片描述

执行 lnmp_install.sh

执行 lnmp_install.sh 脚本

sh lnmp_install.sh  在执行此命令之前,先切换到 lnmp_install.sh 所在文件夹下,我这里是桌面

请添加图片描述

当执行到以下页面时说明脚本正在执行最后一条命令,输入y一直回车到输入密码,然后自己设定一个密码
请添加图片描述

设置密码并确认密码后,一直按回车,出现以下命令后说明安装成功
请添加图片描述

检测环境是否安装成功

在 /usr/share/nginx/html/ 文件夹下创建一个 phpinfio.php 文件

echo "<?php phpinfo(); ?>" > /usr/share/nginx/html/phpinfo.php 创建 phpinfio.php 文件并写入内容
cd /usr/share/nginx/html/   切换到网站根目录下
ls     查看是否创建 phpinfio.php 文件成功

请添加图片描述

查看IP地址

ifconfig

请添加图片描述

用浏览器访问上图ip,如果出现下面界面说明安装成功
请添加图片描述
网站搭建002-CentOS网站搭建(lamp和lnmp环境下的网站搭建)
将网站源码放到/usr/share/nginx/html/目录下,并给予所有权限,访问网站安装

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值