分享 Debian 9 Debian 8使用源安装LEMP教程
【性价之王】 | 【线路之王】 | 【价格之王】 | 【配置之王】 |
【免费之王】 | 【香港首推】 | 【梯子之王】 | 【独服之王】 |
PS:本文同时适用于Debian 8.x Jessie如果您的服务商暂未提供Debian 9.x也可以凑合一用
以下操作推荐在root用户下完成,请使用 sudo -i切换到root用户进行操作
如图1所示,更新系统并安装部分必要软件
12 | sudo 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源,方便安装更新的软件
1234 | sudo 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 |
的国内机器可以用中科大的源
1234 | sudo 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 |
然后执行升级
1 | sudo apt-get -t stretch-backports update && apt-get -t stretch-backports upgrade |
2,增加OndřejSurý大神打包的Nginx源并安装
这里我们推荐OndřejSurý大神打包的Nginx源,这货是一个来自捷克的大佬
2.1首先增加Key
1 | sudo wget -O /etc/apt/trusted.gpg.d/nginx-mainline.gpg https://packages.sury.org/nginx-mainline/apt.gpg |
123 | sudo cat >> /etc/apt/sources.list.d/nginx.list << EOFdeb https://packages.sury.org/nginx-mainline/ $(lsb_release -sc) mainEOF |
国内机器可以用xTom的香港源
123 | sudo cat >> /etc/apt/sources.list.d/nginx.list << EOFdeb https://mirror.xtom.com.hk/sury/nginx-mainline/ $(lsb_release -sc) mainEOF |
2.3接着更新并接安装Nginx
12 | sudo 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 |
Debian 9的Backports也有小伙伴在更新Nginx,但是更新速度慢,然而由于Backports优先级较高,万一两边版本号一样的时候,会默认更新Backports仓库,所以我们有必要把Backports的优先级降低
12345 | sudo cat >> /etc/apt/perences << EOFPackage: nginx*Pin: release a=stretch-backportsPin-Priority: 499EOF |
另外默认没有设置系统启动,需要我们手工加入
1 | sudo systemctl enable nginx |
OndřejSurý大佬打包的PHP源更是好用,Ubuntu的PPA for PHP就是这位大佬做的,当然少不了Debian的源了,下面一步一步来
3.1增加大神的PGP
1 | sudo wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg |
1 | sudo sh -c ‘echo “deb https://packages.sury.org/php/ $(lsb_release -sc) main” > /etc/apt/sources.list.d/php.list’ |
国内机器可以用xTom的香港源
1 | sudo sh -c ‘echo “deb https://mirror.xtom.com.hk/sury/php/ $(lsb_release -sc) main” > /etc/apt/sources.list.d/php.list’ |
3.3更新系统
1 | sudo apt-get update |
这个源目前默认的PHP是7.1.x,如果您需要7.2.x或7.0.x或5.6.x那么请修改对应的PHP版本号(注意配置文件哦)
这里举例WordPress需要的部分PHP包
安装PHP 7.2.x(PHP 7.2开始已经不支持mcrypt组件)
1 | sudo 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就是
1 | sudo 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就是
1 | sudo 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就是
1 | sudo 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 |
如果希望安装其他组件,可以通过搜索看看有没有对应的包
1 | sudo 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
1 | sudo sed -i ‘s/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/’ /etc/php/7.2/fpm/php.ini |
1 | sudo systemctl restart php7.2-fpm |
对应PHP 7.1.x命令如下
1 | sudo systemctl restart php7.1-fpm |
对应PHP 7.0.x命令如下
1 | sudo systemctl restart php7.0-fpm |
对应PHP 5.6.x命令就是
1 | sudo systemctl restart php5.6-fpm |
Nginx参考配置文件如下,新建立个 /etc/nginx/sites-enabled/example.com.conf
1234567891011121314151617181920212223 | sudo 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
1 | sudo systemctl restart nginx |
我们的目录在 /var/www/example.com,创建一个 phpinfo.php并输入 phpinfo()函数
123 | sudo 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的官方源官方按照的教程导入即可
12 | sudo 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的香港源
1 | sudo 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
1 | sudo sed -i ‘s/repo.percona.com/mirrors.tuna.tsinghua.edu.cn/percona/’ /etc/apt/sources.list.d/percona-release.list |
1 | sudo apt-get update |
1 | sudo 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用户登陆
1 | sudo mysql -u root -p |
创建数据库 example_database
1 | CREATE DATABASE example_database DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; |
用户创建³³名 example_user并赋予权限
1 | GRANT ALL ON example_database.* TO ‘example_user’@’localhost’ IDENTIFIED BY ‘这里改成你要设置的强大的没人能猜出来的随机的密码’; |
刷新MySQL权限
1 | FLUSH PRIVILEGES; |
没问题以后就可以退出了
1 | EXIT; |
建立新一个 /var/www/example.com/mysql-test.php文件并测试
12345678910111213141516171819202122 | sudo 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].”<br />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]历史优惠活动内容
猜你可能想看的VPS
- DEDECMS 数据库配置文件在哪?怎么修改 DEDECMS 数据库配置全球[VPS测评]
- THINKPHP5 在 php5.4 版本以上伪静态重写报错→No in全球[VPS测评]
- DogYun 新年动态云全场 7 折 抽奖送流量送折扣 香港&日本&德国日本VPS[主机]
- 双十二 raksmart→I3 独服仅$46 月 10G 口 不限买 1全球[VPS测评]
- DMIT 美国 CN2 特价 VPS→原生 IP 可 Netflix 1美国VPS[主机]
- SoftShellWeb→$12.99 年 256MB 内存 10GB 虚拟空间(主机)
- wget 下载 https 时报错 ERROR: The certifi全球[VPS测评]
- 抗投诉 €15 年 256M 内存 4G 硬盘 1Gbps 不限流量 K全球[VPS测评]
- 企鹅小屋→550 元 月 E5-26XX 16GB 内存 600GB 硬日本VPS[主机]
- 玩具鸡-hostsailor: $6.6 年 256G 流量 荷兰 VP全球[VPS测评]
- 腾讯云限时秒杀→上海 2G 内存 VPS 年付 198 元 云服务器 云全球[VPS测评]
- RackNerd圣诞节1.5g内存20g硬盘2.5T大流量年付仅16.8全球[VPS测评]
- 如何让WordPress网站的媒体库支持 SVG 图标的上传与预览全球[VPS测评]
- DMIT日本东京CN2GIA线路VPS八折优惠,$15.6起/月,CN2日本VPS[主机]
- 搬瓦工又一次关闭免费更换IP服务全球[VPS测评]
- Ouiheberg-3.59欧 月 1核2G内存30G硬盘 100M不限全球[VPS测评]
- Stratagem-2.25GBP每月 英国 1核512MB内存15GB全球[VPS测评]
- 20个温暖心灵的问题,抖音,朋友圈都可以拿去发。全球[VPS测评]
- 拼多多回应筹备跨境电商业务:不予置评全球[VPS测评]
- wordpress 上传附件报错 “抱歉,出于安全的考虑,不支持此文件类全球[VPS测评]
- 手帕云,便宜小带宽香港CN2 VPS,集群10G防御,双向CN2直连,仅香港VPS[主机]
- 咖啡主机:美国高防vps、香港vps 可享受6-7折促销 每月仅需14元美国VPS[主机]
- 跨境电商拔节生长关键期,宁波政协委员月谈会精准助力!全球[VPS测评]
- hosthatch:香港/芝加哥/伦敦等11机房VPS低至$17.5/年香港VPS[主机]
- 永恒云:江苏挂机宝6元/月,60元/年;香港建站vps仅18元;深圳BG香港VPS[主机]
- edgenat:韩国cn2+香港cn2,VPS八折优惠,8核8G/50gWINDOWS
- 腾讯云vps主机:288元/3年,1核/2G/50gSSD,北京/上海/美国VPS[主机]
- 极光KVM:新上香港CN2VPS,终身6折优惠,1核/1G/5Mbps,香港VPS[主机]
- 世界杯季疫情突发,跨境电商订单排队,义乌商人面临难题全球[VPS测评]
- 硅云:香港免备案云服务器仅232元/年;香港2核2G2M仅482元/年香港VPS[主机]
转载请注明原文地址:https://www.motoll.com/read-157797.html