0
点赞
收藏
分享

微信扫一扫

LAMP实战案例: 在一台服务器上实现 wordpress 应用部署

在一台服务器上实现 wordpress 应用部署

基本任务:本范例是在一台服务器上实现 wordpress 应用部署。目前云ECS主机比较便宜了,对于那些IT爱好者自己建个人博客、论坛等提供很好的契机,LAMP架构是中小企业和个人建站的最经济高效的一个解决方案,利用开源LAMP套包,可以在同一个ECS主机上实现多虚拟主机的应用。

1. 架构及主机

LAMP实战案例: 在一台服务器上实现 wordpress 应用部署_个人建站

# 一台服务器
Apache(httpd)+PHP (php-fpm模式) + MariaDB
CentOS 8.4
IP: 192.168.250.48/24
10.3.28-MariaDB

2. 安装软件包并配置

[root@CentOS84 ]#cd /data
[root@CentOS84 ]#pwd
/data
[root@CentOS84 ]#
# 下载博客PHP源文件包
[root@CentOS84 ]#wget https://cn.wordpress.org/latest-zh_CN.zip
[root@CentOS84 ]#ll
total 20656
-rw-r--r-- 1 root root 21064643 Mar 3 03:00 latest-zh_CN.zip
# 解压后的文件夹名为wordpress
[root@CentOS84 ]#unzip latest-zh_CN.zip
Archive: latest-zh_CN.zip
creating: wordpress/
......................
[root@CentOS84 ]#ll -h
-rw-r--r-- 1 root root 21M Mar 3 03:00 latest-zh_CN.zip
drwxr-xr-x 5 root root 4.0K Mar 3 03:00 wordpress
[root@CentOS84 ]#pwd
/data
[root@CentOS84 ]#cd wordpress
[root@CentOS84 ]#ll
total 212
-rw-r--r-- 1 root root 405 Feb 6 2020 index.php
-rw-r--r-- 1 root root 19915 Jan 1 08:15 license.txt
-rw-r--r-- 1 root root 7437 Dec 29 01:38 readme.html
-rw-r--r-- 1 root root 7165 Jan 21 2021 wp-activate.php
drwxr-xr-x 9 root root 4096 Mar 3 03:00 wp-admin
-rw-r--r-- 1 root root 351 Feb 6 2020 wp-blog-header.php
-rw-r--r-- 1 root root 2338 Nov 10 07:07 wp-comments-post.php
-rw-r--r-- 1 root root 3001 Dec 14 16:44 wp-config-sample.php
drwxr-xr-x 5 root root 69 Mar 3 03:00 wp-content
-rw-r--r-- 1 root root 3939 Aug 3 2021 wp-cron.php
drwxr-xr-x 26 root root 12288 Mar 3 03:00 wp-includes
-rw-r--r-- 1 root root 2496 Feb 6 2020 wp-links-opml.php
-rw-r--r-- 1 root root 3900 May 16 2021 wp-load.php
-rw-r--r-- 1 root root 47916 Jan 4 16:30 wp-login.php
-rw-r--r-- 1 root root 8582 Sep 23 05:01 wp-mail.php
-rw-r--r-- 1 root root 23025 Dec 1 01:32 wp-settings.php
-rw-r--r-- 1 root root 31959 Oct 25 08:23 wp-signup.php
-rw-r--r-- 1 root root 4747 Oct 9 2020 wp-trackback.php
-rw-r--r-- 1 root root 3236 Jun 9 2020 xmlrpc.php
[root@CentOS84 ]#

# yum在线方式安装 httpd php php-json php-mysqlnd mariadb-server
[root@CentOS84 ]#dnf -y install httpd php php-json php-mysqlnd mariadb-server

# 修改PHP的配置文件,特别提醒:在实际生产中修改下面的主要行后,要把 “#.....”的注释删除掉
[root@CentOS84 ]#vim /etc/php.ini
# 此文件比较长,只列出需要修改的几行
expose_php = On #响应报文显示首部字段x-powered-by: PHP/x.y.z,暴露php版本,建议为off
max_execution_time= 30 #最长执行时间30s
memory_limit=1024M #生产不够,可调大
display_errors=off #调试使用,不要打开,否则可能暴露重要信息
display_startup_errors=off #建议关闭
post_max_size=1000M #最大上传数据大小,生产可能调大,比下面项大
upload_max_filesize =20M #最大上传文件,生产可能要调大
max_file_uploads = 50 #同时上传最多文件数
date.timezone =Asia/Shanghai #指定时区
short_open_tag=on #开启短标签,如: <? phpinfo();?>

