Build a personal website based DigitalOcean + LAMP + WordPress

1. Register DigitalOcean and New Host

To set up a personal website first need to be in the range of host public network access, you can use the country as Ali cloud, cloud hosting providers such as various foreign DigitalOcean, where the choice of DigitalOcean, first in DigitalOcean registered account on here need to bind a credit cards or use PayPal filled with at least 5 \ (initial registration fee, but registration is successful will receive 50 \) or more new user bonus, very cost-effective, Also, if a student, you can use GitHub educational concessions obtained containing 50 $ DigitalOcean credit, including a large number of benefits.

After successful registration, a new Droplets, select familiar with Linux system release, where the choice of Ubuntu 18.04, select the host size 1G / 25G / 1000G requires a monthly cost $ 5, but the actual billing by the hour, then select the datacenter region, domestic users recommend choosing San Francisco node, and finally type the host name and then create.

After successfully create can see ip address of the host (ip_addr), and received a user name (user_name) and initial password (init_pass) in the registration email, use ssh to connect to the host:

ssh user_name@ip_addr

Then type init_pass, this time will remind password, set up after the success by ssh normal use.

2. Configure LAMP environment

LAMP, namely Linux + Apache + MySQL + PHP, WordPress is using a basic environment.

Linux

Linux installation has been completed at the first step in creating a host.
Subsequent installation and final daily operations may require a non-root account, so first create a new user, follow-up operations are completed using this new user account, create a new user should be completed at the root account.

# 新建用户
adduser username
# 然后根据提示键入密码,之后的选项可以全选默认项

# 将新建的用户加入sudo组
adduser username sudo

Then quit ssh, log in with the new password.

Apache

# 更新apt源
sudo apt update

# 安装Apache
sudo apt install apache2

# 检查UFW是否具有Apache的应用程序配置文件
sudo ufw app list

# 查看Apache Full的配置文件,它应该显示它启用了端口80和443
sudo ufw app info "Apache Full"

# 允许此配置文件的传入HTTP和HTTPS流量
sudo ufw allow in "Apache Full"

# 打开Apache
sudo systemctl start Apache2

# 设置开机启动
update-rc.d apache2 defaults

Opens a browser to access http: // ip_addr, you can see the default Apache test page.
Apache test page

The test page is / var / index.html www / http / under, you can modify this file and refresh your browser, you can see the test page is updated.

MySQL

MySQL installation can follow DigitalOcean the official tutorial to configure, very detailed.

Finally, open the MySQL and set the boot

# 打开MySQL
sudo systemctl start mysql

# 设置开机启动
update-rc.d mysql defaults

PHP

# 安装相关版本的PHP
sudo apt install php libapache2-mod-php php-mysql

# 为了测试,在以下目录创建一个PHP的测试页
sudo vim /var/www/html/info.php

# 使用vim键入如下文本并保存退出
<?php
phpinfo();
?>

At this point the browser to http: //ip_addr/info.php can see the following page shows PHP installation is successful
PHP test page

3. Configure WordPress

# 进入下载目录
cd ~/Download

# 下载最新版本的WordPress
wget https://wordpress.org/latest.tar.gz

# 解压
tar -xzvf latest.tar.gz

# 将解压出的文件夹移入/var/www/html/
mv wordpress /var/www/html/

# 修改权限以便后续的设置
chown -hR www-data /var/www/html/wordpress

Use a browser to access http: // ip_addr / wordpress, follow the prompts to complete the installation of five minutes.

The basic configuration of WordPress to this end.

4. Link to your domain

Choose a domain name provider domain name registration and purchase, and herein million net registered to buy www.zillyrex.com as my personal domain name, follow the prompts and wait for payment approved.

After successfully added two Class A resolution, respectively, fill in the host name for the domain name of your host ip address is www and @, recorded values, the other to keep the default.

It can wait a few minutes at http: // your domain / wordpress to visit your site.

5. Recommended additional configuration

At this point, if you visit the website to enter wordpress After your domain name (such as www.zillyrex.com/wordpress), slight modifications can be directly accessed through the domain name (such as www.zillyrex.com).

# 修改/etc/apache2/apache2.conf
sudo vim /etc/apache2/apache2.conf

# 添加如下内容保存并退出
<Directory /var/www/html/wordpress/>
            Options Indexes FollowSymLinks
            AllowOverride All
            Require all 
</Directory>

# 修改/etc/apache2/sites-available/000-default.conf
sudo vim /etc/apache2/sites-available/000-default.conf

# 将DocumentRoot改为如下内容保存并退出
DocumentRoot /var/www/html/wordpress/

# 进入MySQL
mysql -uroot -p
# 键入MySQL密码

# 在MySQL shell中选择wordpress数据库
>use wordpress;

# 修改表单数据
update wp_options set option_value='http://www.domain.com' where option_name="home";
update wp_options set option_value='http://www.domain.com' where option_name="siteurl";

# 重启Apache和MySQL
sudo systemctl restart apache2
sudo systemctl restart mysql

You can now access your personal website directly through your domain name.


If you need to modify the icon site, can console -> Appearance -> Custom -> Site identity upload error as it appears in the picture clipping process, install php-gd in the host:

# 安装php-gd
sudo apt install php-gd

# 重启Apache
systemctl restart apache2

https instead of http gradually become the mainstream of the current agreement, it is recommended to turn http https

First, apply for SSL certificates, one-year free SSL certificate here for the million to provide network, but also can choose other certificate issuing authority.

The package contains the certificate obtained

  • xxx_public.crt, the certificate file
  • xxx_chain.crt, certificate chain
  • xxx.key, the private key file

New in / etc / apache2 / ssl directory and directory more than three files uploaded to it

Enable SSL module

sudo a2enmod ssl
sudo a2ensite default-ssl

Use vim editor /etc/apache2/sites-enabled/000-default.conf, add the following to the end of the file

<VirtualHost 0.0.0.0:443>

DocumentRoot "/var/www/html/wordpress"

ServerName zillyrex.com # 键入你自己的域名

SSLEngine on

SSLCertificateFile /etc/apache2/ssl/xxx_public.crt

SSLCertificateKeyFile /etc/apache2/ssl/xxx.key

SSLCertificateChainFile /etc/apache2/ssl/xxx_chain.crt

</VirtualHost>

Continue in the front of the file Tags:

<VirtualHost *:80>
...
</VirtualHost> 

Add the following to save and exit

RewriteEngine on
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*) https://%{SERVER_NAME}$1 [L,R]

Restart Apache

sudo a2enmod rewrite
sudo systemctl restart apache2

At this point you can use https the entire station.

Guess you like

Origin www.cnblogs.com/zillyrex/p/11802837.html
Recommended