欢迎来到教程的第 2 部分,如何在 Microsoft Azure 上运行超快的 WordPress(How to run blazingly fast WordPress on Microsoft Azure)(How to run blazingly fast WordPress on Microsoft Azure)。在第一部分中,我们讨论了在您的Azure帐户上设置虚拟机。(Virtual Machine)在这篇文章中,我们将了解如何连接到您的服务器并开始在其上下载和安装WordPress。
(Install)在Microsoft Azure上(Microsoft Azure)安装和设置WordPress
这篇文章会包含很多终端命令,所以请尽量按照教程一步一步来,尽量不要跳过任何步骤。
设置你的服务器
第 1 步(Step 1):要与您的虚拟机通信,您需要建立SSH连接并使用SSH客户端。
什么是 SSH?
According to Wikipedia, Secure Shell (SSH) is a cryptographic network protocol for operating network services securely over an unsecured network. The best known example application is for remote login to computer systems by users.
我们在本教程中使用PuTTY,一个免费的SSH和 telnet 客户端。因此,对于这一步,您需要从此处下载并安装(here)PuTTY。
第 2 步(Step 2):登录到您的Azure面板,打开我们在第一部分创建的虚拟机,然后点击“开始”。然后单击“连接”以开始连接。现在弹出窗口将显示您的用户名和您机器的公共 IP 地址。复制整个SSH主机名(例如[email protected])。您可以点击图片查看大图。
现在打开PuTTY并将此主机名粘贴到主机名字(Host Name)段中,然后选择连接类型为SSH并点击打开,所有其他设置为默认设置。将打开一个新的终端窗口,并提示您输入密码。输入在创建虚拟机时在第 1 部分(part 1)中选择的密码。现在您终于通过 SSH 连接连接到您的虚拟服务器。您现在需要做的就是在此终端窗口中输入一些命令来安装正确的软件和WordPress。
安装 Apache
第 3 步(Step 3):首先(First),您需要确保您安装的Ubuntu上的所有软件包都是最新的。运行以下命令来更新它们:
sudo apt-get update
现在我们将安装Apache,一个免费的HTTP服务器软件。基本上(Basically),Apache会听取某人的请求以显示您的网站内容。在此处(here)阅读有关Apache 的更多信息。运行以下命令来安装Apache:
sudo apt-get install apache2
现在导航到保存 Apache 配置文件的目录并使用文本编辑器打开它。
sudo nano /etc/apache2/apache2.conf
在此文件的末尾添加以下行:
“ServerName 127.0.0.1”.
重启 Apache 服务:
sudo service apache2 reload
并通过执行以下命令授予Apache权限:(Apache)
sudo ufw allow in “Apache Full”
安装 MySQL 和 PHP
第 4 步:(Step 4:)执行以下命令以在Ubuntu上安装(Ubuntu)MySQL和PHP:
sudo apt-get install mysql-server
选择(Choose)适当的MySQL root 密码并点击“Enter”。
sudo apt-get install php5 libapache2-mod-php5 php5-mcrypt php5-mysql
sudo apt-get install php5-cli
sudo apt-get install php5-gd libssh2-php
PHP文件的优先级要高于HTML文件,因此我们需要更改另一个配置文件:
sudo nano /etc/apache2/mods-enabled/dir.conf
现在在这个文件中,移动“index.php”,使其位于“index.html”之前。重新启动Apache服务器。
sudo service apache2 reload
创建 MySQL 数据库
第 5 步:按照以下命令进行操作:
mysql -u root -p
CREATE DATABASE test DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
GRANT ALL ON test.* TO ‘tester’@’localhost’ IDENTIFIED BY ‘testpwd';
FLUSH PRIVILEGES;
Exit;
安装 WordPress
第 6 步:(Step 6: )这实际上是下载WordPress的步骤。导航(Navigate)到根目录,然后下载并解压WordPress。
wget http://wordpress.org/latest.tar.gz
tar xzvf latest.tar.gz
导航到存储所有网站文件的WWW目录,然后将(WWW)WordPress的全部内容复制到您选择的新文件夹中。
cd /var/www
sudo mkdir twcwp
现在通过创建示例配置文件的副本来创建 wp-config.php 文件,然后将下载文件夹的全部内容复制到 www 目录中的“wordpress”文件夹中。
cp ~/wordpress/wp-config-sample.php ~/wordpress/wp-config.php
sudo rsync -avP ~/wordpress/ /var/www/twcwp/
cd /var/www/twcwp/
sudo nano wp-config.php
输入(Enter)我们在前面步骤中创建的数据库详细信息并保存文件。(请参阅下面的屏幕截图以供参考)
配置 Apache
第 7 步(Step 7):现在对于最后一步,我们需要配置 apache,以便它知道在我们的“twcwp”文件夹下运行一个网站。我们需要导航到可用的站点文件夹并创建一个名为“twcwp.conf”的新文件,该文件类似于默认配置文件。
sudo chown www-data:www-data * -R
cd /etc/apache2/sites-available
sudo cp 000-default.conf twcwp.conf
sudo nano twcwp.conf
在此文件中更改以下行
- ServerAdmin your_email_adress
- 服务器名称 twcwp.com
- 服务器别名 twcwp.com
- DocumentRoot /var/www/twcwp
ServerAlias应该是您注册的域名(在我们的例子中,我们没有注册域名,但我们只是将其用作参考)。
执行(Execute)最后一组命令:
sudo chown -R twctestingadmin:www-data *
sudo mkdir /var/www/twcwp/wp-content/uploads
sudo a2ensite twcwp.conf
sudo service apache2 reload
这里“twctestingadmin”是我们虚拟机上管理员帐户的用户名,“twcwp”是包含WordPress文件的目录。您可以用您的详细信息替换这些字符串。
就是这样,现在您拥有一个运行在Microsoft Azure上的功能齐全的虚拟机,它托管您的WordPress网站。您现在需要做的就是配置您的 DNS 记录,以便网站指向虚拟机的公共 IP 地址。
如果您想临时运行您的网站,您可以编辑Windows主机文件并添加一个条目,将公共 IP 地址临时映射到域名。(参考截图)
教程很长,涉及很多步骤。您可以随时在下面的评论部分提出任何问题,我们很乐意为您提供帮助。这篇文章中使用的一些术语对你来说可能是新的,你可以谷歌搜索它们或者只是在评论中留言。
此外,我想向您介绍在昌迪加尔地区为我们带来这个精彩研讨会的(Chandigarh)两位人物:(Workshop)
该研讨会由Microsoft 用户组 Chandigarh(Microsoft Users Group Chandigarh)和WordPress Chandigarh共同举办。您可以在Facebook 上(Facebook)与这两个小组取得联系,并在 meetup.com 上寻找即将在昌迪加尔地区举行的聚会。(Chandigarh)
相关阅读:(Related reads:)
- 如何在谷歌云平台上安装 WordPress(How to install WordPress on Google Cloud Platform)
- 如何使用 Microsoft IIS 托管 WordPress 博客
- 使用 Microsoft WebMatrix 创建 WordPress 网站
- 如何在 Windows PC 上安装 WordPress。
How to install & setup WordPress on Microsoft Azure
Welcome to the part 2 of the tutorial How to run blazingly fast WordPress on Microsoft Azure. In the first part, we discussed setting up a Virtual Machine on your Azure account. And in this post, we will see how to connect to your server and start downloading and installing WordPress on it.
Install & setup WordPress on Microsoft Azure
This post will include a lot of terminal commands, so please try to follow the tutorial step by step and try not to skip any step.
Setting up your server
Step 1: To communicate with your virtual machine, you need to establish an SSH connection and use an SSH client.
What is SSH?
According to Wikipedia, Secure Shell (SSH) is a cryptographic network protocol for operating network services securely over an unsecured network. The best known example application is for remote login to computer systems by users.
We are using PuTTY, a free SSH and telnet client in this tutorial. So for this step, you are required to download and install PuTTY from here.
Step 2: Login to your Azure panel, open the virtual machine, we created in the first part and hit ‘Start’. Then click on ‘Connect’ to start the connection. Now a pop-up will display your username and the public IP address of your machine. Copy the entire SSH hostname (e.g. [email protected]). You may click on the images to see the larger version.
Now open PuTTY and paste this hostname in the Host Name field and select connection type as SSH and hit open with all other settings as default. A new terminal window would open and will prompt you for the password. Enter the password that was chosen in part 1 while creating a virtual machine. Now you are finally connected to your virtual server over an SSH connection. All you need to do now is enter some commands in this terminal window to install proper software and WordPress.
Installing Apache
Step 3: First of all, you need to make sure that all the packages on your installation of Ubuntu are up to date. Run the following command to update them:
sudo apt-get update
Now we’ll install Apache, a free HTTP server software. Basically, Apache will be the one listening to someone’s request to display your website’s content. Read more about Apache here. Run the following command to install Apache:
sudo apt-get install apache2
Now navigate to the directory where Apache’s configuration file is saved and open it using the text editor.
sudo nano /etc/apache2/apache2.conf
At the end of this file add the following line:
“ServerName 127.0.0.1”.
Restart the Apache service:
sudo service apache2 reload
And grant permissions to Apache by executing the following command:
sudo ufw allow in “Apache Full”
Installing MySQL and PHP
Step 4: Execute the following commands in order to install MySQL and PHP on Ubuntu:
sudo apt-get install mysql-server
Choose an appropriate MySQL root password and hit ‘Enter’.
sudo apt-get install php5 libapache2-mod-php5 php5-mcrypt php5-mysql
sudo apt-get install php5-cli
sudo apt-get install php5-gd libssh2-php
PHP files are to be given more priority than the HTML files, so we need to alter another configuration file:
sudo nano /etc/apache2/mods-enabled/dir.conf
Now in this file, move “index.php” so that it comes before “index.html”. Restart the Apache server.
sudo service apache2 reload
Creating a MySQL database
Step 5: Follow the commands:
mysql -u root -p
CREATE DATABASE test DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
GRANT ALL ON test.* TO ‘tester’@’localhost’ IDENTIFIED BY ‘testpwd';
FLUSH PRIVILEGES;
Exit;
Installing WordPress
Step 6: This is actually the step that downloads WordPress. Navigate to the root directory and then download and extract WordPress.
wget http://wordpress.org/latest.tar.gz
tar xzvf latest.tar.gz
Navigate to the WWW directory where all the website files are stored and copy the entire contents of the WordPress here in a new folder of your choice.
cd /var/www
sudo mkdir twcwp
Now create the wp-config.php file by creating the copy of sample configuration file and then copy the entire contents of the downloaded folder into the ‘wordpress’ folder in the www directory.
cp ~/wordpress/wp-config-sample.php ~/wordpress/wp-config.php
sudo rsync -avP ~/wordpress/ /var/www/twcwp/
cd /var/www/twcwp/
sudo nano wp-config.php
Enter the database details we created in previous steps and save the file. (see screenshot below for reference)
Configuring Apache
Step 7: Now for the final step, we need to configure apache so that it knows there is a website running under our “twcwp” folder. We need to navigate to the available sites folder and create a new file called ‘twcwp.conf’ which is similar to the default configuration file.
sudo chown www-data:www-data * -R
cd /etc/apache2/sites-available
sudo cp 000-default.conf twcwp.conf
sudo nano twcwp.conf
In this file alter the following lines
- ServerAdmin your_email_adress
- ServerName twcwp.com
- ServerAlias twcwp.com
- DocumentRoot /var/www/twcwp
ServerAlias should be the domain name you’ve registered (in our case we’ve not registered the domain name but we are just using it for reference).
Execute these final set of commands:
sudo chown -R twctestingadmin:www-data *
sudo mkdir /var/www/twcwp/wp-content/uploads
sudo a2ensite twcwp.conf
sudo service apache2 reload
Here “twctestingadmin” is the username of admin account on our virtual machine and “twcwp” is the directory that contains WordPress files. You can replace these strings with your details.
And this is it, now you have a fully functional virtual machine running on Microsoft Azure that is hosting your WordPress website. All you need to do is now configure your DNS records so that the website points to the public IP address of the virtual machine.
If you want to temporarily run your website, you can edit the Windows hosts file and add an entry that will map the public IP address to the domain name temporarily. (see screenshot for reference)
The tutorial is pretty long and involves a lot of steps. You may feel free to ask any questions in the comments section below and we will be happy to help you out. Some terms used in this post may seem new to you, you can Google search them or just drop a message in comments.
Also, I would like to introduce you to the two personalities who brought us this wonderful Workshop in the Chandigarh area:
- Jasjit Chopra
- Divyadeep Sawhney
The workshop was collectively conducted by Microsoft Users Group Chandigarh and WordPress Chandigarh. You can get in touch with both the groups on Facebook and look for upcoming meetups in Chandigarh area on meetup.com.
Related reads: