ubuntu20.04搭建lamp环境 +制作网页

一、准备工作
二、安装apache2
三、安装mysql
四、安装php
五、安装depress
准备工作
配置虚拟机安装ubuntu20.04
配置环境及相关设置(配置中文及防火墙等)

安装apache2
Apache HTTP服务器是世界上使用最广泛的Web服务器。它提供了许多强大的功能,包括可动态加载的模块,强大的媒体支持以及与其他流行软件的广泛集成。

开始安装

打开终端,进入根目录

`renxiaoxu@ubuntu:~$` sudo su

更新环境

renxiaoxu@ubuntu:~$ apt-get upgrade

安装apache环境

renxiaoxu@ubuntu:~$ sudo apt-get install apache

确认安装后, apt将安装Apache和所有必需的依赖项
安装完成之后我们可以在浏览器中输入localhost进行访问
也可以查看apache

renxiaoxu@ubuntu:~$ service apache2 status

看到runing说明成功

**

安装mysql 数据库
安装mysql

renxiaoxu@ubuntu:~$sudo apt-get install my-server

验证 MySQL

renxiaoxu@ubuntu:~$sudo apt-get install my-server
mysql.service - MySQL Community Server
mysql.service - MySQL Community Server
     Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset:>
     Active: active (running) since Thu 2022-03-10 20:07:08 CST; 1 day 1h ago
   Main PID: 1024 (mysqld)
     Status: "Server is operational"
      Tasks: 43 (limit: 9419)
     Memory: 474.9M
     CGroup: /system.slice/mysql.service
             └─1024 /usr/sbin/mysqld

保护加固 MySQL

renxiaoxu@ubuntu:~$ mysql_secure_installation
●Error: Access denied for user 'root'@'localhost'

mysql需要测试 MySQL 用户密码的强度,并且提高安全性

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:

三个级别的密码验证策略,低级,中级,高级

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: 2

下一次被提示时,将被要求为 MySQL root 用户设置一个密码:

Please set the password for root here.

New password: 

Re-enter new password

如果你设置了验证密码插件,这个脚本将会显示你的新密码强度。输入y确认密码:


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) : y

下一步,你将被要求移除任何匿名用户,限制 root 用户访问本地机器,移除测试数据库并且重新加载权限表。你应该对所有的问题回答y。
以 root 用户身份登录


renxiaoxu@ubuntu:~$ sudo mysql -u root -p

-u 指定用户名 -p需要输入密码


Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 33
Server version: 8.0.28-0ubuntu0.20.04.3 (Ubuntu)
Copyright (c) 2000, 2022, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 


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:
 

安装 PHP 7.4,配合apache
更新环境


renxiaoxu@ubuntu:~# sudo apt update

安装PHP

renxiaoxu@ubuntu:~# sudo apt install php libapache2-mod-php

php安装好了,重启 Apache,重新加载 PHP 模块


renxiaoxu@ubuntu:# sudo systemctl restart apache2

安装 PHP 扩展
PHP 扩展被编译成库文件,用来扩展 PHP 核心功能
安装 MySQL 和 GD 扩展


renxiaoxu@ubuntu:# sudo apt install php-mysql php-gd

在安装一个新的 PHP 扩展之后,依赖于你的设置,不要忘记去重启 Apache 或者 PHP FPM 服务
测试 PHP 处理
进入/var/www

renxiaoxu@ubuntu:~$ cd /var/www

修改权限


renxiaoxu@ubuntu:~$#sudo chmod 777 /etc/apache2/mods-enabled/dir.conf
bash
renxiaoxu@ubuntu:~$/var/www# cd html/

建立php文件


renxiaoxu@ubuntu:~$/var/www/html# sudo gedit index.php

编辑内容如下


?php
     echo phpinfo();
?>

浏览器输入http://localhost/info.php打开测试页面
至此lamp基本搭建完成

安装depress
修改ssh

进入根目录


sudo su -

修改配置文件


sudo vim /etc/ssh/ssh_config.d/

安装ssh


sudo apt-get install openssh-server

添加ssh.service


sudo systemctl enable ssh.service

启动ssh


service ssh start
sudo apt-get update && apt-get upgrade   //升级更新一下

配置防火墙


sudo ufw app list
sudo ufw allow 'Apache'
进入/var/www/html下创建自己的文件夹

cd /var/www/html/

创建你的项目文件夹


mkdir -p food

用户权限设置


renxiaoxu@ubuntu:~$/var/www/html# sudo chown -R 755 /var/www
修改000-default.conf

1.进入文件夹


renxiaoxu@ubuntu:~$/# cd /etc/apache2/sites-available/

2.备份


renxiaoxu@ubuntu:~$/etc/apache2# sudo cp 000-default.conf 000-food.conf

3.修改


renxiaoxu@ubuntu:~$/etc/apache2/sites-available# sudo nano 000-default.conf

