在Ubuntu 20.04上使用LAMP Stack安装最新的WordPress
欢迎来到我们的指南,了解如何在Ubuntu 20.04上使用LAMP Stack安装最新的WordPress。可能已经知道 WordPress的 是一个用PHP编写的免费开放源内容管理系统,主要用于创建免费网站或建立个人博客。
在Ubuntu 20.04上使用LAMP Stack安装最新的WordPress
先决条件
在Ubuntu 20.04上安装WordPress之前,必须先满足一些先决条件,然后才能继续。
运行系统更新
确保您的系统软件包是最新的。
apt update apt upgrade
安装LAMP / LEMP堆栈
WordPress是基于PHP的应用程序,因此,它需要安装LAMP或LEMP堆栈才能正常运行。在本演示中,我们使用LAMP堆栈运行WordPress。 Ubuntu 20.04作为Linux OS,PHP 7.4,MySQL 8和Apache作为Web服务器。
按照下面的链接在Ubuntu 20.04上安装LAMP Stack;
在Ubuntu 20.04上安装LAMP Stack
接下来,安装其他必需的PHP模块(如果尚未安装)。
apt install php7.4-{mysql,cli,json,opcache,xml,gd,curl}
创建WordPress MySQL数据库
登录MySQL并创建WordPress数据库;
mysql -u root -p
创建一个WordPress数据库。相应地替换数据库和数据库用户。
create database wpdb;
创建一个WordPress数据库用户并授予该数据库的所有特权。
create user [email protected] identified by '[email protected]#';
grant all on wpdb.* to [email protected];
重新加载数据库特权表并退出数据库。
flush privileges;
quit
在Ubuntu 20.04上安装最新的WordPress(5.x)
WordPress 5.4.1是本指南写作的最新版本。从下载最新版本的WordPress存档 WordPress下载页面。
wget https://wordpress.org/latest.tar.gz
创建您的Web根目录以在其中安装WordPress。相应地替换名称。
mkdir /var/www/html/wp.kifarunix-demo.com
接下来,将WordPress存档内容提取到上面创建的Web根目录中。
tar xzf latest.tar.gz -C /var/www/html/wp.kifarunix-demo.com --strip-components=1
验证WordPress文件到位。
ls /var/www/html/wp.kifarunix-demo.com
index.php wp-activate.php wp-comments-post.php wp-cron.php wp-load.php wp-settings.php xmlrpc.php license.txt wp-admin wp-config-sample.php wp-includes wp-login.php wp-signup.php readme.html wp-blog-header.php wp-content wp-links-opml.php wp-mail.php wp-trackback.php
在Ubuntu 20.04上配置WordPress
WordPress随附了一个示例配置, wp-config-sample.php
。重命名示例配置文件。
cp /var/www/html/wp.kifarunix-demo.com/wp-config{-sample,}.php
接下来,编辑配置文件并设置数据库连接详细信息,
vim /var/www/html/wp.kifarunix-demo.com/wp-config.php
更换 DB_NAME,DB_USER,DB_PASSWORD 使用您在为WordPress创建MySQL数据库时设置的值。
... // ** MySQL settings - You can get this info from your web host ** // /** The name of the database for WordPress */ define( 'DB_NAME', 'wpdb' ); /** MySQL database username */ define( 'DB_USER', 'wpadmin' ); /** MySQL database password */ define( 'DB_PASSWORD', '[email protected]#' ); /** MySQL hostname */ define( 'DB_HOST', 'localhost' ); /** Database Charset to use in creating database tables. */ define( 'DB_CHARSET', 'utf8' ); ...
接下来,生成身份验证唯一密钥和盐。您可以简单地从WordPress秘密密钥服务生成密钥和盐,如下所示;
curl -s https://api.wordpress.org/secret-key/1.1/salt/
define('AUTH_KEY', 'BkIM1nZ`;ni.E(^[email protected],R{bG%[email protected]=~=-];h%|bA{idi ^BTT|[7,l_L&i5UY');
define('SECURE_AUTH_KEY', 'WAgvv#q|d_EOhWk|;kKhE2&jO{h-G#oMz4,W;O)xH}VB63a2FV^*?oR$5w[tP0=h');
define('LOGGED_IN_KEY', '?|&6H,|v3}-_-(m[*m Kd<|3|m3QMLW5|>Tr=[I|b9q)! g*=H9vDpg(@');
define('NONCE_KEY', '&yq9[1N^f,P l IVMse<[email protected],yFkP!fE;_|+r[uD-?sbJQp|_e0?eXxtP~|$#8E');
define('NONCE_SALT', '[email protected]|+Hg;-w++_l;>-NL>+xB&r{FfQ*@E|ti/[email protected]]');
注意,请勿使用以上键。产生你的,
内 wp-config.php,用上述内容替换以下几行。
... * @since 2.6.0 */ define( 'AUTH_KEY', 'put your unique phrase here' ); define( 'SECURE_AUTH_KEY', 'put your unique phrase here' ); define( 'LOGGED_IN_KEY', 'put your unique phrase here' ); define( 'NONCE_KEY', 'put your unique phrase here' ); define( 'AUTH_SALT', 'put your unique phrase here' ); define( 'SECURE_AUTH_SALT', 'put your unique phrase here' ); define( 'LOGGED_IN_SALT', 'put your unique phrase here' ); define( 'NONCE_SALT', 'put your unique phrase here' ); /**#@-*/ ...
您的配置应如下所示;
...
* @since 2.6.0
*/
/**
* define( 'AUTH_KEY', 'put your unique phrase here' );
* define( 'SECURE_AUTH_KEY', 'put your unique phrase here' );
* define( 'LOGGED_IN_KEY', 'put your unique phrase here' );
* define( 'NONCE_KEY', 'put your unique phrase here' );
* define( 'AUTH_SALT', 'put your unique phrase here' );
* define( 'SECURE_AUTH_SALT', 'put your unique phrase here' );
* define( 'LOGGED_IN_SALT', 'put your unique phrase here' );
* define( 'NONCE_SALT', 'put your unique phrase here' );
*/
define('AUTH_KEY', 'BkIM1nZ`;ni.E(^[email protected],R{bG%[email protected]=~=-];h%|bA{idi ^BTT|[7,l_L&i5UY');
define('SECURE_AUTH_KEY', 'WAgvv#q|d_EOhWk|;kKhE2&jO{h-G#oMz4,W;O)xH}VB63a2FV^*?oR$5w[tP0=h');
define('LOGGED_IN_KEY', '?|&6H,|v3}-_-(m[*m Kd<|3|m3QMLW5|>Tr=[I|b9q)! g*=H9vDpg(@');
define('NONCE_KEY', '&yq9[1N^f,P l IVMse<[email protected],yFkP!fE;_|+r[uD-?sbJQp|_e0?eXxtP~|$#8E');
define('NONCE_SALT', '[email protected]|+Hg;-w++_l;>-NL>+xB&r{FfQ*@E|ti/[email protected]]');
/**#@-*/
...
保存并退出配置文件。
配置Apache Web服务器
为您的WordPress网站创建一个Apache虚拟主机配置。
vim /etc/apache2/sites-available/wordpress.conf
ServerAdmin [email protected]
ServerName wp.kifarunix-demo.com
DocumentRoot /var/www/html/wp.kifarunix-demo.com
AllowOverride All
ErrorLog /var/log/apache2/wp.error.log
CustomLog /var/log/apache2/wp.access.log combined
保存并退出配置文件。
将您的站点配置的用户和组所有权设置为Apache用户, www-data
。
chown -R www-data:www-data /var/www/html/wp.kifarunix-demo.com
检查Apache语法错误;
apachectl -t
如果你得到, Syntax OK
,继续启用WordPress网站配置。
a2ensite wordpress.conf
禁用默认的Apache网站;
a2dissite 000-default.conf
重新启动Apache;
systemctl restart apache2
如果UFW正在运行,请打开端口80 / tcp以允许外部访问。
ufw allow 80/tcp
在Ubuntu 20.04上完成WordPress安装
要在Ubuntu 20.04上完成WordPress的设置,请导航至浏览器并访问WordPress网站, http://
。
选择您的WordPress安装语言,然后单击 继续。
设置站点标题,用户名,密码,电子邮件地址,选择禁用还是启用站点索引并在Ubuntu 20.04上安装WordPress。
安装完成后,使用您刚创建的用户名和密码登录到WordPress。然后你去。您的WordPress已成功设置。
您现在可以在WordPress博客上编写和发布您的东西。这使我们结束了关于如何在Ubuntu 20.04上使用LAMP Stack安装最新WordPress的指南的结尾。
。