LNMP安装步骤详细教程以及一键部署脚本
LNMP安装步骤详细教程以及一键部署lnmp脚本
安装包
提取码:1w3t
文章目录
一、安装 Nginx 服务
二、安装 MySQL 服务
三、安装配置 PHP 解析环境
四、一键部署LNMP脚本
一、安装 Nginx 服务
1、关闭防火墙
systemctl stop firewalld
systemctl disable firewalld
setenforce 0
1
2
3
4
5
2、安装依赖包
yum -y install pcre-devel zlib-devel gcc gcc-c++ make
1
2
3
3、创建运行用户
useradd -M -s /sbin/nologin nginx
1
2
3
4、编译安装
cd /opt
tar zxvf nginx-1.12.0.tar.gz -C /opt/
cd nginx-1.12.0/
./configure
–prefix=/usr/local/nginx
–user=nginx
–group=nginx
–with-http_stub_status_module
make && make install
1
2
3
4
5
6
7
8
9
10
11
12
13
5、优化路径
ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/
1
2
6、添加 Nginx 系统服务
vim /lib/systemd/system/nginx.service
[Unit]
Description=nginx
After=network.target
[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
1
2
3
4
5
6
7
8
9
10
11
12
13
chmod 754 /lib/systemd/system/nginx.service
systemctl start nginx.service
systemctl enable nginx.service
1
2
3
二、安装 MySQL 服务
1、安装Mysql环境依赖包
yum -y install
ncurses
ncurses-devel
bison
cmake
1
2
3
4
5
6
2、创建运行用户
useradd -M -s /sbin/nologin mysql
1
2
3、编译安装
cd /opt
tar zxvf mysql-boost-5.7.20.tar.gz
1
2
cd /opt/mysql-5.7.20/
1
cmake
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock
-DSYSCONFDIR=/etc
-DSYSTEMD_PID_DIR=/usr/local/mysql
-DDEFAULT_CHARSET=utf8
-DDEFAULT_COLLATION=utf8_general_ci
-DWITH_EXTRA_CHARSETS=all
-DWITH_INNOBASE_STORAGE_ENGINE=1
-DWITH_ARCHIVE_STORAGE_ENGINE=1
-DWITH_BLACKHOLE_STORAGE_ENGINE=1
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1
-DMYSQL_DATADIR=/usr/local/mysql/data
-DWITH_BOOST=boost
-DWITH_SYSTEMD=1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
make -j 4 && make install
1
4、修改mysql 配置文件
vim /etc/my.cnf
1
2
[client]
port = 3306
socket=/usr/local/mysql/mysql.sock
[mysqld]
user = mysql
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
port = 3306
character-set-server=utf8
pid-file = /usr/local/mysql/mysqld.pid
socket=/usr/local/mysql/mysql.sock
bind-address = 0.0.0.0
skip-name-resolve
max_connections=2048
default-storage-engine=INNODB
max_allowed_packet=16M
server-id = 1
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_AUTO_VALUE_ON_ZERO,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,PIPES_AS_CONCAT,ANSI_QUOTES
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
5、更改mysql安装目录和配置文件的属主属组
chown -R mysql:mysql /usr/local/mysql/
chown mysql:mysql /etc/my.cnf
1
2
3
6、设置路径环境变量
echo ‘export PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH’ >> /etc/profile
source /etc/profile
1
2
3
7、初始化数据库
cd /usr/local/mysql/bin/
mysqld
–initialize-insecure
–user=mysql
–basedir=/usr/local/mysql
–datadir=/usr/local/mysql/data
1
2
3
4
5
6
7
8、添加mysqld系统服务
cp /usr/local/mysql/usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/
systemctl daemon-reload
systemctl start mysqld.service
systemctl enable mysqld
1
2
3
4
5
9、修改mysql 的登录密码
mysqladmin -u root -p password “abc123”
1
2
10、授权远程登录
mysql -u root -p
1
2
三、安装配置 PHP 解析环境
1、安装环境依赖包
yum -y install gd
libjpeg libjpeg-devel
libpng libpng-devel
freetype freetype-devel
libxml2 libxml2-devel
zlib zlib-devel
curl curl-devel
openssl openssl-devel
1
2
3
4
5
6
7
8
9
2、编译安装
cd /opt
tar xjvf php-7.1.10.tar.bz2
1
2
3
cd php-7.1.10
1
./configure
–prefix=/usr/local/php
–with-mysql-sock=/usr/local/mysql/mysql.sock
–with-mysqli
–with-zlib
–with-curl
–with-gd
–with-jpeg-dir
–with-png-dir
–with-freetype-dir
–with-openssl
–enable-fpm
–enable-mbstring
–enable-xml
–enable-session
–enable-ftp
–enable-pdo
–enable-tokenizer
–enable-zip
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
make -j 4 && make install
1
3、路径优化
ln -s /usr/local/php/bin/* /usr/local/bin/
1
2
4、调整PHP配置文件
php有三个配置文件:
php.ini 主配置文件
php-fpm.conf 进程服务配置文件
www.conf 扩展配置文件
1
2
3
4
5
调整主配置文件:
cp /opt/php-7.1.10/php.ini-development /usr/local/php7/php.ini
vim /usr/local/php7/php.ini
–1170行–修改
mysqli.default_socket = /usr/local/mysql/mysql.sock
–939行–取消注释,修改
date.timezone = Asia/Shanghai
php -m #验证安装的模块
1
2
3
4
5
6
7
8
9
调整进程服务配置文件:
cd /usr/local/php/etc/
cp php-fpm.conf.default php-fpm.conf
vim php-fpm.conf
–17行–去掉";"注释
pid = run/php-fpm.pid
1
2
3
4
5
6
调整扩展配置文件:
cd /usr/local/php/etc/php-fpm.d/
cp www.conf.default www.conf
1
2
3
5、启动php-fpm
/usr/local/php/sbin/php-fpm -c /usr/local/php/lib/php.ini
1
2
#PHP-FPM(FastCGI Process Manager:FastCGI 进程管理器)是一个 PHPFastCGI 管理器, 由于Nginx服务器不能处理动态页面,需要由 Nginx 把动态请求交给 php-fpm 进程进行解析。
1
6、配置 Nginx 支持 PHP 解析
vim /usr/local/nginx/conf/nginx.conf
–65行–取消注释,修改
location ~ .php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name; #将/scripts修改为nginx的工作目录
include fastcgi_params;
}
systemctl restart nginx.service
1
2
3
4
5
6
7
8
9
10
11
12
7、验证PHP 测试页
vim /usr/local/nginx/html/index.php
<?php phpinfo(); ?>
1
2
3
4
5
浏览器访问
http://192.168.126.10/index.php
1
2
8、验证数据库工作是否正常
mysqladmin -u root -p password “abc123”
mysql -u root -p
1
2
CREATE DATABASE bbs;
GRANT all ON bbs.* TO ‘bbsuser’@’%’ IDENTIFIED BY ‘admin123’;
GRANT all ON bbs.* TO ‘bbsuser’@‘localhost’ IDENTIFIED BY ‘admin123’;
flush privileges;
1
2
3
4
vim /usr/local/nginx/html/index.php #替换原来的测试页内容
1
<?php $link=mysqli_connect('192.168.126.20','bbsuser','admin123'); if($link) echo "
Success!!
"; else echo "Fail!!"; ?>
1
2
3
4
5
浏览器访问
http://192.168.126.10/index.php
1
2
3
四、一键部署LNMP脚本
#!bin/bash
#创建在线yum源
mkdir -p /etc/yum.repos.d/repo.bak && mv /etc/yum.repos.d/* /etc/yum.repos.d/repo.bak 2>1&>/dev/null
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo 2>1&>/dev/null
yum clean all 2>1&>/dev/null
yum list 2>1&>/dev/null
#关闭防火墙,将安装Apache所需软件包传到/opt目录下
systemctl stop firewalld
systemctl disable firewalld
setenforce 0
#安装依赖包
yum -y install pcre-devel zlib-devel gcc gcc-c++ make
#创建运行用户、组(Nginx 服务程序默认以 nobody 身份运行,建议为其创建专门的用户账号,以便更准确地控制其访问权限)
useradd -M -s /sbin/nologin nginx
#编译安装Nginx
cd /opt
tar zxvf nginx-1.12.0.tar.gz
cd nginx-1.12.0/
./configure
–prefix=/usr/local/nginx
–user=nginx
–group=nginx
–with-http_stub_status_module
make && make install
#让系统识别nginx的操作命令
ln -s /usr/local/nginx/sbin/* /usr/local/sbin/
#添加 Nginx 系统服务
cat > /lib/systemd/system/nginx.service << EOF
[Unit]
Description=nginx
After=network.target
[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStart=/usr/local/nginx/sbin/nginx
ExecrReload=/bin/kill -s HUP $MAINPID
ExecrStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
EOF
chmod 754 /lib/systemd/system/nginx.service
cp /usr/local/nginx/conf/nginx.conf{,.bak}
cat > /usr/local/nginx/conf/nginx.conf <<eof
user nginx;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#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 logs/access.log main;sendfile on;
#tcp_nopush on;#keepalive_timeout 0;
keepalive_timeout 65;#gzip on;server {listen 80;server_name localhost;#charset koi8-r;#access_log logs/host.access.log main;location / {root html;index index.html index.htm;}#error_page 404 /404.html;# redirect server error pages to the static page /50x.html#error_page 500 502 503 504 /50x.html;location = /50x.html {root html;}# proxy the PHP scripts to Apache listening on 127.0.0.1:80##location ~ \.php$ {# proxy_pass http://127.0.0.1;#}# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000#location ~ \.(php|php5)?$ {root html;fastcgi_pass 127.0.0.1:9000;fastcgi_index index.php;fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html\$fastcgi_script_name;include fastcgi_params;}# deny access to .htaccess files, if Apache's document root# concurs with nginx's one##location ~ /\.ht {# deny all;#}
}# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;# location / {
# root html;
# index index.html index.htm;
# }
#}# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;# location / {
# root html;
# index index.html index.htm;
# }
#}
}
eof
systemctl start nginx.service
systemctl enable nginx.service
#安装 MySQL 服务
#安装依赖包
cd /opt
yum -y install
ncurses
ncurses-devel
bison
cmake
#创建运行用户
useradd -M -s /sbin/nologin mysql
#编译安装
tar zxvf mysql-boost-5.7.20.tar.gz
cd /opt/mysql-5.7.20/
cmake
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock
-DSYSCONFDIR=/etc
-DSYSTEMD_PID_DIR=/usr/local/mysql
-DDEFAULT_CHARSET=utf8
-DDEFAULT_COLLATION=utf8_general_ci
-DWITH_EXTRA_CHARSETS=all
-DWITH_INNOBASE_STORAGE_ENGINE=1
-DWITH_ARCHIVE_STORAGE_ENGINE=1
-DWITH_BLACKHOLE_STORAGE_ENGINE=1
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1
-DMYSQL_DATADIR=/usr/local/mysql/data
-DWITH_BOOST=boost
-DWITH_SYSTEMD=1
make -j 4 && make install
cat > /etc/my.cnf<<EOF
[client]
port = 3306
socket=/usr/local/mysql/mysql.sock
[mysqld]
user = mysql
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
port = 3306
character-set-server=utf8
pid-file = /usr/local/mysql/mysqld.pid
socket=/usr/local/mysql/mysql.sock
bind-address = 0.0.0.0
skip-name-resolve
max_connections=2048
default-storage-engine=INNODB
max_allowed_packet=16M
server-id = 1
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_AUTO_VALUE_ON_ZERO,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,PIPES_AS_CONCAT,ANSI_QUOTES
EOF
#更改mysql安装目录和配置文件的属主属组
chown -R mysql:mysql /usr/local/mysql/
chown mysql:mysql /etc/my.cnf
#设置路径环境变量
echo ‘export PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH’ >> /etc/profile
source /etc/profile
#初始化数据库
cd /usr/local/mysql/bin/
mysqld
–initialize-insecure
–user=mysql
–basedir=/usr/local/mysql
–datadir=/usr/local/mysql/data
#添加mysqld系统服务
cp /usr/local/mysql/usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/
systemctl daemon-reload
systemctl start mysqld.service
systemctl enable mysqld
#修改mysql 的登录密码
function abc {
passwd=$1
/usr/bin/expect <<-EOF
spawn mysqladmin -u root -p password $passwd
expect “Enter password:”
send “\r”
expect eof
EOF
}
abc “abc123”
function bcd {
/usr/bin/expect <<-EOF
spawn mysql -u root -p
expect “Enter password:” {send “abc123\r”}
expect “mysql>” {send “grant all privileges on . to ‘root’@’%’ identified by ‘abc123’;\r”}
expect “mysql>” {send “show databases;\r”}
expect “mysql>” {send “quit\r”}
expect eof
EOF
}
bcd
echo -e “\033[31m mysql安装完成!\033[0m”
#安装配置 PHP 解析环境
#安装环境依赖包
cd /opt
yum -y install gd
libjpeg libjpeg-devel
libpng libpng-devel
freetype freetype-devel
libxml2 libxml2-devel
zlib zlib-devel
curl curl-devel
openssl openssl-devel
#编译安装
tar xjvf php-7.1.10.tar.bz2
cd php-7.1.10
./configure
–prefix=/usr/local/php
–with-mysql-sock=/usr/local/mysql/mysql.sock
–with-mysqli
–with-zlib
–with-curl
–with-gd
–with-jpeg-dir
–with-png-dir
–with-freetype-dir
–with-openssl
–enable-fpm
–enable-mbstring
–enable-xml
–enable-session
–enable-ftp
–enable-pdo
–enable-tokenizer
–enable-zip
make -j 4 && make install
#路径优化
ln -s /usr/local/php/bin/* /usr/local/bin/
#调整PHP配置文件
#php有三个配置文件:
#php.ini 主配置文件
#php-fpm.conf 进程服务配置文件
#www.conf 扩展配置文件
#调整主配置文件
cd /usr/local/
mkdir php7
cd php7
cp /opt/php-7.1.10/php.ini-development /usr/local/php7/php.ini
sed -i ‘1170d’ /usr/local/php7/php.ini
sed -i “1169a mysqli.default_socket = /usr/local/mysql/mysql.sock” /usr/local/php7/php.ini
sed -i ‘939d’ /usr/local/php7/php.ini
sed -i “938a date.timezone = Asia/Shanghai” /usr/local/php7/php.ini
#调整进程服务配置文件
cd /usr/local/php/etc/
cp php-fpm.conf.default php-fpm.conf
sed -i ‘17c pid = run/php-fpm.pid’ /usr/local/php/etc/php-fpm.conf
#调整扩展配置文件
cd /usr/local/php/etc/php-fpm.d/
cp www.conf.default www.conf
#启动php-fpm
/usr/local/php/sbin/php-fpm -c /usr/local/php/lib/php.ini
#配置 Nginx 支持 PHP 解析
#安装nginx已修改好
systemctl restart nginx.service
#验证PHP 测试页
cat > /usr/local/nginx/html/index.php<<EOF
<?php phpinfo(); ?>
EOF
LNMP安装步骤详细教程以及一键部署脚本相关推荐
- IntelliJ IDEA(2020.3)的下载、安装步骤详细教程
IntelliJ IDEA(2020.3)的下载.安装教程 本文大致介绍了IntelliJ IDEA(2020.3)的下载.安装教程供小白编程爱好者借鉴,因为我也是学习者,这只是我自己的观点,如有错误 ...
- window安装Stable-Diffusion-WebUI详细教程
直接上效果图,这是通过stable diffusion webui 利用古风模型生成的图片,实在是太好看了!!! 看了这些图,有没有心痒痒的?今天就来带大家入个门!先把软件搞起来 ! [前言] Sta ...
- Ubuntu16.04在线安装MongoDB详细教程
Ubuntu16.04在线安装MongoDB详细教程 文章目录 Ubuntu16.04在线安装MongoDB详细教程 前言 安装流程 信任MongoDB公钥 创建列表文件 安装MongoDB 常见问题 ...
- 【转】Ubuntu16.04安装 Matlab2018a详细教程
转自:[Ubuntu]安装 Matlab2018a详细教程_My Blogs-CSDN博客_matlab2018a安装教程 Matlab2018a安装包下载: 链接: 百度网盘 请输入提取码 提取码: ...
- 源码编译安装Apache-附一键部署脚本
1.进入apache官网https://www.apache.org/,点击Download 2.如图选择 3.选择httpd 4.下载两个包,2.2为CentOS6使用,2.4为CentOS7使用 ...
- win10安装Tomcat10详细教程
win10安装Tomcat10详细教程 提示:安装Tomcat前需要本机有java环境,如未有java环境的,可以先参考此篇博文: win10安装JDK1.8详细教程. 文章目录 win10安装Tom ...
- Cent OS虚拟机安装最新详细教程
Cent OS虚拟机安装最新详细教程 一,先下载Cent OS镜像 Tips: 所有需要下载的软件都可以再 我的 资源 里面找到 选择国内镜像下载比较快 阿里镜像: 附上地址http://mirror ...
- lnmp一键部署脚本
LNMP一键部署脚本 LNMP代表的是:linux系统下 nginx+mysql+php 网站服务器架构 一键部署的意思是,执行脚本,解决所有依赖关系,没有报错.脚本执行完成,环境部署完成 所以在做一 ...
- MacOS 软件 Adobe Illustrator 2022 - AI 安装使用详细教程
MacOS 软件 Adobe Illustrator 2022 - AI 安装使用详细教程 一个领先的矢量图形设计应用程序 ➤ 前往下载 ⇲ 该软件属于顶流产品,不过多介绍了,下面直接上安装教程 安装 ...
最新文章
- Win10+Python+Django+Nginx+MySQL开发教程及实例(1)——开发环境搭建
- Pat乙级 1058 选择题
- 洛阳理工Linux实验报告,洛阳理工学院实验报告.doc
- 基于动态IP的Internet视频监控解决方案(作者:吴晓晖)
- PHP培训选云和数据,送给云和数据郑州分中心PHP培训班全体学员的祝福
- (一)nodejs循序渐进-nodejs环境安装(基础篇)
- 2022年科技与IT十大趋势
- PHP:ServerPush (Comet推送) 技术的探讨
- 温度转换的python程序_人生苦短,请用Python!
- linux下搭建python机器学习环境
- 当代研究生应当掌握的并行训练方法(单机多卡)
- PHP+MySQL制作简单动态网站(附详细注释+源码)
- 八达岭长城 景区 导游图 、地图、大图、高清、超高清
- ajax 点击下一页,ajax调用不会进入下一页
- matlab解坐标方程,matlab程序(解泊松方程)
- OA系统,满足各行业办公所需的管理软件
- matlab系统辨识工具箱原理,matlab常用工具箱介绍
- [2018][PAMI]Deep Self-Evolution Clustering 笔记
- 【Ware】免费的格式转换软件推荐
- 基于神经网络的自适应最优控制