The ServerName directive sets the request scheme, hostname and port that
      # the server uses to identify itself. This is used when creating        # redirection URLs. In the context of virtual hosts, the ServerName        # specifies what hostname must appear in the request's Host: header to        # match this virtual host. For the default virtual host (this file) this        # value is not decisive as it is used as a last resort host regardless.        # However, you must set it for any further virtual host explicitly.        #ServerName www.example.com        ServerAdmin 1052469821@qq.com        ServerName lifeonchina        ServerAlias www.lifeonchina.com        DocumentRoot /var/www/html        # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,        # error, crit, alert, emerg.        # It is also possible to configure the loglevel for particular        # modules, e.g.        #LogLevel info ssl:warn

4.修改完后ctrl+x保存退出

5.确认


renxiaoxu@ubuntu:~$/etc/apache2/sites-available# sudo a2ensite 000-default.conf
bash
Site 000-default already enabled       //成功

6.重启apache2,并检查


renxiaoxu@ubuntu:~$/etc/apache2/sites-available# sudo systemctl restart apache2
renxiaoxu@ubuntu:~$/etc/apache2/sites-available# sudo apache2ctl configtest
报错

Set the 'ServerName' directive globally to suppress this message

解决方式


renxiaoxu@ubuntu:~$/etc/apache2/sites-available# sudo nano  /etc/apache2/apache2.conf

编辑配置文件apache.conf

#在文件最后添加一行 ServerName localhost:80 #然后保存并重启Apache2

再测试


service apache2 restart
root@suliu-virtual-machine:/etc/apache2/sites-available# sudo apache2ctl configtest 
Syntax OK.  //成功!

修改完成

1.登陆lmysql


renxiaoxu@ubuntu:/etc/apache2/sites-available# sudo mysql -u root -p

-//输入密码


Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 14Server version: 8.0.28-0ubuntu0.20.04.3 (Ubuntu)Copyright (c) 2000, 2022, Oracle and/or its affiliates.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql>           //成功进入

2.创建数据库//database:life; user:life_user; password:##############;


mysql> CREATE DATABASE life;(接着上面的mysql>,只需要写入CREATE DATABASE life;)

Query OK, 1 row affected (0.06 sec)

3.创建USER

mysql> CREATE USER life_user@localhost IDENTIFIED BY '##############';

4.创建GRANT

mysql> GRANT ALL PRIVILEGES ON life.* TO life_user@localhost;
mysql> FLUSH PRIVILEGES;

退出

mysql> EXIT;

数据库创建完成、

安装wordpress
1.进入/var/www/html/

renxiaoxu@ubuntu:/etc/apache2/sites-available# cd /var/www/html/

2.下载woedpress文件

renxiaoxu@ubuntu:-virtual-machine:~# wget http://wordpress.org/latest.tar.gz

3.查看下载的文件

renxiaoxu@ubuntu-virtual-machine:~# ls

-看到latest.tar.gz,这是一个压缩包,将其解压 #@4.解压

renxiaoxu@ubuntu:-virtual-machine:~# tar xzvf latest.tar.gz

-解压完成后多了一个wordpress文件

5.update

sudo apt-get update

6.删除压缩文件

renxiaoxu@ubuntu:~$ rm latest.tar.gz

7.将wordpress里面的文件全部移到根目录即上一层目录

renxiaoxu@ubuntu:~$/var/www/html/wordpress# mv * /var/www/html/

编辑wenjian
1.备份wp-config-sample.php

renxiaoxu@ubuntu:~$/var/www/html# cp wp-config-sample.php wp-config.php

2.修改wp-config.php

rrenxiaoxu@ubuntu:~$/var/www/html# sudo nano wp-config.php

3.修改如下,数据库名,用户名,密码

bash
define( 'DB_NAME', 'life' );
/** Database username */define( 'DB_USER', 'life_user' );/** Database password */define( 

linux常用指令
#@sudo gedit asdf命令下无法输入中文
//直接gedit asdf

#@删除文件
//sudo rm
// -rf 强力删除,不需确认
// -i 每删除一个文件或进入一个子目录都要确认
// -r 递归删除子目录
// -d 删除空目录
// -v 显示删除结果

#@快速查找文件
//whereis asdf
//locate asdf
//find /-name asdf

#@创建文件夹
//mkdir asdf

#@创建多级文件夹
//mkdir -p asdf

#@创建文件
//touch asdf.x

#@打开当前目录的弹窗
//sudo nautilus

#@复制一个文件到另一个文件
//sudo cp -r 文件夹名 目标文件夹路径

#@修改文件名
//sudo mv 原文件名 修改后文件名

#@启动mysql
// service mysql start

#mysql查看状态
// service mysql status

#@关闭mysql
// service mysql stop

#@启动apache
service apache2 start

#@重启apache
//service apache2 restart

#@停止apache
//service apache2 stop

#@apache查看状态
//service apache2 status

#@查看mysql的用户名和密码
//sudo cat /etc/mysql/debian.cnf

#@user = debian-sys-maint
#@password = K8Jjiz7MPntks3fZ

#@ctrl + r –查找上一次命令

#@回到本行首字母
//ctrl + a

#@登陆mysql
//sudo mysql -uroot -p

  • 4
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值