# 新建一个php的状态查看页面,这个步骤很利于调试
[root@CentOS84 ]#vim /var/www/html/phpinfo.php
[root@CentOS84 ]#cat /var/www/html/phpinfo.php
<?php
phpinfo();
?>

# 启动 httpd和mariadb并开机运行
[root@CentOS84 ]#systemctl enable --now httpd mariadb
[root@CentOS84 ]#systemctl enable --now php-fpm

# 登录数据库创建 wordpress 库并授权 实际生产中建议对数据库root等账号均需要设定好复杂的密&码;同时要做好主机的防火墙等配置,确保主机访问安全
[root@CentOS84 ]#mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 8
Server version: 10.3.28-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 wordpress;
Query OK, 1 row affected (0.000 sec)

MariaDB [(none)]> grant all on wordpress.* to wordpress@'localhost' identified by 'shone123456';
Query OK, 0 rows affected (0.001 sec)

MariaDB [(none)]> quit
Bye
[root@CentOS84 ]#

[root@CentOS84 ]#mv wordpress/* /var/www/html/
# 如果需要在一台机器上实现博客和论坛,建议在/var/www/html/下建好两个目录wordpress 和 Discuz 分别存放对应的文件,本次我们只演示一个论坛,直接将wordpress的所有文件放在主目录下
[root@CentOS84 ]#ll /var/www/html/
total 212
-rw-r--r-- 1 apache apache 405 Feb 6 2020 index.php
-rw-r--r-- 1 apache apache 19915 Jan 1 08:15 license.txt
-rw-r--r-- 1 apache apache 7437 Dec 29 01:38 readme.html
-rw-r--r-- 1 apache apache 7165 Jan 21 2021 wp-activate.php
drwxr-xr-x 9 apache apache 4096 Mar 3 03:00 wp-admin
-rw-r--r-- 1 apache apache 351 Feb 6 2020 wp-blog-header.php
-rw-r--r-- 1 apache apache 2338 Nov 10 07:07 wp-comments-post.php
-rw-r--r-- 1 apache apache 3001 Dec 14 16:44 wp-config-sample.php
drwxr-xr-x 5 apache apache 69 Mar 3 03:00 wp-content
-rw-r--r-- 1 apache apache 3939 Aug 3 2021 wp-cron.php
drwxr-xr-x 26 apache apache 12288 Mar 3 03:00 wp-includes
-rw-r--r-- 1 apache apache 2496 Feb 6 2020 wp-links-opml.php
-rw-r--r-- 1 apache apache 3900 May 16 2021 wp-load.php
-rw-r--r-- 1 apache apache 47916 Jan 4 16:30 wp-login.php
-rw-r--r-- 1 apache apache 8582 Sep 23 05:01 wp-mail.php
-rw-r--r-- 1 apache apache 23025 Dec 1 01:32 wp-settings.php
-rw-r--r-- 1 apache apache 31959 Oct 25 08:23 wp-signup.php
-rw-r--r-- 1 apache apache 4747 Oct 9 2020 wp-trackback.php
-rw-r--r-- 1 apache apache 3236 Jun 9 2020 xmlrpc.php

# 所有的文件修改完成,数据库也配置好了,重新启动服务
[root@CentOS84 ]#systemctl restart httpd mariadb php-fpm

# 验证服务启动
[root@CentOS84 ]#systemctl status httpd mariadb
● httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
Drop-In: /usr/lib/systemd/system/httpd.service.d
└─php-fpm.conf
Active: active (running) since Fri 2022-03-04 04:46:24 CST; 20min ago
Docs: man:httpd.service(8)
Main PID: 7262 (httpd)
Status: "Total requests: 12; Idle/Busy workers 100/0;Requests/sec: 0.0096; Bytes served/sec: 7 B/sec"
Tasks: 278 (limit: 23544)
Memory: 49.8M
CGroup: /system.slice/httpd.service
├─7262 /usr/sbin/httpd -DFOREGROUND
├─7334 /usr/sbin/httpd -DFOREGROUND
├─7335 /usr/sbin/httpd -DFOREGROUND
├─7336 /usr/sbin/httpd -DFOREGROUND
├─7337 /usr/sbin/httpd -DFOREGROUND
└─7729 /usr/sbin/httpd -DFOREGROUND

Mar 04 04:46:24 CentOS84 systemd[1]: Starting The Apache HTTP Server...
Mar 04 04:46:24 CentOS84 httpd[7262]: AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using>
Mar 04 04:46:24 CentOS84 systemd[1]: Started The Apache HTTP Server.
Mar 04 04:46:25 CentOS84 httpd[7262]: Server configured, listening on: port 80

