用LAMP实现博客系统

Posted Happy_Future

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了用LAMP实现博客系统相关的知识,希望对你有一定的参考价值。

一、概述

lamp作为一个经典的组合,能够实现一些轻量级web服务的实现。本次用wordpress部署博客。

二、LAMP的部署

1、实现的基础框架

使用2台服务器做为服务端,数据库进行分开部署。

2、Mariadb的安装和初始化

yum install -y  mariadb-server mariadb

创建开机启动并启动数据库

[root@localhost ~]# systemctl enable --now 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.

加固mariadb

[root@localhost ~]# 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
you haven\'t set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none): 
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] n
 ... skipping.

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!

创建数据库账号并创建数据库

MariaDB [(none)]> create user "wordpress"@"192.168.22.%" identified by \'123456\';
Query OK, 0 rows affected (0.001 sec)
MariaDB [(none)]> create database wordpress;
Query OK, 1 row affected (0.000 sec)
MariaDB [(none)]> grant all on wordpress.* to "wordpress"@"192.168.22.%";
Query OK, 0 rows affected (0.000 sec)

2、HTTPD和php-FPM的安装

安装基础软件包和opcache php性能优化扩展包

yum install -y httpd 

因为wordpress需要php7.3以上,所以此处用编译安装php-fpm,安装编译依赖包,需要用到EPEL和POWERTOOL源。

yum -y install make gcc libxml2-devel bzip2-devel libmcrypt-devel sqlite-devel
oniguruma-devel openssl-devel

https://www.php.net/distributions/php-7.4.24.tar.gz
解压php源码包

tar xf php-7.4.24.tar.gz 

执行编译

./configure \\
--prefix=/etc/php74 \\
--enable-mysqlnd \\
--with-mysqli=mysqlnd \\
--with-pdo-mysql=mysqlnd \\
--with-openssl \\
--with-zlib \\
--with-config-file-path=/etc \\
--with-config-file-scan-dir=/etc/php.d \\
--enable-mbstring \\
--enable-xml \\
--enable-sockets \\
--enable-fpm \\
--enable-maintainer-zts \\
--disable-fileinfo

配置php环境变量

echo \'PATH=/etc/php74/bin:$PATH\' >> /etc/profile.d/php.sh

确认版本信息

复制php主配置文件

cd ~/php-7.4.24
cp php.ini-production /etc/php.ini
cp sapi/fpm/php-fpm.service /usr/lib/systemd/system/
cd /etc/php74/etc
cp php-fpm.conf.default php-fpm.conf
cd php-fpm.d/
cp www.conf.default www.conf

#修改进程所有者

#开启错误日志/etc/php74/etc/php-fpm.conf
error_log = /var/log/php-fpm/php-fpm-error.log
vim /apps/php74/etc/php-fpm.d/www.conf
user apache
group apache
#支持status和ping页面
pm.status_path = /fpm_status
ping.path = /ping
#支持opcache提升性能
mkdir /etc/php.d/
vim /etc/php.d/opcache.ini
[opcache]
zend_extension=opcache.so
opcache.enable=1

设置开机启动并启动服务

[root@localhost html]# systemctl daemon-reload
[root@localhost html]# systemctl enable --now httpd php-fpm
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.
Created symlink /etc/systemd/system/multi-user.target.wants/php-fpm.service → /usr/lib/systemd/system/php-fpm.service.

vhost的设定,在/etc/httpd/conf.d/添加vhost.conf

<virtualhost *:80>
servername blog.test.org
documentroot /var/www/html/wordpress
<directory /var/www/html/wordpress>
require all granted
</directory>
ProxyPassMatch ^/(.*\\.php)$ fcgi://127.0.0.1:9000/var/www/html/wordpress/$1
ProxyPassMatch ^/(status|ping)$ fcgi://127.0.0.1:9000/$1
CustomLog "logs/access_wordpress_log" common
</virtualhost>

3、下载wordpress软件包

wordpress最新版软件包
解压软件到/var/www/html目录中

tar -xf wordpress-5.8.1.tar.gz -C /var/www/html/

更改属主属组

chown -R apache.apache /var/www/html/wordpress

打开浏览器可以访问虚拟主机

填写数据连接信息

安装完成

管理员首页面板

三、总结

通过以上安装和配置操作,已经实现了基于vhost的博客。

以上是关于用LAMP实现博客系统的主要内容,如果未能解决你的问题,请参考以下文章

使用三台服务器搭建 lamp+nfs 的博客系统(wordpress)

CentOS6.6服务器系统配置(LAMP+phpMyAdmin)全流程

LAMP架构

LAMP基于php模块实现个人博客搭建

实现LAMP,wordpress搭建个人博客

001.WordPress建站部署