banner
云野阁

云野阁

闲云野鹤,八方逍遥

LAMP部署

基础环境#

系统环境:
CentOS Stream 9

软件环境:
Apache-2.4.57
Mysql-8.0.36(mariaDB)
PHP-8.0.30

部署过程#

配置安全策略#

firewall-cmd --add-port=80/tcp --permanent
firewall-cmd --reload
firewall-cmd --list-all

安装 Apache#

yum -y install httpd
systemctl start httpd
systemctl enable httpd
# 查看版本
httpd -v

安装 PHP#

# 安装php相应模块
yum -y install php php-curl php-dom php-exif php-fileinfo php-fpm php-gd php-hash php-mbstring php-mysqli php-openssl php-pcre php-xml
# 查看版本
php -v
# 测试php
echo "<?php phpinfo(); ?>" > /var/www/html/test.php
#在浏览器中访问http://本机ip/test.php
# 删除测试用例
rm -f /var/www/html/test.php

安装 Mysql#

yum -y install mysql-server
# 查看版本
mysql -V
systemctl start mysqld
systemctl enable mysqld
# 查看MySQL的初始密码
grep "password" /var/log/mysql/mysqld.log
# MySQL的安全性配置
mysql_secure_installation

Securing the MySQL server deployment.

Connecting to MySQL using a blank password.

VALIDATE PASSWORD COMPONENT can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD component?

Press y|Y for Yes, any other key for No: y

There are three levels of password validation policy:

LOW Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary file

Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 0
Please set the password for root here.

New password:

Re-enter new password:

Estimated strength of the password: 50
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL 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? (Press y|Y for Yes, any other key for No) : 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? (Press y|Y for Yes, any other key for No) : y
Success.

By default, MySQL 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? (Press y|Y for Yes, any other key for No) : 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? (Press y|Y for Yes, any other key for No) : y
Success.

All done!

验证测试#

安装 WordPress 进行验证 LAMP 的验证测试

(1)下载并配置 WordPress

cd /var/www/html/
# 安装下载解压工具
yum -y install wget tar
# 下载并解压WordPress程序
wget https://cn.wordpress.org/latest-zh_CN.tar.gz
tar zxvf latest-zh_CN.tar.gz

(2)创建数据库

create user 'wordpress'@'localhost' identified by 'wordpress@123';
grant all privileges on wordpress.* to 'wordpress'@'localhost';
flush privileges;
exit;

(3)重启服务

systemctl restart httpd

(4)WordPress 初始化配置

/var/www/html/wordpress中创建 wp-config.php 文件。

vi /var/www/html/wordpress/wp-config.php
**************************wp-config.php**************************
<?php
/**
 * WordPress 基础配置文件
 *
 * 这个文件被安装程序用于自动生成 wp-config.php 配置文件
 * 您不必使用网站,可以将这个文件复制到「wp-config.php」并填写这些值。
 *
 * 本文件包含以下配置选项:
 *
 * * 数据库设置
 * * 密钥
 * * 数据库表名前缀
 * * ABSPATH
 *
 * @link https://wordpress.org/documentation/article/editing-wp-config-php/
 *
 * @package WordPress
 */

// ** 数据库设置 - 您可以从您的主机获取这些信息 ** //
/** WordPress 数据库名称 */
define( 'DB_NAME', 'wordpress' );

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

/** 数据库密码 */
define( 'DB_PASSWORD', 'wordpress@123' );

/** 数据库主机 */
define( 'DB_HOST', 'localhost' );

/** 创建表时使用的数据库字符集。 */
define( 'DB_CHARSET', 'utf8mb4' );

/** 数据库排序规则类型。如不确定,请勿更改。 */
define( 'DB_COLLATE', '' );

