Debian手动安装LNMPA环境及相关配置
LNMPA是指(Linux/Nginx/MySQL/PHP/Apache),是广泛使用的网站建站环境。以下将详细介绍手动安装上述环境的方式,如需要一键自动脚本安装,可参考https://lnmp.org/install.html进行安装。
以下以Debian系统为例,说明LNMPA的安装与配置方式。以下命令建议使用root用户进行操作。
安装Apache
Debian 上安装Apache相对简单,使用下述命令可安装:
sudo apt install apache2
设置URL重写
apache默认没有开启URL重写, 使用命令行sudo a2enmod rewrite
开启重写模块后,打开 /etc/apache2/apache2.conf
,找到 <Directory /var/www/>
部分,将 AllowOverride None
修改为 AllowOverride All
。删除 Indexes
,保存并重启apache systemctl restart apache2
。
修改默认端口
apache在此处是作为后端处理,需要将其默认的80端口设置为其它端口。打开 /etc/apache2/ports.conf
,将 Listen 80
部分的数字改成其它的可用端口号,比如 Listen 88
。同时注意也要修改 /etc/apache2/sites-available/000-default.conf
中的端口号为88。保存并重启apachesystemctl restart apache2
。
修改用户组权限
如果apache默认设置的用户组与我们所需的用户组不一致,则可为其设置指定的用户组。在 /etc/apache2/envvars
中可以找到aache所归属的用户组,比如默认的用户与用户组均为www-data,如果要修改的话可以修改成www。
安装mysql
由于Debian默认使用MariaDB 在APT的软件包存储库中并没有mysql,需要自行添加存储库。在https://dev.mysql.com/downloads/repo/apt/中提供了存储库包的下载地址,点击下载,复制对应的下载链接。例如:
wget https://dev.mysql.com/get/mysql-apt-config_0.8.22-1_all.debapt install ./mysql-apt-config_0.8.22-1_all.deb
出现以下界面,确认安装参数为以下内容即可。选择[OK]
。
更新软件包存储库并安装MySQL。
sudo apt update
sudo apt install mysql-server libmysqlclient21 libmysqlclient-dev
sudo apt install default-libmysqlclient-dev
在此过程中会出现输入数据库用户root密码的提示,输入二次并确认。
然后会出现密码安全验证选项选择推荐的强验证方式。
安装php
Debian 下将 PHP 安装入 Apache 2 的例子:
apt install php-common libapache2-mod-php php-cli
APT 将自动安装 Apache 2 的 PHP 模块以及所有依赖的库并激活之。应重启动 Apache 以使更改生效,由于安装了MySQL,还需要启用php的MySQL支持。
sudo apt install php-mysql php-curl
可在/var/www/html
目录下放置一个phpinfo.php
来检查php环境是否安装正确。文件中填写以下内容:
<?php
phpinfo();
?>
访问http://ip/phpinfo.php,可查看页面是否正常打开。
phpMyAdmin安装
使用phpMyAdmin之前,需要为php开启mysqli 与xml的参数项,具体可先参考以下内容进行设置。
apt install php-xml php-mbstring php-gd;
编辑/etc/php/7.4/apache2/php.ini
,将其中的;extension=mysqli
与 ;extension=gd2
选项前的逗号去除,保存,重启Apache systemctl restart apache2
以使配置生效。
从https://www.phpmyadmin.net/下载程序,解压后上传至/var/www/htm/phpMyAdmin
目录下,访问http://ip:88/phpMyAdmin/,检查访问是否正常。
安装nginx
使用以下命令安装nginx。
sudo apt install nginx
修改用户权限
在 /etc/nginx/nginx.conf
中,修改默认的用户组 www-data
为 www
。
设置网站配置
设置反向代理,在 /etc/nginx/
下新建文件 proxy.conf
。
proxy_connect_timeout 300s;
proxy_send_timeout 900;
proxy_read_timeout 900;
proxy_buffer_size 32k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_redirect off;
proxy_hide_header Vary;
proxy_set_header Accept-Encoding '';
proxy_set_header Host $http_host;
proxy_set_header Referer $http_referer;
proxy_set_header Cookie $http_cookie;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
修改默认的配置文件/etc/nginx/sites-available/default
,其中添加以下内容:
# deny running scripts inside writable directorieslocation ~* /(images|cache|media|logs|tmp)/.*\.(php|pl|py|jsp|asp|sh|cgi)$ {return 403;error_page 403 /403_error.html;}location /{try_files $uri @apache;}location @apache{internal;proxy_pass http://127.0.0.1:88;include proxy.conf;}location ~ [^/]\.php(/|$){proxy_pass http://127.0.0.1:88;include proxy.conf;}
重启nginx。 /etc/init.d/nginx restart
。
安装证书
安装证书使用 acme.sh
进行,acme.sh可帮助用户自动申请证书,并且在证书快到期时自动续期。
首先进行证书的安装。
curl https://get.acme.sh | sh -s email=my@example.com
在安装完成后,断开并重新连接终端。运行以下内容以执行证书申请。其中要将 www.mydomain.com
替换为其它的域名,/home/wwwroot/mydomain.com
替换为服务器的地址。
acme.sh --issue -d www.mydomain.com --webroot /home/wwwroot/mydomain.com/ --server buypass
安装证书。
acme.sh --install-cert -d example.com \
--key-file /path/to/keyfile/in/nginx/key.pem \
--fullchain-file /path/to/fullchain/nginx/cert.pem \
--reloadcmd "service nginx force-reload"
申请完成的证书在 /home/{username}/.acme.sh/
的目录中,请记住以上内容。
创建SSL配置文件
在Nginx的配置文件目录/etc/nginx/sites-available/
中创建一个名为 ssl.conf
的文件,文件内容填写如下。将其中的 mydomain.com
替换为实际的域名。
server{listen 443 ssl http2;#listen [::]:443 ssl http2;server_name isoface.net ;index index.html index.htm index.php default.html default.htm default.php;root /home/michael/homepage;client_max_body_size 512M;ssl_certificate /home/michael/.acme.sh/mydomain.com/mydomain.com.cer;ssl_certificate_key /home/michael/.acme.sh/mydomain.com/mydomain.com.key;ssl_session_timeout 5m;ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;ssl_prefer_server_ciphers on;ssl_ciphers "TLS13-AES-256-GCM-SHA384:TLS13-CHACHA20-POLY1305-SHA256:TLS13-AES-128-GCM-SHA256:TLS13-AES-128-CCM-8-SHA256:TLS13-AES-128-CCM-SHA256:EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5";ssl_session_cache builtin:1000 shared:SSL:10m;#error_page 404 /404.html;# Deny access to PHP files in specific directory#location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; }location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)${expires 30d;}location ~ .*\.(js|css)?${expires 12h;}location ~ /.well-known {allow all;}location ~ /\.{deny all;}# deny running scripts inside writable directorieslocation ~* /(images|cache|media|logs|tmp)/.*\.(php|pl|py|jsp|asp|sh|cgi)$ {return 403;error_page 403 /403_error.html;}location / {# First attempt to serve request as file, then# as directory, then fall back to displaying a 404.try_files $uri @apache;}location @apache{internal;proxy_pass http://127.0.0.1:88;include proxy.conf;}location ~ [^/]\.php(/|$){proxy_pass http://127.0.0.1:88;include proxy.conf;}access_log /home/michael/www.isoface.cn.log;}
同步修改 /etc/nginx/sites-available/default
。
##
# You should look at the following URL's in order to grasp a solid understanding
# of Nginx configuration files in order to fully unleash the power of Nginx.
# https://www.nginx.com/resources/wiki/start/
# https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/
# https://wiki.debian.org/Nginx/DirectoryStructure
#
# In most cases, administrators will remove this file from sites-enabled/ and
# leave it as reference inside of sites-available where it will continue to be
# updated by the nginx packaging team.
#
# This file will automatically load configuration files provided by other
# applications, such as Drupal or Wordpress. These applications will be made
# available underneath a path with that package name, such as /drupal8.
#
# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
### Default server configuration
#
server {listen 80;listen [::]:80;server_name isoface.net; rewrite ^(.*)$ https://${server_name}$1 permanent;client_max_body_size 512M;# SSL configuration## listen 443 ssl default_server;# listen [::]:443 ssl default_server;## Note: You should disable gzip for SSL traffic.# See: https://bugs.debian.org/773332## Read up on ssl_ciphers to ensure a secure configuration.# See: https://bugs.debian.org/765782## Self signed certs generated by the ssl-cert package# Don't use them in a production server!## include snippets/snakeoil.conf;root /home/michael/homepage;# Add index.php to the list if you are using PHPindex index.html index.htm index.php;#server_name isoface.net;# deny running scripts inside writable directorieslocation ~* /(images|cache|media|logs|tmp)/.*\.(php|pl|py|jsp|asp|sh|cgi)$ {return 403;error_page 403 /403_error.html;}location / {# First attempt to serve request as file, then# as directory, then fall back to displaying a 404.try_files $uri @apache;}location @apache{internal;proxy_pass http://127.0.0.1:88;include proxy.conf;}location ~ [^/]\.php(/|$){proxy_pass http://127.0.0.1:88;include proxy.conf;}# pass PHP scripts to FastCGI server##location ~ \.php$ {# include snippets/fastcgi-php.conf;## # With php-fpm (or other unix sockets):# fastcgi_pass unix:/run/php/php7.4-fpm.sock;# # With php-cgi (or other tcp sockets):# fastcgi_pass 127.0.0.1:9000;#}# deny access to .htaccess files, if Apache's document root# concurs with nginx's one##location ~ /\.ht {# deny all;#}
}# Virtual Host configuration for example.com
#
# You can move that to a different file under sites-available/ and symlink that
# to sites-enabled/ to enable it.
#
#server {
# listen 80;
# listen [::]:80;
#
# server_name example.com;
#
# root /var/www/example.com;
# index index.html;
#
# location / {
# try_files $uri $uri/ =404;
# }
#}
为当前文件创建软连接。
ln -s /etc/nginx/sites-available/ssl.conf /etc/nginx/sites-enabled/ssl.conf
重启nginx。 /etc/init.d/nginx restart
。此时网站已可以使用https进行访问。
主域名访问时跳转至子目录设置
如果要访问主域名时,要将访问链接定向至子目录中,则按以下方式进行设置。在主目录中创建一个名为 .htaccess
文件,按照以下方式写入。
# Turn mod_rewrite on
RewriteEngine on#Hide the joomla subdirectory isoface
RewriteCond %{REQUEST_URI} !^/isoface/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /isoface/$1 [L]
RewriteRule ^(/)?$ isoface/index.php [L]
设定文件上传的大小限制
在nginx 中设置 配置文件,在设定的配置文件default
与 ssl.conf
中 server
部分添加 client_max_body_size 512M;
修改 /etc/php/7.4/apache2/php.ini
。
post_max_size = 512Mupload_max_filesize = 512M
设置apache 后端获取真实IP
通过以下命令启用获取真实IP的模块:
a2enmod remoteip
编辑 /etc/apache2/apach2.conf
文件,在其中添加
RemoteIPHeader X-Forwarded-For
RemoteIPInternalProxy 127.0.0.1
在配置文件中找到
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
将其中的 %h
改成 %a
,使用 systemctl restart apache2
重启模块。
Debian手动安装LNMPA环境及相关配置相关推荐
- Tomcat下载安装与环境变量的配置
注意:安装Tomcat之前,一定要先安装好JDK并正确配置jdk环境变量: 参考教程:JDK的安装与环境变量的配置 1.Tomcat下载 (1)百度搜索"Tomcat官网".&qu ...
- Python安装与环境变量的配置
Python安装与环境变量的配置 python下载: Python安装包下载地址 1 . 选择Windows系统的 2 . 选择相应的32/64位版本点击下载 python安装: 1 . 下载完成后, ...
- 【从零开始vnpy量化投资】三. 手动安装vnpy环境
[从零开始vnpy量化投资]三. 手动安装vnpy环境 概述 本章的主要内容是使用conda创建独立的python运行环境,再将vnpy安装到conda的环境中,以便开发时访问和编辑源码以及为后续部署 ...
- jdk绿色免安装版如何进行相关配置?
jdk绿色免安装版如何进行相关配置? 1.到网上下载一个绿色版kdk版本 如下: 2.新建文本文件重命名后缀为:xx.bat.运行. 内容如下: @echo off echo **以下设置Java环境 ...
- anaconda配置python环境变量_Anaconda的安装及其环境变量的配置详解
Anaconda的安装及其环境变量的配置详解 随着python的发展越来越好,用python的伙伴也越来越多.本人刚开始接触python的时候用的第一个集成环境就是Anaconda,因为自带很多包,安 ...
- jdk安装和环境变量的配置
jdk安装和环境变量的配置 1.jdk 下载链接: http://www.oracle.com/technetwork/java/javase/downloads/index.html (下拉 ...
- window安装python3装环境变量_Windows下的Python安装与环境变量的配置
Windows下的Python安装与环境变量的配置 第一步:python下载: 第二步:python安装: 双击下载包,进入Python安装向导. 此处省略安装时的配图,下一步.下一步即可.但请要注意 ...
- java8安装_科学网—Java JDK 8 的安装以及环境变量的配置(Linux and Windows) - 彭勇的博文...
Java JDK 8 的安装以及环境变量的配置(Linux and Windows) JDK(Java Development Kit)包括了Java语言的编译器,可以在这里下载: 根据操作系统选择相 ...
- Java jdk的安装 与 环境变量的配置
Java jdk的安装 与 环境变量的配置 1. 下载jdk (1)打开浏览器,在地址栏中输入 http://www.oracle.com/index.html,进入到Oracle的官方主页: (2) ...
最新文章
- MySQL · 引擎特性 · InnoDB 崩溃恢复过程
- 八个JS中你见过的类型。
- step5 . day2 网络编程 基于TPC协议的网络编程流程及API
- SQL未能排它地锁定数据库以执行该操作解决
- [翻译]在 .NET Core 中的并发编程
- PostgreSQL开放自由
- 常用PHP数组函数总结
- [设计纹理素材]可爱手绘淡雅清新图案花样背景素材
- R语言实现K最近邻算法(KNN)
- c中static的含义
- 线性稳压芯片的选取要素
- FormData兼容性问题
- 当电脑内存比较小的时候,小于4G,安装32bit还是64bit呢
- Hibernate 查询Criterion数据
- 从kernel源码进阶C语言
- 数据中心的铜缆布线活力无限不过时
- 计算机硬件 OR CX 1,计算机硬件复习提纲
- STM32开发笔记112:ADS1258驱动设计——读寄存器
- 计算机毕设智能大棚,本科毕设论文-智能大棚管理系统设计论文.doc
- oracle修改scott密码
热门文章
- 【技巧】desc +表名;
- python虚拟机原理_pvm虚拟机基本原理
- SEO工作者面试基本都会被问到的问题
- 星际穿越+降临+明日边缘?星际拓荒重新定义星际探索题材游戏
- Mangos模拟器综合资源贴
- CPT103-Introduction to Databases小豪的笔记
- 如何快速地向服务器传大文件,大文件如何快速传输
- Python读取和操作Excel(.xlsx)文件
- vue人力管理_springboot+vue微人事人力资源管理系统,前后台分离源码
- 考研【真题】一些名校的部分真题(侵权请通知我删除)