香雨站

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 108|回复: 0

Ubuntu22.04LTS上搭建LAMP环境

[复制链接]

3

主题

5

帖子

12

积分

新手上路

Rank: 1

积分
12
发表于 2023-3-6 15:44:55 | 显示全部楼层 |阅读模式
一.更新升级ubuntu系统(普通用户)

1. 获取root权限
sudo susu2. 系统更新
apt update3. 软件升级
apt upgrade 二.安装Apache2 Web服务器

1. 安装Apache
apt install apache22. 检查Apache是否开启(一般安装完成后默认开启),绿字显示“Active: active(running)”即为正常开启。
systemctl status apache23. 开启,关闭,重启Apache服务器的命令行,需要时使用。
(1)开启服务器
systemctl start apache2 (2)关闭服务器
systemctl stop apache2 (3) 重启服务器
systemctl restart apache24. 打开浏览器,输入域名或IP,确认Apache的默认信息页面。  


三.安装MySQL

1. 查看系统里有无安装MySQL
dpkg -l | grep mysql2. 安装MySQL
apt install mysql-server3. 检查安装结果,mysql的socket处于LISTEN状态即表示安装成功。
netstat -tap | grep mysql4. 常用mysql 命令。
<登入mysql>
mysql -u root -p   -u 表示选择登陆的用户名,此处是root用户,-p 表示登陆的用户密码,系统会要求输入root用户的密码,按要求输入即可。
<查看现有数据库(在登入mysql之后)>
show databases;5. 数据库初始化操作(登出mysql状态)
mysql_secure_installation过程中有以下5处需要注意的地方,如下对话框所示操作即可。
(1)安装验证密码插件
(2)设置root管理员在数据库中的专有密码
(3)删除匿名账户,使用root用户从远程登录数据库,以确保数据库运行安全。
(4)删除默认的测试数据库,取消测试数据库的一系列访问权限。
(5)刷新授权列表,让初始化的设定立即生效。
Securing the MySQL server deployment.
  Connecting to MySQL using a blank password.
  VALIDATE PASSWORD PLUGIN 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
  plugin?    # 要安装验证密码插件吗?
   
  Press y|Y for Yes, any other key for No: N    # 这里我选择N
  Please set the password for root here.
   
  New password:   # 输入要为root管理员设置的数据库密码
   
  Re-enter new password:  
  # 再次输入密码
   
  By default, a MySQL installation has an anonymous user,
  allowing anyone to log into MySQL without having to have
  a user account created for them. This is intended only for
  testing, and to make the installation go a bit smoother.
  You should remove them before moving into a production
  environment.
  Remove anonymous users? (Press y|Y for Yes, any other key for
  No) : y     # 删除匿名账户
  Success.
   
  Normally, root should only be allowed to connect from
  'localhost'. This ensures that someone cannot guess at
  the root password from the network.
   
  Disallow root login remotely? (Press y|Y for Yes, any other
  key for No) : N   # 禁止root管理员从远程登录,这里我没有禁止
   
  ... skipping.
  By default, MySQL comes with a database named 'test' that
  anyone can access. This is also intended only for testing,
  and should be removed before moving into a production
  environment.
   
  Remove test database and access to it? (Press y|Y for Yes, any
  other key for No) : y  # 删除test数据库并取消对它的访问权限
  - Dropping test database...
  Success.
   
  - Removing privileges on test database...
  Success.
   
  Reloading the privilege tables will ensure that all changes
  made so far will take effect immediately.
   
  Reload privilege tables now? (Press y|Y for Yes, any other key
  for No) : y   # 刷新授权表,让初始化后的设定立即生效
  Success.
6. 检查mysql服务状态
systemctl status mysql显示下列结果,说明mysql服务器运行正常。  


