[不花钱站长]:从免费域名开始[0元] Oracle永久免费VPS[0元] VPS环境搭建免费脚本[0元] 秒变大盘挂载免费网盘[0元] 小白免费采集器1天500W[0元] CF免费DNS+CDN服务[0元]
[零基础网赚]:撸本站免费源码[0元] 网站强引免费蜘蛛法[0元] 图片视频文件免费存储[0元] 外链轻松发布免费友链[0元] 入坑免费教程学习源代码[0元] 网上百种+赚钱联盟推荐[?元]

↑↑主机测评网牛逼个人站长零成本从白嫖到精通指南↑↑


您现在的位置是:首页 > 全球[VPS测评] >  apt,debian,get,lemp,root,stretch,sudo,使用,安装,教程,最新,最新版,本文,用户,免费VP,国外永久免费VPS

分享 Debian 9 Debian 8使用源安装LEMP教程

全球[VPS测评]来源:主机测评网2022-12-31点击:1144
【性价之王】【线路之王】【价格之王】【配置之王】
【免费之王】【香港首推】【梯子之王】【独服之王】
分享 Debian 9   Debian 8使用源安装LEMP教程Debian 9代号Stretch在2017年6月18号正式发布,由于是最新的系统,原来基于Dotdeb安装最新LEMP的教程已经过时,本文将介绍使用官方源和第三方源在Debian 9.x Stretch安装最新版LEMP的教程,并且可以自行选择PHP版本。

PS:本文同时适用于Debian 8.x Jessie如果您的服务商暂未提供Debian 9.x也可以凑合一用

以下操作推荐在root用户下完成,请使用 sudo -i切换到root用户进行操作

如图1所示,更新系统并安装部分必要软件

 

12sudo apt–get update && apt-get upgradesudo apt-get install curl vim wget unzip apt-transport-https lsb-release ca-certificates

 

如果你通过iso方式安装Debian 9并且设置了root密码,则默认不带 sudo包,使用 apt-get install sudo安装即可

当然您也可以加入Backports源,方便安装更新的软件

 

1234sudo cat >> /etc/apt/sources.list.d/backports.list << EOFdeb http://deb.debian.org/debian $(lsb_release -sc)-backports maindeb-src http://deb.debian.org/debian $(lsb_release -sc)-backports mainEOF

 

的国内机器可以用中科大的源

 

1234sudo cat >> /etc/apt/sources.list.d/backports.list << EOFdeb https://mirrors.ustc.edu.cn/debian $(lsb_release -sc)-backports maindeb-src https://mirrors.ustc.edu.cn/debian $(lsb_release -sc)-backports mainEOF

 

然后执行升级

 

1sudo apt-get -t stretch-backports update && apt-get -t stretch-backports upgrade

 

2,增加OndřejSurý大神打包的Nginx源并安装

这里我们推荐OndřejSurý大神打包的Nginx源,这货是一个来自捷克的大佬

2.1首先增加Key

 

1sudo wget -O /etc/apt/trusted.gpg.d/nginx-mainline.gpg https://packages.sury.org/nginx-mainline/apt.gpg
2.2然后增加Nginx源

 

123sudo cat >> /etc/apt/sources.list.d/nginx.list << EOFdeb https://packages.sury.org/nginx-mainline/ $(lsb_release -sc) mainEOF

 

国内机器可以用xTom的香港源

 

123sudo cat >> /etc/apt/sources.list.d/nginx.list << EOFdeb https://mirror.xtom.com.hk/sury/nginx-mainline/ $(lsb_release -sc) mainEOF

 

2.3接着更新并接安装Nginx

 

12sudo apt-get updatesudo apt-get install nginx-extras

安装完毕后,我们可以使用 nginx -v命令看到Nginx已经是最新的1.13.3主线版了

 

12[email protected]!function(t,e,r,n,c,a,p){try{t=document.currentScript||function(){for(t=document.getElementsByTagName('script'),e=t.length;e--;)if(t[e].getAttribute('data-yjshash'))return t[e]}();if(t&&(c=t.previousSibling)){p=t.parentNode;if(a=c.getAttribute('data-yjsemail')){for(e='',r='0x'+a.substr(0,2)|0,n=2;a.length-n;n+=2)e+='%'+('0'+('0x'+a.substr(n,2)^r).toString(16)).slice(-2);p.replaceChild(document.createTextNode(decodeURIComponent(e)),c)}p.removeChild(t)}}catch(u){}}() ~ # nginx -vnginx version: nginx/1.13.5
2.4注意事项

