CentOS 7 基于yum方式快速搭建LAMP wordpress

本文涉及的产品
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
RDS MySQL Serverless 高可用系列,价值2615元额度,1个月
简介: LAMP是流行的经典快速部署互联网应用的标配。 它的全称是Linux+Apache+Mysql+PHP。

LAMP是流行的经典快速部署互联网应用的标配。 它的全称是Linux+Apache+Mysql+PHP。之前写过基于CentOS6下编译以及yum方式搭建LAMP。本次主要主要是基于CentOS7来描述,同时演示了在该架构下安装WordPress,供大家参考。

有关CentOS 6下搭建文章可参考:
Linux 6 下yum方式安装配置LAMP平台
Linux 6下编译安装配置LAMP平台

一、安装LAMP

当前环境
[root@centos7-web ~]# more /etc/redhat-release 
CentOS Linux release 7.2.1511 (Core) 

基于yum方式安装httpd,php,mariadb
[root@centos7-web ~]# yum install httpd -y
[root@centos7-web ~]# yum install php php-mysql -y 
[root@centos7-web ~]# yum install mariadb-server -y

验证相关安装包
[root@centos7-web ~]# rpm -qa|grep httpd
httpd-2.4.6-40.el7.centos.x86_64
httpd-tools-2.4.6-40.el7.centos.x86_64

[root@centos7-web ~]# rpm -qa|grep php
php-cli-5.4.16-36.el7_1.x86_64
php-mysql-5.4.16-36.el7_1.x86_64
php-common-5.4.16-36.el7_1.x86_64
php-pdo-5.4.16-36.el7_1.x86_64
php-5.4.16-36.el7_1.x86_64

[root@centos7-web ~]# rpm -qa|grep maria
mariadb-libs-5.5.44-2.el7.centos.x86_64
mariadb-server-5.5.44-2.el7.centos.x86_64
mariadb-5.5.44-2.el7.centos.x86_64

启动及验证httpd
[root@centos7-web ~]# systemctl start httpd
[root@centos7-web ~]# ss -nltp|grep httpd
LISTEN    0    128   :::80  :::*      users:(("httpd",pid=120703,fd=4),("httpd",pid=120702,fd=4),
("httpd",pid=120701,fd=4),("httpd",pid=120700,fd=4),("httpd",pid=120699,fd=4),("httpd",pid=120688,fd=4))

[root@centos7-web ~]# echo "This is a httpd test page.">/var/www/html/index.html
[root@centos7-web ~]# curl http://localhost
This is a httpd test page.

启动及验证mariadb
[root@centos7-web ~]# rpm -ql mariadb-server|grep service
/usr/lib/systemd/system/mariadb.service

[root@centos7-web ~]# systemctl start mariadb.service
[root@centos7-web ~]# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.44-MariaDB MariaDB Server

Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> show variables like 'version';
+---------------+----------------+
| Variable_name | Value          |
+---------------+----------------+
| version      | 5.5.44-MariaDB |
+---------------+----------------+
1 row in set (0.00 sec)

MariaDB [(none)]> show databases;

+--------------------+
| Database          |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test              |
+--------------------+
4 rows in set (0.00 sec)

MariaDB [(none)]> exit
Bye

测试PHP
    由于当前PHP使用模块化方式被装载到httpd,因此无需单独启动及设置PHP,如下可以检测到已加载php5模块以及rewrite模块
[root@centos7-web ~]# httpd -M|grep php
php5_module (shared)
[root@centos7-web ~]# httpd -M|grep rewrite
rewrite_module (shared)

[root@centos7-web ~]# echo " 
<html>
<h1>This is a php test page.</h1>
<?php
phpinfo();
?>
</html>">/var/www/html/index.php 

