安卓系统

如何在Ubuntu 18.04上使用Apache安装Wordpress

ubuntu 18.04手动安装wordpress / install worpress on ubuntu 18.04(并初步打造成一个网站的样子)

ubuntu 18.04手动安装wordpress / install worpress on ubuntu 18.04(并初步打造成一个网站的样子)

目录:

Anonim

WordPress是迄今为止最受欢迎的开源博客和CMS平台,为全球四分之一的网站提供支持。 它基于PHP和MySQL,并包含大量功能,可以使用免费和高级插件和主题进行扩展。 WordPress使您可以轻松地建立自己的电子商务商店,网站,产品组合或博客。

在本教程中,我们将向您展示如何在Ubuntu 18.04计算机上安装WordPress。 这是一个相当简单的过程,只需不到十分钟即可完成。 在撰写本文时,WordPress的最新版本是5.0.2。

我们将使用LAMP堆栈,其中Apache作为Web服务器,SSL证书,最新的PHP 7.2和MySQL / MariaDB作为数据库服务器。

先决条件

在继续本教程之前,请确保满足以下先决条件:

  • 有一个域名指向您的服务器公用IP。 我们将使用 example.com 。以具有sudo特权的用户身份登录。请按照以下说明安装Apache。您已经为您的域安装了SSL证书。 您可以按照以下说明安装免费的“让我们加密SSL”证书。

更新软件包列表,并将已安装的软件包升级到最新版本:

sudo apt update sudo apt upgrade

创建一个MySQL数据库

WordPress使用MySQL数据库存储其所有数据,如帖子,页面,用户,插件和主题设置。 我们将首先创建一个MySQL数据库,MySQL用户帐户并授予对该数据库的访问权限。

如果您的Ubuntu服务器上未安装MySQL或MariaDB,则可以按照以下指南之一进行操作:

通过键入以下命令登录到MySQL Shell:

sudo mysql

在MySQL Shell中,运行以下SQL语句以创建数据库:

CREATE DATABASE wordpress CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;

接下来,创建一个MySQL用户帐户并授予对数据库的访问权限:

GRANT ALL ON wordpress.* TO 'wordpressuser'@'localhost' IDENTIFIED BY 'change-with-strong-password';

最后,输入以下命令退出mysql控制台:

EXIT

安装PHP

PHP 7.2是Ubuntu 18.04中的默认PHP版本,完全受支持,建议WordPress使用。

要安装PHP和所有必需的PHP扩展,请运行以下命令:

sudo apt install php7.2 php7.2-cli php7.2-mysql php7.2-json php7.2-opcache php7.2-mbstring php7.2-xml php7.2-gd php7.2-curl

重新启动Apache,以便加载新安装的PHP扩展:

sudo systemctl restart apache2

下载Wordpress

在下载Wordpress存档之前,首先创建一个目录,其中将存放我们的WordPress文件:

sudo mkdir -p /var/www/example.com

下一步是使用以下wget命令从WordPress下载页面下载最新版本的WordPress:

cd /tmp wget

下载完成后,解压缩存档并将解压缩的文件移到域的文档根目录中:

