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
看到runing說明成功
**
安裝mysql 數據庫
安裝mysql
驗證 MySQL
renxiaoxu@ubuntu:~$sudo apt-get install my-server mysql.service - MySQL Community Server mysql.service - MySQL Community ServerLoaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset:>Active: active (running) since Thu 2022-03-10 20:07:08 CST; 1 day 1h agoMain PID: 1024 (mysqld)Status: "Server is operational"Tasks: 43 (limit: 9419)Memory: 474.9MCGroup: /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 filePlease 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 用戶身份登錄
-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
更新環境
安裝PHP
renxiaoxu@ubuntu:~# sudo apt install php libapache2-mod-phpphp安裝好了,重啟 Apache,重新加載 PHP 模塊
renxiaoxu@ubuntu:# sudo systemctl restart apache2安裝 PHP 擴展
PHP 擴展被編譯成庫文件,用來擴展 PHP 核心功能
安裝 MySQL 和 GD 擴展
在安裝一個新的 PHP 擴展之后,依賴于你的設置,不要忘記去重啟 Apache 或者 PHP FPM 服務
測試 PHP 處理
進入/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編輯內容如下
?phpecho 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.conf1.進入文件夾
renxiaoxu@ubuntu:~$/# cd /etc/apache2/sites-available/2.備份
renxiaoxu@ubuntu:~$/etc/apache2# sudo cp 000-default.conf 000-food.conf3.修改
renxiaoxu@ubuntu:~$/etc/apache2/sites-available# sudo nano 000-default.confThe 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:warn4.修改完后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/
2.下載woedpress文件
renxiaoxu@ubuntu:-virtual-machine:~# wget http://wordpress.org/latest.tar.gz3.查看下載的文件
renxiaoxu@ubuntu-virtual-machine:~# ls-看到latest.tar.gz,這是一個壓縮包,將其解壓 #@4.解壓
renxiaoxu@ubuntu:-virtual-machine:~# tar xzvf latest.tar.gz-解壓完成后多了一個wordpress文件
5.update
sudo apt-get update6.刪除壓縮文件
renxiaoxu@ubuntu:~$ rm latest.tar.gz7.將wordpress里面的文件全部移到根目錄即上一層目錄
renxiaoxu@ubuntu:~$/var/www/html/wordpress# mv * /var/www/html/編輯wenjian
1.備份wp-config-sample.php
2.修改wp-config.php
rrenxiaoxu@ubuntu:~$/var/www/html# sudo nano wp-config.php3.修改如下,數據庫名,用戶名,密碼
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
總結
以上是生活随笔為你收集整理的ubuntu20.04搭建lamp环境 +制作网页的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ETC/CFX/RVN/NEOXA/ER
- 下一篇: VS code 安装Source Cod