[root@centos7-web ~]# curl http://localhost/index.php
<html>
<h1>This is a php test page.</h1>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head>
<style type="text/css">
body {background-color: #ffffff; color: #000000;}
body, td, th, h1, h2 {font-family: sans-serif;}
pre {margin: 0px; font-family: monospace;}
a:link {color: #000099; text-decoration: none; background-color: #ffffff;}
a:hover {text-decoration: underline;}
table {border-collapse: collapse;}
           .............

验证PHP连接mariadb数据库
[root@centos7-web ~]# vim /var/www/html/connmysql.php
<?php
        $conn
        if ($conn
                echo "succ";
        else
                echo "

        mysql_close();
?>

[root@centos7-web ~]# curl http://localhost/connmysql.php
succ

二、安装及配置wordpress

[root@centos7-web ~]# cd /usr/local/src
[root@centos7-web src]# ls -hltr
total 8.3M
-rw-r--r-- 1 root root 8.3M Sep 22 17:17 wordpress-4.8.1-zh_CN.tar.gz

[root@centos7-web src]# tar -xf wordpress-4.8.1-zh_CN.tar.gz
[root@centos7-web src]# cp -R wordpress /var/www/html/

[root@centos7-web ~]# cp /var/www/html/wordpress/wp-config-sample.php /var/www/html/wordpress/wp-config.php
[root@centos7-web ~]# vim /var/www/html/wordpress/wp-config.php
###主要是配置数据库名及用户密码
/** WordPress数据库的名称 */
define('DB_NAME', 'wpdb');

/** MySQL数据库用户名 */
define('DB_USER', 'wpadmin');

/** MySQL数据库密码 */
define('DB_PASSWORD', 'pass');

/** MySQL主机 */
define('DB_HOST', 'localhost');

/** 创建数据表时默认的文字编码 */
define('DB_CHARSET', 'utf8');

/** 数据库整理类型。如不确定请勿更改 */
define('DB_COLLATE', '');

创建wordpress数据库及用户
[root@centos7-web ~]# mysql

MariaDB [(none)]> create database wpdb character set utf8;
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> grant all privileges on wpdb.* to 'wpadmin'@'localhost' identified by 'pass';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)

配置wordpress
打开浏览器完成wordpress配置
这里写图片描述

安装wordpress后,即可登陆到后台管理面版
这里写图片描述

这里写图片描述
主页界面
这里写图片描述

相关实践学习
如何在云端创建MySQL数据库
开始实验后,系统会自动创建一台自建MySQL的 源数据库 ECS 实例和一台 目标数据库 RDS。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助 &nbsp; &nbsp; 相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
目录
相关文章
|
1月前
|
网络协议 Linux
CentOS7 yum安装报错“Could not resolve host: mirrorlist.centos.org;"之解决办法(换源)
CentOS7 yum安装报错“Could not resolve host: mirrorlist.centos.org; Name or service not known“之解决办法(换源)
|
22天前
|
缓存 Linux 网络安全
解决 CentOS 7 官方 yum 仓库无法使用的最佳实践
【8月更文挑战第18天】若 CentOS 7 的官方 YUM 仓库无法使用,可按以下步骤解决: 1. **检查网络连接**: - 确认服务器能正常上网,可通过访问外部网站或网络诊断测试。 - 检查防火墙设置,避免其阻挡 YUM 的网络访问。 2. **检查 YUM 配置**: - 核实 `/etc/yum.repos.d/` 下的 `CentOS-Base.repo` 文件中仓库地址正确无误。 - 确认配置文件内的 `enabled` 选项设为 `1` 以启用仓库。
275 0
|
27天前
|
安全 Java 应用服务中间件
如何通过 Yum 在 CentOS 7 上安装 Apache Tomcat 7
如何通过 Yum 在 CentOS 7 上安装 Apache Tomcat 7
69 0
|
29天前
|
jenkins Java Devops
CentOS 7上安装 Jenkins 2.346 -- yum 方式
CentOS 7上安装 Jenkins 2.346 -- yum 方式
42 0
|
29天前
|
jenkins Linux 持续交付
CentOS 7上安装 Jenkins 2.227 -- yum 方式
CentOS 7上安装 Jenkins 2.227 -- yum 方式
84 0
|
3月前
|
缓存 Linux
CentOS7添加阿里云yum源
CentOS7添加阿里云yum源
3517 1
|
4月前
|
安全 Linux 虚拟化
解决Centos7 yum 出现could not retrieve mirrorlist 错误
在新安装的CentOS7.x通过VMware后,遇到无法通过`ip addr`获取IP地址以及`yum`安装软件时加载镜像列表失败的问题。
1218 2
|
4月前
|
Linux
CentOS 7 配置yum阿里源 (三步即可)
CentOS 7 配置yum阿里源 (三步即可)
7687 1
|
4月前
|
弹性计算 关系型数据库 Shell
安装 LAMP 环境(yum 版本)
【4月更文挑战第29天】
61 5
|
4月前
|
存储 Linux 网络安全
centos7使用yum网络安装
这些是使用Yum进行网络安装的基本步骤。根据你的需求,你可以重复步骤3和4来安装其他软件包。请注意,执行Yum操作需要root或具有sudo权限的用户。
178 1