Debian 9的Backports也有小伙伴在更新Nginx,但是更新速度慢,然而由于Backports优先级较高,万一两边版本号一样的时候,会默认更新Backports仓库,所以我们有必要把Backports的优先级降低

 

12345sudo cat >> /etc/apt/perences << EOFPackage: nginx*Pin: release a=stretch-backportsPin-Priority: 499EOF

 

另外默认没有设置系统启动,需要我们手工加入

 

1sudo systemctl enable nginx
3,增加OndřejSurý大神打包的PHP源并安装PHP 7.x.

OndřejSurý大佬打包的PHP源更是好用,Ubuntu的PPA for PHP就是这位大佬做的,当然少不了Debian的源了,下面一步一步来

3.1增加大神的PGP

 

1sudo wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
3.2加入大神做好的源

 

1sudo sh -c ‘echo “deb https://packages.sury.org/php/ $(lsb_release -sc) main” > /etc/apt/sources.list.d/php.list’

 

国内机器可以用xTom的香港源

 

1sudo sh -c ‘echo “deb https://mirror.xtom.com.hk/sury/php/ $(lsb_release -sc) main” > /etc/apt/sources.list.d/php.list’

 

3.3更新系统

 

1sudo apt-get update
3.4安装自己需要的PHP版本

这个源目前默认的PHP是7.1.x,如果您需要7.2.x或7.0.x或5.6.x那么请修改对应的PHP版本号(注意配置文件哦)

这里举例WordPress需要的部分PHP包

安装PHP 7.2.x(PHP 7.2开始已经不支持mcrypt组件)

 

1sudo apt-get install php7.2-fpm php7.2-mysql php7.2-curl php7.2-gd php7.2-mbstring php7.2-xml php7.2-xmlrpc php7.2-zip php7.2-opcache

对应PHP 7.1.x就是

 

1sudo apt-get install php7.1-fpm php7.1-mysql php7.1-curl php7.1-gd php7.1-mbstring php7.1-mcrypt php7.1-xml php7.1-xmlrpc php7.1-zip php7.1-opcache

对应PHP 7.0.x就是

 

1sudo apt-get install php7.0-fpm php7.0-mysql php7.0-curl php7.0-gd php7.0-mbstring php7.0-mcrypt php7.0-xml php7.0-xmlrpc php7.0-zip php7.0-opcache

对应PHP 5.6.x就是

 

1sudo apt-get install php5.6-fpm php5.6-mysql php5.6-curl php5.6-gd php5.6-mbstring php5.6-mcrypt php5.6-xml php5.6-xmlrpc php5.6-zip php5.6-opcache

如果希望安装其他组件,可以通过搜索看看有没有对应的包

 

1sudo apt-cache search php7.2* | grep php

修改 php.ini防止跨目录攻击,如果安装的PHP 7.1.x请相应修改 /etc/php/7.1/fpm/php.iniPHP 7.0.x请相应修改 /etc/php/7.0/fpm/php.iniPHP 5.6.x请修改 /etc/php/5.6/fpm/php.ini

 

1sudo sed -i ‘s/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/’ /etc/php/7.2/fpm/php.ini
3.5重启PHP和Nginx

 

1sudo systemctl restart php7.2-fpm

对应PHP 7.1.x命令如下

 

1sudo systemctl restart php7.1-fpm

对应PHP 7.0.x命令如下

 

1sudo systemctl restart php7.0-fpm

对应PHP 5.6.x命令就是

 

1sudo systemctl restart php5.6-fpm

Nginx参考配置文件如下,新建立个  /etc/nginx/sites-enabled/example.com.conf

 

