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/目录下,并给予所有权限,访问网站安装