/**#@+
 * 身份验证唯一密钥与盐。
 *
 * 将这些更改为任意独一无二的字符串!您可以使用
 * {@link https://api.wordpress.org/secret-key/1.1/salt/ WordPress.org 密钥服务}
 * 生成这些。
 *
 * 您可以随时更改这些内容以使所有现有 cookies 失效。
 * 这将强制所有用户必须重新登录。
 *
 * @since 2.6.0
 */
define( 'AUTH_KEY',         'T]opAWiO&i]=T0%gG|Cr8ZiHC4(AjG3#,Oa%Z,Xus}tB:CMH*m?TAJ!g8rCgn9G{' );
define( 'SECURE_AUTH_KEY',  'u]bD9(4N<|LD=!XlaLf8mI5vQM!!Wy,`=9[2g1g86Cp~EZnUe$q{P3W.[aH$n,bV' );
define( 'LOGGED_IN_KEY',    '-}sR0i@QOgDAbYWs:blZjDaJF-NdN|l5Vtiw2kVy(TUd0]:7~_)Lsg(t5kP>FVs~' );
define( 'NONCE_KEY',        ':*qn^%vaF;vWh$f/rR*SI8]Er=jpW{bKRWt4/F25b:ULoJGi&:*B{SP9D$Dx]t1=' );
define( 'AUTH_SALT',        ':1NyIcq-rH.2Qe@cH{xbKICQ`>!bmz_cKl@SQcLYM]||y9}dII:4j<d~sG~[mGR/' );
define( 'SECURE_AUTH_SALT', 'IRC$m2W;1CZ`PaR315_evXujKAgHr?x1.fLws,8tJ_$g+0EJkY?Y$LF*QXi*7h=l' );
define( 'LOGGED_IN_SALT',   'Zcg^hRDB5DXV<v?NxVNBMoT=s#mFvCw$A%!8{uBdl6EeZ`IhB.~8FNPprKgB>sKZ' );
define( 'NONCE_SALT',       'T#D,{:EEHw`~F~B2%R/TP*Kt-,/-| /](V-MJz7Nr?)XBr~rnEY*Hfs1rwUUMYi-' );

/**#@-*/

/**
 * WordPress 数据表前缀。
 *
 * 如果您为每个安装分配一个唯一前缀,您可以在一个数据库中拥有多个安装。
 * 请只使用数字、字母和下划线!
 */
$table_prefix = 'wp_';

/**
 * 开发者专用:WordPress 调试模式。
 *
 * 将此值更改为 true 以启用开发过程中的通知显示。
 * 强烈建议插件和主题开发人员在其开发环境中使用 WP_DEBUG。
 *
 * 有关可用于调试的其他常量的信息,请访问文档。
 *
 * @link https://wordpress.org/documentation/article/debugging-in-wordpress/
 */
define( 'WP_DEBUG', false );

/**
 * 简体中文专属:ICP 备案号显示
 *
 * 在设置 → 常规中设置你的 ICP 备案号。
 * 可调用简码 [cn_icp] 或函数 cn_icp() 显示。
 *
 * @since 6.5.0
 * @link https://cn.wordpress.org/support/i10n-features/
 */
define( 'CN_ICP', true );

/**
 * 简体中文专属:公安备案号显示
 *
 * 在设置 → 常规中设置你的公安备案号。
 * 可调用简码 [cn_ga] 或函数 cn_ga() 显示。
 *
 * @since 6.5.0
 * @link https://cn.wordpress.org/support/i10n-features/
 */
define( 'CN_GA', true );

/* 在这行和「停止编辑」行之间添加任何自定义值。 */



/* 就这样,停止编辑!祝您使用愉快。 */

/** WordPress 目录的绝对路径。 */
if ( ! defined( 'ABSPATH' ) ) {
    define( 'ABSPATH', __DIR__ . '/' );
}

/** 设置 WordPress 变量和包含的文件。 */
require_once ABSPATH . 'wp-settings.php';
**************************wp-config.php**************************

在浏览器中输入http://本地ip/wordpress,进行初始化配置。配置完成并登录 WordPress 之后,LAMP 验证测试成功。

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.