7. 常用mysql命令(部分重复),再次进入数据库(使用刚刚设置的root密码)
mysql -u root -p8. 打开mysql命名的数据库
use mysql;9. 显示当前数据库表
show tables;10. 查询user表里的数据
select * from user;     (user表里是mysql数据库的所有账户信息)
11. 退出mysql
exit12. 配置mysql允许远程访问
(1)编辑配置文件
vi /etc/mysql/mysql.conf.d/mysqld.cnf加#注释掉bind-address = 127.0.0.1,如下


保存退出。
(2)进入mysql数据库
mysql -u root -p(3)执行下列操作(mysql登入状态下)
grant all on *.* to root@'%' identified by '你的密码' with grant option;        刷新权限(mysql登入状态下)
flush privileges;         退出mysql(mysql登入状态下)
exit       重启mysql:
systemctl restart mysql四.安装PHP

(1)安装
apt install php(2)测试,查看版本
php -v(3)命令Apache首先提供PHP页面
打开dir.conf,编辑文件,将其更改为首先列出index.php。
/etc/apache2/mods-enabled/dir.conf         默认:  


        更改为:  


        重启Apache2服务器
systemctl restart apache2         在/var/www/html中创建一个名为index.php的新文件。
vi /var/www/html/index.php        输入以下内容
<?php
phpinfo();
?>         保存并退出该文件。
         打开浏览器并输入服务器IP地址或域名,不出意外就能访问到PHP的默认信息页面。  


        然后在IP地址后面输入/index.html也能访问到Apache的默认信息页面。  


五.升级安装PHP8.1
1. 安装PHP
apt install php六.安装PHP必要扩展
apt install php8.1-dev
apt install php8.1-pear
apt install php8.1-fpm php8.1-mysql php8.1-curl php8.1-json php8.1-mbstring php8.1-xml php8.1-intl     按需安装,有无法安装的可忽略。
七.安装PHP可选扩展
apt-get install php7.4-zip         #moodle平台安装必须
apt-get install php7.4-xlmrpc      #moodle平台安装必须
apt-get install php7.4-gd
apt-get install php7.4-soap
apt-get install php7.4-gmp
apt-get install php7.4-odbc
apt-get install php7.4-pspell
apt-get install php7.4-bcmath
apt-get install php7.4-enchant
apt-get install php7.4-ldap
apt-get install php7.4-opcache
apt-get install php7.4-readline
apt-get install php7.4-sqlite3
apt-get install php7.4-bz2
apt-get install php7.4-interbase
apt-get install php7.4-pgsql
apt-get install php7.4-recode       #安装时提示没有此安装文件
apt-get install php7.4-sybase
apt-get install php7.4-xsl
apt-get install php7.4-cgi
apt-get install php7.4-dba
apt-get install php7.4-phpdbg
apt-get install php7.4-snmp
apt-get install php7.4-tidy
apt-get install php7.4-zip*
apt-get install php7.4-imagick      #wordpress 默认需要   按需安装,有无法安装的可忽略。
八.安装phpMyAdmin,通过网页可视性操控mysql,方便,但可能引发安全漏洞。
apt install phpmyadmin         创建phpMyAdmin的软链接到Apache的根目录下(/var/www/html/)
ln -s /usr/share/phpmyadmin /var/www/html/phpmyadmin九.新增mysql用户并赋权
1. 登入mysql
mysql -u root -p2. 添加用户
create user ‘新增用户名’@‘localhost’ identified with mysql_native_password by ‘密码’;
grant all privileges on *.* to ‘新增用户名’@‘localhost’ with grant option;
flush privileges;
quit;3. 重启mysql
systemctl restart mysql十.安装MariaDB

  • 安装
apt update
apt install mariadb-server2. 验证运行状态
systemctl status mariadb3. MariaDB安全防护
mysql_secure_installation        #前面已经设置过,这里没做任何改动
至此,ubuntu22.04LTS平台上LAMP服务器就安装完成了。

(终)
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|香雨站

GMT+8, 2025-3-15 22:42 , Processed in 0.086059 second(s), 22 queries .

Powered by Discuz! X3.4

© 2001-2013 Comsenz Inc.. 技术支持 by 巅峰设计

快速回复 返回顶部 返回列表