LAMP+WordPress
一、简介
LAMP:
- L:linux——操作系统,提供服务器运行的基础环境。
- A:apache(httpd)——网页服务器软件,负责处理HTTP请求和提供网页内容。
- M:mysql,mariadb——数据库管理系统,用于存储网站数据。
- P:php,perl,python——服务器端脚本语言,用于生成动态网页内容。
LAMP的特点包括:
- 开源:所有组件都是开源的,这意味着它们可以免费使用,并且有活跃的社区支持。
- 灵活性:LAMP组件可以灵活配置,以适应不同的网站需求。
- 广泛支持:由于其流行度,有大量的教程、文档和工具来支持LAMP环境。
- 稳定性:Linux和Apache都是经过长期测试的稳定系统。
- 安全性:虽然任何系统都可能面临安全威胁,但LAMP组件有定期的安全更新和补丁。
WordPress:
WordPress是一个开源的内容管理系统,最初于2003年被开发用来简化个人在线写作,但随着时间的发展,它已经成长为一个全功能的网站框架。WordPress使用PHP编写,使用MySQL作为数据库管理系统。
WordPress的特点包括:
- 易用性:WordPress有一个直观的后台管理界面,使得即使是非技术用户也能轻松管理网站。
- 可扩展性:通过插件和主题,WordPress可以扩展其功能,适应各种网站需求。
- 社区支持:有一个庞大的社区,提供帮助、教程和资源。
- SEO友好:WordPress支持搜索引擎优化(SEO),有助于提高网站在搜索引擎中的排名。
- 多语言支持:WordPress支持多种语言,可以创建多语言网站。
- 移动友好:WordPress主题和插件支持响应式设计,确保网站在各种设备上都能良好显示。
LAMP和WordPress经常一起使用,因为WordPress可以在LAMP环境中运行,利用Apache作为服务器,MySQL作为数据库,PHP作为脚本语言。这种组合提供了一个强大而灵活的平台,用于构建和维护网站。
二、搭建
下载需要的软件包,启动数据库和httpd
[root@node1 ~]# yum -y mariadb mariadb-server httpd
[root@node1 ~]# systemctl restart mariadb
[root@node1 ~]# systemctl enable mariadb
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.
[root@node1 ~]#
配置数据库,初始化数据库
[root@node1 ~]# 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]
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] n # 远程连接
... skipping.
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 # 是否删除原来的默认表
- 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@node1 ~]#
安装php,配置php文件,设置php的时区并启动php
[root@node1 ~]# yum -y install php php-cli php-fpm php-gd php-curl php-zip php-mbstring php-opcache php-intl php-mysqlnd
[root@node1 ~]# vim /etc/php.ini
date.timezone = Asia/Shanghai
[root@node1 ~]# systemctl enable php-fpm
Created symlink /etc/systemd/system/multi-user.target.wants/php-fpm.service → /usr/lib/systemd/system/php-fpm.service.
[root@node1 ~]#
为php做一个网页
[root@node1 ~]# cd /var/www/html/
[root@node1 html]# vim index.php
[root@node1 html]# cat index.php
<?php
phpinfo
?>
[root@node1 html]#
更改apache的配置文件,是其支持php的网页
[root@node1 ~]# vim /etc/httpd/conf/httpd.conf
<IfModule dir_module>
DirectoryIndex index.html index.php
</IfModule>
浏览器访问ip查看网页,看到默认的网页
192.168.100.10
基本架构已经做好
基于此架构部署wordpress
准备好wordpress安装包,解压
[root@node1 ~]# mkdir /etc/software
[root@node1 ~]# cd /etc/software
#上传安装包
[root@node1 software]# ls
wordpress wordpress-6.5.5.tar.gz
[root@node1 software]# cp -r wordpress /var/www/html/ # 移动到默认网页下面
[root@node1 software]# ls /var/www/html/
index.php wordpress
[root@node1 software]#
更改wordpress的所属主所属组,更改权限为775
[root@node1 html]# cd /var/www/html/
[root@node1 html]# ll -ld wordpress/
drwxr-xr-x 5 root root 4096 Jul 16 09:47 wordpress/
[root@node1 html]# chown -R apache.apache /var/www/html/wordpress/
[root@node1 html]# ll -ld wordpress/
drwxr-xr-x 5 apache apache 4096 Jul 16 09:47 wordpress/
[root@node1 html]# chmod -R 775 /var/www/html/wordpress/
[root@node1 html]# ll -ld wordpress/
drwxrwxr-x 5 apache apache 4096 Jul 16 09:47 wordpress/
为数据库做配置
[root@node1 html]# mysql -u root -p # 登录数据库
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 12
Server version: 10.5.22-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 database sjk_db; # 创建数据表
Query OK, 1 row affected (0.000 sec)
MariaDB [(none)]> create user 'wordpress_user'@'localhost' identified by 'linux' # 设置用户名和密码
-> ;
Query OK, 0 rows affected (0.001 sec)
MariaDB [(none)]> grant all on sjk_db.* to 'wordpress_user'@'localhost' # 为用户设置权限
-> ;
Query OK, 0 rows affected (0.001 sec)
MariaDB [(none)]> flush privileges; # 同步设置
Query OK, 0 rows affected (0.000 sec)
MariaDB [(none)]>
使用虚拟主机来配置apache,更改配置文件
[root@node1 html]# cp -r /usr/share/doc/httpd-core/httpd-vhosts.conf /etc/httpd/conf.d
[root@node1 html]# vim /etc/httpd/conf.d/httpd-vhosts.conf
<VirtualHost 192.168.100.10:80>
DocumentRoot "/var/www/html/wordpress"
<Directory "/var/www/html/wordpress">
Options Indexes FollowSymLinks
AllowOverride all
Require all granted
</Directory>
配置好配置文件后启动httpd,访问ip查看网页内容
192.168.100.10
登录
完成!