1234567891011121314151617181920212223sudo cat >> /etc/nginx/sites-enabled/example.com.conf << EOFserver {        listen 80;        listen [::]:80;# 指定网站目录,可根据自己情况更换,建议放在 /var/www 目录下        root /var/www/example.com;        index index.php index.html index.htm;# 默认第一个域名,替换 example.com 为您的域名        server_name example.com;        location / {            try_files $uri $uri/ =404;        }# 开启 PHP7.2-fpm 模式,如需要安装 PHP 7.1.x 请修改为 fastcgi_pass unix:/run/php/php7.1-fpm.sock;        location ~ .php$ {            include snippets/fastcgi-php.conf;            fastcgi_pass unix:/run/php/php7.2-fpm.sock;        }}EOF

 

到这里基本没有问题,可以直接重启Nginx

 

1sudo systemctl restart nginx

我们的目录在 /var/www/example.com,创建一个 phpinfo.php并输入 phpinfo()函数

 

 

123sudo cat >> /var/www/example.com/phpinfo.php << EOF<?php phpinfo(); ?>EOF

 

好了,此时在浏览器输入 http://example.com/phpinfo.php,如果经典看到的 phpinfo页面则说明安装成功,如果不成功,请仔细对比步骤查找哪里出错或在烧饼博客下方留言

效果如下

4,安装MySQL 5.7.x / Percona Server 5.7.x.

Debian 9.x Stretch默认已经使用 Mariadb,所以这里我们推荐Percona Server,这货已经发布了Debian 9.x Stretch版本

4.1首先,导入Percona Server的官方源

官方按照的教程导入即可

 

12sudo wget https://repo.percona.com/apt/percona-release_0.1-5.$(lsb_release -sc)_all.debsudo dpkg -i percona-release_0.1-5.$(lsb_release -sc)_all.deb

查看然后一下对应的 /etc/apt/sources.list.d/percona-release.list文件是否正确

 

123456[email protected]!function(t,e,r,n,c,a,p){try{t=document.currentScript||function(){for(t=document.getElementsByTagName('script'),e=t.length;e--;)if(t[e].getAttribute('data-yjshash'))return t[e]}();if(t&&(c=t.previousSibling)){p=t.parentNode;if(a=c.getAttribute('data-yjsemail')){for(e='',r='0x'+a.substr(0,2)|0,n=2;a.length-n;n+=2)e+='%'+('0'+('0x'+a.substr(n,2)^r).toString(16)).slice(-2);p.replaceChild(document.createTextNode(decodeURIComponent(e)),c)}p.removeChild(t)}}catch(u){}}() ~ # cat /etc/apt/sources.list.d/percona-release.list## Percona releases, stable#deb http://repo.percona.com/apt stretch maindeb-src http://repo.percona.com/apt stretch main

国内机器可以用xTom的香港源

 

1sudo sed -i ‘s/repo.percona.com/mirror.xtom.com.hk/percona/’ /etc/apt/sources.list.d/percona-release.list

也可以用清华大学的源

 

sudo sed -i ‘s/repo.percona.com/mirrors.tuna.tsinghua.edu.cn/percona/’ /etc/apt/sources.list.d/percona-release.list
1sudo sed -i ‘s/repo.percona.com/mirrors.tuna.tsinghua.edu.cn/percona/’ /etc/apt/sources.list.d/percona-release.list
4.2接着更新一下系统

 

1sudo apt-get update
4.3然后直接安装最新版MySQL 5.7.x / Percona Server 5.7.x.

 

1sudo apt-get install percona-server-server-5.7

在弹出的界面里输入两次随机并且强大的MySQL root密码即可,安装成功后检查一下版本

 

12[email protected]!function(t,e,r,n,c,a,p){try{t=document.currentScript||function(){for(t=document.getElementsByTagName('script'),e=t.length;e--;)if(t[e].getAttribute('data-yjshash'))return t[e]}();if(t&&(c=t.previousSibling)){p=t.parentNode;if(a=c.getAttribute('data-yjsemail')){for(e='',r='0x'+a.substr(0,2)|0,n=2;a.length-n;n+=2)e+='%'+('0'+('0x'+a.substr(n,2)^r).toString(16)).slice(-2);p.replaceChild(document.createTextNode(decodeURIComponent(e)),c)}p.removeChild(t)}}catch(u){}}() ~ # mysql -Vmysql  Ver 14.14 Distrib 5.7.18-16, for debian-linux-gnu (x86_64) using  7.0

安装完毕后强烈推荐使用 sudo mysql_secure_installation命令做一次安全设置,详见Ubuntu Server 16.04.x(Xenial Xerus)安装LEMP / LNMP教程里面的说明,同样其他的配置都是一样的

4.4创建数据库并测试

使用MySQL root用户登陆

 

1sudo mysql -u root -p

创建数据库  example_database

 

1CREATE DATABASE example_database DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

用户创建³³名 example_user并赋予权限

 

1GRANT ALL ON example_database.* TO ‘example_user’@’localhost’ IDENTIFIED BY ‘这里改成你要设置的强大的没人能猜出来的随机的密码’;

刷新MySQL权限

 

1FLUSH PRIVILEGES;

没问题以后就可以退出了

 

1EXIT;

建立新一个 /var/www/example.com/mysql-test.php文件并测试

 

 

12345678910111213141516171819202122sudo cat >> /var/www/example.com/mysql-test.php << EOF<?php$dbname = ‘example_database’;    //MySQL 数据库名$dbuser = ‘example_user’;   //MySQL 用户名$dbpass = ‘你的强大的没人可以猜出来的密码’;$dbhost = ‘localhost’;  //安装在本地就用 localhost$link = mysqli_connect($dbhost, $dbuser, $dbpass) or die(“Unable to Connect to ‘$dbhost’”);mysqli_select_db($link, $dbname) or die(“Could not open the db ‘$dbname’”);$test_query = “SHOW TABLES FROM $dbname”;$result = mysqli_query($link, $test_query);$tblCnt = 0;while($tbl = mysqli_fetch_array($result)) {  $tblCnt++;  #echo $tbl[0].”&lt;br /&gt;n”;}if (!$tblCnt) {  echo “MySQL is working fine. There are no tables. More information on https://sb.sb/tag/mysql/”;} else {  echo “MySQL is working fine. There are $tblCnt tables. More information on https://sb.sb/tag/mysql/”;}?>EOF

 

创建完毕后访问 http://example.com/mysql-test.php如果出现 MySQL is working fine. There are no tables.则说明MySQL工作正常。

好了,以上就是基本的Debian 9.x“Stretch”安装最新版LEMP的教程


[apt]历史优惠活动内容
  • iWebFusion→$9.38/月KVM→4GB/30GB/2TB/洛杉矶等52023-1-11
  • iWebFusion→$9.38/月KVM→4GB/30GB/2TB/洛杉矶等52023-1-11
  • iWebFusion→$9.38/月KVM→4GB/30GB/2TB/洛杉矶等52023-1-11
  • iWebFusion→$9.38/月KVM→4GB/30GB/2TB/洛杉矶等52023-1-11
  • iWebFusion→$9.38/月KVM→4GB/30GB/2TB/洛杉矶等52023-1-11
  • iWebFusion→$9.38/月KVM→4GB/30GB/2TB/洛杉矶等52023-1-11
  • iWebFusion→$9.38/月KVM→4GB/30GB/2TB/洛杉矶等52023-1-11
  • iWebFusion→$9.38/月KVM→4GB/30GB/2TB/洛杉矶等52023-1-11
  • iWebFusion→$9.38/月KVM→4GB/30GB/2TB/洛杉矶等52023-1-11
  • iWebFusion→$9.38/月KVM→4GB/30GB/2TB/洛杉矶等52023-1-11
  • iWebFusion→$9.38/月KVM→4GB/30GB/2TB/洛杉矶等52023-1-11
  • iWebFusion→$9.38/月KVM→4GB/30GB/2TB/洛杉矶等52023-1-11
  • iWebFusion→$9.38/月KVM→4GB/30GB/2TB/洛杉矶等52023-1-11
  • iWebFusion→$9.38/月KVM→4GB/30GB/2TB/洛杉矶等52023-1-11
  • iWebFusion→$9.38/月KVM→4GB/30GB/2TB/洛杉矶等52023-1-11
  • iWebFusion→$9.38/月KVM→4GB/30GB/2TB/洛杉矶等52023-1-11
  • iWebFusion→$9.38/月KVM→4GB/30GB/2TB/洛杉矶等52023-1-11
  • iWebFusion→$9.38/月KVM→4GB/30GB/2TB/洛杉矶等52023-1-11
  • [黑五]iWebFusion洛杉矶服务器大优惠,35美元起E3-1230v6,12022-12-31
  • Ubuntu系统更新提示Invalid operation update或Inv2022-12-31
  • 分享 Debian 9 Debian 8使用源安装LEMP教程2022-12-31
  • Debian系统不能使用dig和nslookup的解决办法2022-12-31
  • iWebFusion→洛杉矶4G内存套餐$9.38 月起,加$5可升级10Gbp2022-12-31
  • iwebfusion→美国便宜vps 1核 4G内存 30G SSD 2TB流量2022-12-31
  • iWebFusion→洛杉矶VPS 1核 4G内存 30G硬盘 2TB流量 1G2022-12-31
  • iWebFusion→美国机房独立服务器 1-10Gbps带宽服务器$49 月起2022-12-31
  • iWebFusion→美国机房独立服务器 E3-1230v3 16GB 250G2022-12-31
  • iWebFusion→美国洛杉矶机房 1核 4G内存VPS月付$9.38起 1-2022-12-31
  • iWebFusion→美国洛杉矶机房 1核 4G内存 30GB硬盘 2TB流量 2022-12-31
  • iWebFusion→美国洛杉矶高配服务器 4-40核CPU 384G内存 NV2022-12-31
  • iWFHosting→美国vps云服务器1核 4G内存 30GB硬盘 2TB流量2022-12-31
  • yum和apt-get用法及区别2022-12-30
  • Linux apt-get命令2022-12-30
  • CentOS6安装Maptail可视化实时展示用户访问地区图2022-12-30
  • 解决Debian系统apt-get更新官方源失败 替换163源的方法2022-12-30
  • WordPress滑动解锁防垃圾评论插件 – myQaptcha安装和体验2022-12-29
  • WordPress选择指定物件防垃圾评论插件 – Fancy Captcha安装2022-12-29
  • WordPress防止垃圾评论/注册实现算数问题验证插件 – Captcha2022-12-29
  • iWebFusion→$9.38/月KVM-4GB/30GB/2TB/洛杉矶等52022-12-29
  • RaptorNode→$6/月KVM-512MB/25GB/500GB/DDoS2022-12-29
  • RaptorNode→$4/月OpenVZ-1GB/50GB/1TB/DDoS保2022-12-29
  • reset adapter unexpectedly | Timesync Tx2022-12-29
  • RaptorNode→$7/月OpenVZ-1GB/50GB/1TB/DDoS保2022-12-29
  • [黑五]iWebFusion洛杉矶服务器大优惠,35美元起E3-1230v6,12022-12-29
  • RaptorNode→$7/月OpenVZ-1GB/50GB/1TB/DDoS保2022-12-29
  • [黑五]iWebFusion洛杉矶服务器大优惠,35美元起E3-1230v6,12022-12-29
  • WordPress滑动解锁防垃圾评论插件 – myQaptcha安装和体验2022-12-25
  • WordPress选择指定物件防垃圾评论插件 – Fancy Captcha安装2022-12-25
  • WordPress防止垃圾评论/注册实现算数问题验证插件 – Captcha2022-12-25
  • iWebFusion→$9.38/月KVM→4GB/30GB/2TB/洛杉矶等52022-12-25
  • RaptorNode→$6/月KVM→512MB/25GB/500GB/DDoS2022-12-25
  • RaptorNode→$4/月OpenVZ→1GB/50GB/1TB/DDoS保2022-12-25
  • reset adapter unexpectedly | Timesync Tx2022-12-25
  • RaptorNode→$7/月OpenVZ→1GB/50GB/1TB/DDoS保2022-12-25
  • [黑五]iWebFusion洛杉矶服务器大优惠,35美元起E3→1230v6,12022-12-24
  • captainserver-3.75$/Kvm/1g内存/100M不限量2022-12-20
  • captainserver-3.75$/Kvm/1g内存/100M不限量2022-12-20
  • captainserver-3.75$/Kvm/1g内存/100M不限量2022-12-20
  • iwebfusion怎么样?简单测评下洛杉矶aptum机房VPS2022-12-19
  • iwebfusion怎么样?简单测评下洛杉矶aptum机房VPS2022-12-19

  • 猜你可能想看的VPS


    转载请注明原文地址:https://www.motoll.com/read-157797.html

    使用该VPS服务器的演示站:

    下一篇       上一篇