● mariadb.service - MariaDB 10.3 database server
Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled)
Active: active (running) since Fri 2022-03-04 04:46:28 CST; 20min ago
Docs: man:mysqld(8)
https://mariadb.com/kb/en/library/systemd/
Process: 7642 ExecStartPost=/usr/libexec/mysql-check-upgrade (code=exited, status=0/SUCCESS)
Process: 7290 ExecStartPre=/usr/libexec/mysql-prepare-db-dir mariadb.service (code=exited, status=0/SUCCESS)
Process: 7263 ExecStartPre=/usr/libexec/mysql-check-socket (code=exited, status=0/SUCCESS)
Main PID: 7611 (mysqld)
Status: "Taking your SQL requests now..."
Tasks: 30 (limit: 23544)
Memory: 88.4M
CGroup: /system.slice/mariadb.service
└─7611 /usr/libexec/mysqld --basedir=/usr

Mar 04 04:46:27 CentOS84 mysql-prepare-db-dir[7290]: See the MariaDB Knowledgebase at http://mariadb.com/kb or the
Mar 04 04:46:27 CentOS84 mysql-prepare-db-dir[7290]: MySQL manual for more instructions.
Mar 04 04:46:27 CentOS84 mysql-prepare-db-dir[7290]: Please report any problems at http://mariadb.org/jira
Mar 04 04:46:27 CentOS84 mysql-prepare-db-dir[7290]: The latest information about MariaDB is available at http://mariadb.org/.
Mar 04 04:46:27 CentOS84 mysql-prepare-db-dir[7290]: You can find additional information about the MySQL part at:
Mar 04 04:46:27 CentOS84 mysql-prepare-db-dir[7290]: http://dev.mysql.com
Mar 04 04:46:27 CentOS84 mysql-prepare-db-dir[7290]: Consider joining MariaDB's strong and vibrant community:
Mar 04 04:46:27 CentOS84 mysql-prepare-db-dir[7290]: https://mariadb.org/get-involved/
Mar 04 04:46:27 CentOS84 mysqld[7611]: 2022-03-04 4:46:27 0 [Note] /usr/libexec/mysqld (mysqld 10.3.28-MariaDB) starting as proce>
Mar 04 04:46:28 CentOS84 systemd[1]: Started MariaDB 10.3 database server.

3. 登录网页初始化论坛

3.1 php状态页

LAMP实战案例: 在一台服务器上实现 wordpress 应用部署_个人建站_02

3.2 博客wordpress 初始化

浏览器登录 http://192.168.250.48/ 输入前面数据库配置时候的用户名和密&码

LAMP实战案例: 在一台服务器上实现 wordpress 应用部署_个人建站_03

运行wordpress 安装程序

LAMP实战案例: 在一台服务器上实现 wordpress 应用部署_apache_04

LAMP实战案例: 在一台服务器上实现 wordpress 应用部署_LAMP_05


经过上面步骤完成了wordpress初始化安装过程,登录wordpress就可以进行管理等个性化配置了

LAMP实战案例: 在一台服务器上实现 wordpress 应用部署_php_06

LAMP实战案例: 在一台服务器上实现 wordpress 应用部署_个人建站_07

LAMP实战案例: 在一台服务器上实现 wordpress 应用部署_LAMP_08

LAMP实战案例: 在一台服务器上实现 wordpress 应用部署_php_09


至此整个博客的基本配置全部完成了!

4. 验证

[root@CentOS84 ]#ss -tlnp
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 80 *:3306 *:* users:(("mysqld",pid=7611,fd=22))
LISTEN 0 511 *:80 *:* users:(("httpd",pid=7729,fd=4),("httpd",pid=7337,fd=4),("httpd",pid=7336,fd=4),("httpd",pid=7335,fd=4),("httpd",pid=7262,fd=4))
[root@CentOS84 ]#

[root@CentOS84 ]#
[root@CentOS84 ]#
[root@CentOS84 ]#mysql -uroot
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 12
Server version: 10.3.28-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)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| wordpress |
+--------------------+
4 rows in set (0.002 sec)

MariaDB [(none)]> use wordpress
Database changed
MariaDB [wordpress]> show tables;
Empty set (0.001 sec)

MariaDB [wordpress]> show tables;
+-----------------------+
| Tables_in_wordpress |
+-----------------------+
| wp_commentmeta |
| wp_comments |
| wp_links |
| wp_options |
| wp_postmeta |
| wp_posts |
| wp_term_relationships |
| wp_term_taxonomy |
| wp_termmeta |
| wp_terms |
| wp_usermeta |
| wp_users |
+-----------------------+
12 rows in set (0.001 sec)

MariaDB [wordpress]>
举报

相关推荐

0 条评论