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

2018-08-06 10:44:18 浏览数 (1)

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

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

一、安装LAMP

代码语言:javascript复制
当前环境
[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

代码语言:javascript复制
[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后,即可登陆到后台管理面版

主页界面

0 人点赞