1、什么是LAMP
LAMP(linux+apache+mysql+php/python)网站架构,是⽬前国际流⾏的Web框架,该框架包 括:Linux操作系统,Apache⽹络服务器,MySQL数据库,Perl、PHP或者Python编程语 ⾔,所有组成产品均是开源软件,是国际上成熟的架构框架,很多流⾏的商业应⽤都是采取 这个架构,LAMP具有通⽤、跨平台、⾼性能、低价格的优势,因此LAMP⽆论是性能、质量 还是价格都是企业搭建⽹站的⾸选平台。LAMP架构广泛应用于各种动态网站和应用系统,如社交网站、博客平台、在线商店等。
2、LAMP架构工作过程
1、当客户端请求的是静态资源时,web服务器会直接把静态资源返回客户端(静态资源是预先存储在文件系统中的固定内容.)
2、当客户端请求的是动态资源时,httpd的php模块会进行相应的动态资源运算,如果此过程还需要数据库的数据作为运算参数时,php会连接mysql取得数据然后进行运算,运算的结果转为静态资源由web服务器返回到客户端;(动态资源则需要服务器端程序在执行过程中生成和返回.)
3、LAMP搭建过程(以下是基于VMware虚拟机的linux9.2操作系统)
1、配置Linux的yun源安装(包保证可以ping通外网)
2、安装配置apache,基于虚拟机主机模式的https协议
3、安装配置mysql
4、安装配置php,以及php-mysql模块
5、基于LAMP搭建discuz测试
1、yum源仓库的配置
mount /dev/sr0 /mnt /*镜像挂载*/
cp -Ra /mnt/* /opt
cd
vi /etc/yum.repos.d/local.repo /*yum仓库配置*/
[local]
name=local
baseurl=file:///opt/BaseOS/
enabled=1
gpgcheck=0
[AppStream]
name=AppStream
baseurl=file:///opt/AppStream/
enable=1
gpgcheck=0
yum makecahce /*查看是否配置成功,命令用于确保 YUM 的缓存是最新的,从而提供更准确和可靠的软件包管理功能*/
2、安装apache
yum -y install httpd*
systemctl start httpd.service /*启动服务*/
systemctl enable httpd.service /*设置开机自启动*/
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.
3、安装mysql
yum install mariadb-server mariadb -y /*yum源安装数据库*/
systemctl start mariadb.service /*启动数据库*/
systemctl enable mariadb.service /*设置开机自启动*/
mysql_secure_installation /*数据库的配置(先按2次回车输入yes输入密码(2次)一直回车即可完成配置)*/
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
haven't set the root password yet, you should just press enter here.
Enter current password for root (enter for none):
OK, successfully used password, moving on...
Setting the root password or using the unix_socket ensures that nobody
can log into the MariaDB root user without the proper authorisation.
You already have your root account protected, so you can safely answer 'n'.
Switch to unix_socket authentication [Y/n]
Enabled successfully!
Reloading privilege tables..
... Success!
You already have your root account protected, so you can safely answer 'n'.
Change the root password? [Y/n] y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
... Success!
By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB 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? [Y/n]
... 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? [Y/n]
... Success!
By default, MariaDB 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? [Y/n]
- 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? [Y/n]
... Success!
Cleaning up...
All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!
4、安装php及测试静态资源配置
yum -y install php /*安装php组件*/
vi /var/www/html/info.php /*文件编译测试静态资源效果*/
cat /var/www/html/info.php
<?php
phpinfo();
?>
systemctl restart httpd.service
5、基于lamp的discuz论坛安装
1、在浏览器搜索discuz选择简体中文下载安装即可(此操作是在主机中操作)
2、将其安装包拖动到虚拟机当中
3、进入虚拟机对该安装包进行解压(先将其移动到/var/www/html 目录下在进行解压)
[root@localhost ~]# ls
公共 视频 文档 音乐 anaconda-ks.cfg
模板 图片 下载 桌面 Discuz_X3.5_SC_UTF8_20231221.zip
[root@localhost ~]# mv Discuz_X3.5_SC_UTF8_20231221.zip /var/www/html/
[root@localhost ~]# cd /var/www/html/
[root@localhost html]# ls
Discuz_X3.5_SC_UTF8_20231221.zip info.php
[root@localhost html]# unzip Discuz_X3.5_SC_UTF8_20231221.zip
4、删除多余的文件只留下upload
[root@localhost html]# ls
Discuz_X3.5_SC_UTF8_20231221.zip LICENSE readme upload
info.php qqqun.png readme.html utility.html
[root@localhost html]# mv Discuz_X3.5_SC_UTF8_20231221.zip /root /*该安装包也可以选择直接删除*/
[root@localhost html]# rm -rf LICENSE readme info.php qqqun.png readme.html utility.html
[root@localhost html]# ls
upload
5、将upload移动到该目录下
[root@localhost html]# mv upload/* ./ /*将upload目录下的所有文件和子目录移动到当前目录/
[root@localhost html]# ls
admin.php connect.php group.php misc.php source upload
api crossdomain.xml home.php plugin.php static
api.php data index.php portal.php template
archiver favicon.ico install robots.txt uc_client
config forum.php member.php search.php uc_server
6、浏览器输入ip地址后面加上/install/查看效果
7、要进行修改权限否则会出现以下效果
8、对文件进行权限修改
[root@localhost html]# chown -R apache.apache /var/www/html/
[root@localhost html]# ll
总用量 72
-rw-r--r--. 1 apache apache 2869 12月 21 19:29 admin.php
drwxr-xr-x. 10 apache apache 149 12月 21 19:28 api
-rw-r--r--. 1 apache apache 727 12月 21 19:29 api.php
drwxr-xr-x. 2 apache apache 23 12月 21 19:28 archiver
drwxr-xr-x. 2 apache apache 90 12月 21 19:28 config
-rw-r--r--. 1 apache apache 1040 12月 21 19:29 connect.php
-rw-r--r--. 1 apache apache 106 12月 21 19:29 crossdomain.xml
drwxr-xr-x. 12 apache apache 178 12月 21 19:28 data
-rw-r--r--. 1 apache apache 5558 12月 21 16:24 favicon.ico
-rw-r--r--. 1 apache apache 2357 12月 21 19:29 forum.php
-rw-r--r--. 1 apache apache 906 12月 21 19:29 group.php
-rw-r--r--. 1 apache apache 1325 12月 21 19:29 home.php
-rw-r--r--. 1 apache apache 6920 12月 21 19:29 index.php
drwxr-xr-x. 5 apache apache 64 12月 21 19:28 install
-rw-r--r--. 1 apache apache 998 12月 21 19:29 member.php
-rw-r--r--. 1 apache apache 2410 12月 21 19:29 misc.php
-rw-r--r--. 1 apache apache 1790 12月 21 19:29 plugin.php
-rw-r--r--. 1 apache apache 1086 12月 21 19:29 portal.php
-rw-r--r--. 1 apache apache 639 12月 21 19:29 robots.txt
-rw-r--r--. 1 apache apache 1755 12月 21 19:29 search.php
drwxr-xr-x. 10 apache apache 168 12月 21 19:28 source
drwxr-xr-x. 7 apache apache 86 12月 21 19:29 static
drwxr-xr-x. 3 apache apache 38 12月 21 19:29 template
drwxr-xr-x. 8 apache apache 146 12月 21 19:29 uc_client
drwxr-xr-x. 13 apache apache 4096 12月 21 19:29 uc_server
drwxr-xr-x. 2 apache apache 6 1月 14 09:49 upload
9、关闭防火墙
[root@localhost html]# chmod -R 777 /var/www/html/
[root@localhost html]# systemctl stop firewalld.service
[root@localhost html]# setenforce 0
10、进行以下操作即可
服务器地址就是自己的ip地址可以通过以下命令查看自己的ip地址(数据库名字和用户名设置的要与在虚拟机的mysql中设置的要相同)
[root@localhost html]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: ens160: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
link/ether 00:0c:29:c3:a5:c2 brd ff:ff:ff:ff:ff:ff
altname enp3s0
inet 192.168.81.101/24 brd 192.168.81.255 scope global noprefixroute ens160
valid_lft forever preferred_lft forever
inet6 fe80::20c:29ff:fec3:a5c2/64 scope link noprefixroute
valid_lft forever preferred_lft forever
对mysql进行数据配置和用户配置
[root@localhost html]# mysql -uroot -p123456
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 10.5.16-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> create user 'zpyr'@'192.168.81.101'identified by '123456';
Query OK, 0 rows affected (0.011 sec)
MariaDB [(none)]> grant all privileges on zpyr.* TO 'zpyr'@'192.168.81.101';
Query OK, 0 rows affected (0.002 sec)
/*
CREATE USER 'username'@'ip地址' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON database_name.* TO 'username'@'ip地址';
其中,username是你要创建的用户名,password是用户的密码,database_name是你要给用户授权的数据库名。
*/
以上就是LAMP基于discuz的搭建过程