tar xf latest.tar.gz sudo mv /tmp/wordpress/* /var/www/example.com/

设置正确的权限,以便Web服务器可以使用以下chown命令完全访问站点的文件和目录:

sudo chown -R www-data: /var/www/example.com

配置Apache

到目前为止,如果没有检查本教程的先决条件,则应该已经在系统上安装了带有SSL证书的Apache。

下一步是为我们的WordPress域编辑Apache虚拟主机配置:

sudo nano /etc/apache2/sites-available/example.com.conf

以下Apache配置将 http 重定向到 https ,将 www 重定向到您域的 non-www 版本,并启用HTTP2。 不要忘记用您的Wordpress域替换 example.com 并为SSL证书文件设置正确的路径。

/etc/apache2/sites-available/example.com.conf

ServerName example.com ServerAlias www.example.com Redirect permanent / https://example.com/ ServerName example.com ServerAlias www.example.com Protocols h2 http:/1.1 Redirect permanent / https://example.com/ DirectoryIndex index.html index.php DocumentRoot /var/www/example.com ErrorLog ${APACHE_LOG_DIR}/example.com-error.log CustomLog ${APACHE_LOG_DIR}/example.com-access.log combined SSLEngine On SSLCertificateFile /etc/letsencrypt/live/example.com/cert.pem SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem SSLCertificateChainFile /etc/letsencrypt/live/example.com/chain.pem Options FollowSymLinks AllowOverride All Require all granted ServerName example.com ServerAlias www.example.com Redirect permanent / https://example.com/ ServerName example.com ServerAlias www.example.com Protocols h2 http:/1.1 Redirect permanent / https://example.com/ DirectoryIndex index.html index.php DocumentRoot /var/www/example.com ErrorLog ${APACHE_LOG_DIR}/example.com-error.log CustomLog ${APACHE_LOG_DIR}/example.com-access.log combined SSLEngine On SSLCertificateFile /etc/letsencrypt/live/example.com/cert.pem SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem SSLCertificateChainFile /etc/letsencrypt/live/example.com/chain.pem Options FollowSymLinks AllowOverride All Require all granted ServerName example.com ServerAlias www.example.com Redirect permanent / https://example.com/ ServerName example.com ServerAlias www.example.com Protocols h2 http:/1.1 Redirect permanent / https://example.com/ DirectoryIndex index.html index.php DocumentRoot /var/www/example.com ErrorLog ${APACHE_LOG_DIR}/example.com-error.log CustomLog ${APACHE_LOG_DIR}/example.com-access.log combined SSLEngine On SSLCertificateFile /etc/letsencrypt/live/example.com/cert.pem SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem SSLCertificateChainFile /etc/letsencrypt/live/example.com/chain.pem Options FollowSymLinks AllowOverride All Require all granted ServerName example.com ServerAlias www.example.com Redirect permanent / https://example.com/ ServerName example.com ServerAlias www.example.com Protocols h2 http:/1.1 Redirect permanent / https://example.com/ DirectoryIndex index.html index.php DocumentRoot /var/www/example.com ErrorLog ${APACHE_LOG_DIR}/example.com-error.log CustomLog ${APACHE_LOG_DIR}/example.com-access.log combined SSLEngine On SSLCertificateFile /etc/letsencrypt/live/example.com/cert.pem SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem SSLCertificateChainFile /etc/letsencrypt/live/example.com/chain.pem Options FollowSymLinks AllowOverride All Require all granted ServerName example.com ServerAlias www.example.com Redirect permanent / https://example.com/ ServerName example.com ServerAlias www.example.com Protocols h2 http:/1.1 Redirect permanent / https://example.com/ DirectoryIndex index.html index.php DocumentRoot /var/www/example.com ErrorLog ${APACHE_LOG_DIR}/example.com-error.log CustomLog ${APACHE_LOG_DIR}/example.com-access.log combined SSLEngine On SSLCertificateFile /etc/letsencrypt/live/example.com/cert.pem SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem SSLCertificateChainFile /etc/letsencrypt/live/example.com/chain.pem Options FollowSymLinks AllowOverride All Require all granted

为域启用虚拟主机。 以下命令将创建从 sites-available sites-enabled 目录的符号链接:

sudo a2ensite example.com

为了使新配置生效,请输入以下命令重新启动Apache服务:

sudo systemctl restart apache2

完成WordPress安装

现在已经下载了Wordpress并完成了服务器配置,是时候通过Web界面完成WordPress安装了。

打开浏览器,输入您的域,然后会出现类似以下的屏幕:

在这里,您可以通过安装新主题和插件来自定义WordPress安装。

结论

恭喜,您已在Ubuntu 18.04服务器上成功将WordPress和Apache一起安装。 WordPress的第一步是一个很好的起点,可以学习更多有关如何开始使用WordPress的信息。

ubuntu wordpress mysql mariadb cms apache