lamp介绍
LAMP(Linux-Apache-MySQL-PHP)⽹站架构是⽬前国际流⾏的Web框架,该框架包 括:Linux操作系统,Apache⽹络服务器,MySQL数据库,Perl、PHP或者Python编程语言,所有组成产品均是开源软件,是国际上成熟的架构框架,很多流⾏的商业应⽤都是采取 这个架构,LAMP具有通⽤、跨平台、⾼性能、低价格的优势,因此LAMP⽆论是性能、质量 还是价格都是企业搭建⽹站的⾸选平台。
LAMP是⼀个多C/S架构的平台,最初级为web客户端基于TCP/IP通过http协议发起传送, 这个请求可能是动态的,也可能是静态的。所以web服务器通过发起请求的后缀来判断,如 果是静态的资源就由web服务器⾃⾏处理,然后将资源发给客户端。如果是动态这时web服 务器会通过CGI(Common Gateway interface)协议发起给php。这⾥但是如果php是 以模块形式与Web服务器联系。那么他们是通过内部共享内存的⽅式。如果是php单独的放 置与⼀台服务器,那么他们是通过sockets套接字监听的⽅式通信(这⼜是⼀个C/S架构)。 这时php会相应的执⾏⼀段程序,如果在执⾏程序时,需要⽤到数据。那么php就会通过 mysql协议发送给mysql服务器(也可以看作是⼀个C/S架构)。由mysql服务器处理,将数 据供给php程序。
架构访问流程:
LAMP搭建过程 (yum安装)
(1)安装配置apache,基于虚拟主机模式的https协议
(2)安装配置mysql
(3)安装配置php,以及php-mysql模块
(4)基于LAMP搭建wordpress测试
环境:
redhat 9.0
基础网络环境搭建完成
安装httpd服务 启动并设置开机自启
[root@admin ~]# yum -y install httpd*
正在更新 Subscription Management 软件仓库。
无法读取客户身份
本系统尚未在权利服务器中注册。可使用 subscription-manager 进行注册。
AppStream 3.1 MB/s | 3.2 kB 00:00
BaseOS 2.7 MB/s | 2.7 kB 00:00
省略。。。。。。。。。。
[root@admin ~]# systemctl restart httpd.service
[root@admin ~]# systemctl enable httpd.service
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.
[root@admin ~]#
查看端口、关闭防火墙
[root@admin ~]# ss -anltp | grep 80
LISTEN 0 511 :80 :* users:(("httpd",pid=84829,fd=4),("httpd",pid=84828,fd=4),("httpd",pid=84827,fd=4),("httpd",pid=84825,fd=4))
[root@admin ~]# systemctl stop firewalld.service
[root@admin ~]# systemctl disable firewalld.service
Removed "/etc/systemd/system/multi-user.target.wants/firewalld.service".
Removed "/etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service".
[root@admin ~]# setenforce 0
浏览器访问测试页 ip
安装mariadb
[root@admin ~]# yum -y install mariadb*
正在更新 Subscription Management 软件仓库。
无法读取客户身份
本系统尚未在权利服务器中注册。可使用 subscription-manager 进行注册。
上次元数据过期检查:0:07:10 前,执行于 2024年04月07日 星期日 15时44分01秒。
依赖关系解决。
软件包 架构 版本 仓库 大小
省略。。。。。。。。
启动服务并设置开机自启
[root@admin ~]# systemctl restart mariadb.service
[root@admin ~]# systemctl enable mariadb.service
Created symlink /etc/systemd/system/mysql.service → /usr/lib/systemd/system/mariadb.service.
Created symlink /etc/systemd/system/mysqld.service → /usr/lib/systemd/system/mariadb.service.
Created symlink /etc/systemd/system/multi-user.target.wants/mariadb.service → /usr/lib/systemd/system/mariadb.service.
初始化MySQL
[root@admin ~]# mysql_secure_installation
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] //是否使用'unix_socket'进行身份验证
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 //设置root密码
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] 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? [Y/n] y //是否禁止root远程登录
... 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] 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? [Y/n] y //是否重新加载权限
... 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!
[root@admin ~]#
安装php组件
[root@admin ~]# yum -y install php*
正在更新 Subscription Management 软件仓库。
无法读取客户身份
本系统尚未在权利服务器中注册。可使用 subscription-manager 进行注册。
上次元数据过期检查:0:17:29 前,执行于 2024年04月07日 星期日 15时44分01秒。
依赖关系解决。
软件包 架构 版本 仓库 大小
省略 。。。。。
[root@admin ~]# yum search php //搜索php软件包
正在更新 Subscription Management 软件仓库。
无法读取客户身份
本系统尚未在权利服务器中注册。可使用 subscription-manager 进行注册。
上次元数据过期检查:0:18:12 前,执行于 2024年04月07日 星期日 15时44分01秒。
========================================================== 名称 和 概况 匹配:php ==========================================================
php.x86_64 : PHP scripting language for creating dynamic web sites
php-bcmath.x86_64 : A module for PHP applications for using the bcmath library
php-cli.x86_64 : Command-line interface for PHP
php-common.x86_64 : Common files for PHP
php-dba.x86_64 : A database abstraction layer module for PHP applications
php-dbg.x86_64 : The interactive PHP debugger
php-devel.x86_64 : Files needed for building PHP extensions
php-embedded.x86_64 : PHP library for embedding in applications
php-enchant.x86_64 : Enchant spelling extension for PHP applications
php-fpm.x86_64 : PHP FastCGI Process Manager
php-gd.x86_64 : A module for PHP applications for using the gd graphics library
php-gmp.x86_64 : A module for PHP applications for using the GNU MP library
php-intl.x86_64 : Internationalization extension for PHP applications
php-ldap.x86_64 : A module for PHP applications that use LDAP
php-mbstring.x86_64 : A module for PHP applications which need multi-byte string handling
php-mysqlnd.x86_64 : A module for PHP applications that use MySQL databases
php-odbc.x86_64 : A module for PHP applications that use ODBC databases
php-pdo.x86_64 : A database access abstraction module for PHP applications
php-pear.noarch : PHP Extension and Application Repository framework
php-pecl-rrd.x86_64 : PHP Bindings for rrdtool
php-pgsql.x86_64 : A PostgreSQL database module for PHP
php-process.x86_64 : Modules for PHP script using system process interfaces
php-snmp.x86_64 : A module for PHP applications that query SNMP-managed devices
php-soap.x86_64 : A module for PHP applications that use the SOAP protocol
php-xml.x86_64 : A module for PHP applications which use XML
============================================================== 名称 匹配:php ==============================================================
php-ffi.x86_64 : Foreign Function Interface
php-opcache.x86_64 : The Zend OPcache
php-pecl-apcu.x86_64 : APC User Cache
php-pecl-apcu-devel.x86_64 : APCu developer files (header)
php-pecl-xdebug3.x86_64 : Provides functions for function traces and profiling
php-pecl-zip.x86_64 : A ZIP archive management extension
[root@admin ~]#
新建一个PHP测试文件,测试是否可以访问php
[root@admin ~]# cat /var/www/html/info.php
<?php
phpinfo();
?>
[root@admin ~]#
重启httpd服务
[root@admin ~]# systemctl restart httpd.service
[root@admin ~]#
浏览器 IP+info.php 测试访问
下载wordpress 并解压
[root@admin ~]# wget https://cn.wordpress.org/latest-zh_CN.zip
--2024-04-07 16:10:58-- https://cn.wordpress.org/latest-zh_CN.zip
正在解析主机 cn.wordpress.org (cn.wordpress.org)... 198.143.164.252
正在连接 cn.wordpress.org (cn.wordpress.org)|198.143.164.252|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:27090973 (26M) [application/zip]
正在保存至: “latest-zh_CN.zip”
latest-zh_CN.zip 100%[================================================================>] 25.84M 8.99MB/s 用时 2.9s
2024-04-07 16:11:04 (8.99 MB/s) - 已保存 “latest-zh_CN.zip” [27090973/27090973])
[root@admin ~]#
[root@admin ~]# unzip latest-zh_CN.zip
Archive: latest-zh_CN.zip
creating: wordpress/
inflating: wordpress/wp-login.php
[root@admin ~]# ls
公共 模板 视频 图片 文档 下载 音乐 桌面 anaconda-ks.cfg latest-zh_CN.zip wordpress
将wordpress的文件复制到 /var/www/html/ 下 并授权
[root@admin ~]# \cp wordpress/* /var/www/html/ -r
[root@admin ~]# cd /var/www/html/
[root@admin html]# ls
index.php readme.html wp-blog-header.php wp-content wp-links-opml.php wp-mail.php wp-trackback.php
info.php wp-activate.php wp-comments-post.php wp-cron.php wp-load.php wp-settings.php xmlrpc.php
license.txt wp-admin wp-config-sample.php wp-includes wp-login.php wp-signup.php
[root@admin html]# rm -rf info.php && cd
[root@admin ~]# chown -R apache.apache /var/www/html/
[root@admin ~]#
浏览器访问 ip+index.php访问
点击开始前进去MySQL创建一个用户用作wordpress登录用户
[root@admin ~]# mysql -uroot -p1
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 24
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)]>
MariaDB [(none)]> create user 'admin'@'%' identified by '123456';
Query OK, 0 rows affected (0.003 sec)
MariaDB [(none)]> grant all privileges on . to 'admin'@'%';
Query OK, 0 rows affected (0.001 sec)
MariaDB [(none)]>
回到wordpress 点击开始填写
登录进入后页面
浏览器再次访问 ip 页面 弹出默认的wordpress页面