1. 程式人生 > >CentOS 7 基於yum方式快速搭建LAMP wordpress

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

LAMP是流行的經典快速部署網際網路應用的標配。 它的全稱是Linux+Apache+Mysql+PHP。之前寫過基於CentOS6下編譯以及yum方式搭建LAMP。本次主要主要是基於CentOS7來描述,同時演示了在該架構下安裝WordPress,供大家參考。

一、安裝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後,即可登陸到後臺管理面版
這裡寫圖片描述

這裡寫圖片描述
主頁介面
這裡寫圖片描述