ubuntu手动搭建lnmp

第一步下载更新你的服务器源

apt update
apt upgrade

第二步下载Nginx服务

apt install nginx

第三步下载MySQL数据库

apt install mysql-server

第四步创建MySQL密码

先登录数据库

mysql -uroot

 再创建密码

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '新密码';

、第五步安装PHP

apt install php

第六步下载其他PHP件

apt install php-fpm
apt install php-mysql

第七步添加PHP解析到Nginx配置文件,不然有PHP文件的网站打不开

找到Nginx配置文件,一般在etc/nginx/nginx.conf

location ~ \.php$ {
    include snippets/fastcgi-php.conf;
    fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;  
}

 注意php7.4-fpm版本要跟你的一样,fpm版本查看方法使用查找命令找php文件夹,里面有fpm文件夹加版本号

Nginx添加多网站,添加配置文件,在执行 

sudo ln -s /etc/nginx/sites-available/site1 /etc/nginx/sites-enabled/

创建网站配置文件:为每个网站创建一个Nginx配置文件。在/etc/nginx/sites-available/目录下创建两个配置文件,例如site1和site2。

phpmaadmin下载链接

wget https://files.phpmyadmin.net/phpMyAdmin/5.2.1/phpMyAdmin-5.2.1-all-languages.zip

nginx添加配置文件案例

server {
    listen 80;
    server_name example1.com;

    location / {
        root /var/www/site1;
        index index.html;
    }
}

Nginx配置文件可用的

##
# 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 7778 default_server;
	listen [::]:7778 default_server;

	# 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 /www/phpmyadmin;


	#Add index.php to the list if you are using PHP
	index index.php index.html index.htm index.nginx-debian.html;

	server_name _;

	location / {
		# First attempt to serve request as file, then
		# as directory, then fall back to displaying a 404.
		#index.php
		try_files $uri $uri/ =404;
	}

	# 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;
	#}

        location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php8.1-fpm.sock;
        }   





}
# 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;
#	}
#}

mysql其他配置。运行以下指令执行安全性脚本

sudo mysql_secure_installation

以下是安全脚本中文解释

Securing the MySQL server deployment.

Connecting to MySQL using a blank password.

VALIDATE PASSWORD COMPONENT can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD component?

Press y|Y for Yes, any other key for No:

确保MySQL服务器部署的安全。
使用空白密码连接MySQL。
VALIDATE PASSWORD COMPONENT可用于测试密码
并提高安全性。它检查密码的强度
并且允许用户仅设置以下密码
足够安全。是否要设置VALIDATE PASSWORD组件?
按y|y表示“是”,按任意其他键表示“否”:

There are three levels of password validation policy:

LOW    Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary                  file

Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG:

密码验证策略有三个级别:
LOW长度>=8
MEDIUM长度>=8,数字、大小写混合和特殊字符
STRONG长度>=8,数字,混合大小写,特殊字符和字典文件
请输入0=LOW、1=MEDIUM和2=STRONG:

Securing the MySQL server deployment.

Connecting to MySQL using a blank password.
The 'validate_password' component is installed on the server.
The subsequent steps will run with the existing configuration
of the component.
Please set the password for root here.

New password:

确保MySQL服务器部署的安全。
使用空白密码连接MySQL。
“validate_password”组件已安装在服务器上。
后续步骤将使用现有配置运行
组件的。
请在此处设置root用户的密码。
新密码:


Estimated strength of the password: 50
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) :

密码的估计强度:50
您想继续使用提供的密码吗?(按y|y表示“是”,按任意其他键表示“否”):

Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : Y
 ... Failed! Error: SET PASSWORD has no significance for user 'root'@'localhost' as the authentication method used doesn't store authentication data in the MySQL server. Please consider using ALTER USER instead if you want to change authentication parameters.


您想继续使用提供的密码吗?(按y|y表示“是”,按任意其他键表示“否”):y
…失败!错误:SET PASSWORD对用户'root'@'localhost'没有意义,因为使用的身份验证方法不会将身份验证数据存储在MySQL服务器中。如果要更改身份验证参数,请考虑改用ALTER USER。

有些网站只支持PHP7.2和7.4下面是安装PHP7.2方法

添加 Ondřej Surý PPA 源:Ondřej Surý 维护了一个 PPA 源,提供了各个 PHP 版本的软件包。

sudo apt install software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt update
sudo apt install php7.2

安装 PHP 7.2 和相关模块:

sudo apt install php7.2

 

sudo apt install php7.2-cli php7.2-fpm php7.2-mysql php7.2-curl php7.2-gd php7.2-mbstring php7.2-xml php7.2-xmlrpc php7.2-zip

验证安装是否成功:安装完成后,你可以使用以下命令验证 PHP 版本:

php -v

你可能感兴趣的:(ubuntu,linux,运维)