{"id":86,"date":"2022-07-19T13:40:43","date_gmt":"2022-07-19T13:40:43","guid":{"rendered":"https:\/\/www.ddzheng.cc\/?p=86"},"modified":"2022-07-19T16:45:29","modified_gmt":"2022-07-19T16:45:29","slug":"how-to-start-a-wordpress-site-%e5%a6%82%e4%bd%95%e5%bb%ba%e7%ab%8b%e4%b8%80%e4%b8%aawordpress%e7%ab%99%e7%82%b9","status":"publish","type":"post","link":"https:\/\/www.ddzheng.cc\/?p=86","title":{"rendered":"How to Start a WordPress Site \u5982\u4f55\u5efa\u7acb\u4e00\u4e2aWordPress\u7ad9\u70b9"},"content":{"rendered":"\n<p>This post shows how to start a new WordPress site with Ubuntu, Nginx, PHP, MariaDB\/MySQL which is the LNMP stack. It assumes you have basic knowledge of how to use command line Linux.<\/p>\n\n\n<h1 class=\"wp-block-heading\" id=\"register-a-domain\">Register a Domain<\/h1>\n\n\n<p>There are free domain registers like freenom. I used NameSilo for this domain. Choose a domain you like, with acceptable price and renewal price. Don&#8217;t forget to add WHOIS privacy.<\/p>\n\n\n<h1 class=\"wp-block-heading\" id=\"buy-a-server\">Buy a Server<\/h1>\n\n\n<p>If you use local server, you can skip this step. Just make sure your server has a public IP address. If it&#8217;s behind a firewall, make a proper port forwarding rule.<\/p>\n\n\n\n<p>I used Racknerd&#8217;s VPS. After purchasing you can choose what OS to use. Then you will be given server credentials. You will use username root and the password given to login to your server with SSH. Password can be changed, new users can be created, and you can also use certs to login and disable password login completely.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"527\" height=\"376\" src=\"https:\/\/www.ddzheng.cc\/wp-content\/uploads\/2022\/07\/image.png\" alt=\"\" class=\"wp-image-87\"\/><\/figure>\n\n\n<h1 class=\"wp-block-heading\" id=\"point-domain-name-to-server\">Point Domain Name to Server<\/h1>\n\n\n<p>In your domain register&#8217;s settings, find DNS settings, add a new A record of @ as well as www, set the record content to the IP address of your server. Now you can access your server with domain name.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1075\" height=\"179\" src=\"https:\/\/www.ddzheng.cc\/wp-content\/uploads\/2022\/07\/image-1.png\" alt=\"\" class=\"wp-image-88\" srcset=\"https:\/\/www.ddzheng.cc\/wp-content\/uploads\/2022\/07\/image-1.png 1075w, https:\/\/www.ddzheng.cc\/wp-content\/uploads\/2022\/07\/image-1-720x120.png 720w, https:\/\/www.ddzheng.cc\/wp-content\/uploads\/2022\/07\/image-1-768x128.png 768w\" sizes=\"auto, (max-width: 1075px) 100vw, 1075px\" \/><\/figure>\n\n\n<h1 class=\"wp-block-heading\" id=\"install-server-software\">Install Server Software<\/h1>\n\n\n<p>I used Ubuntu Server 20.04. If you are using a different OS, consult related documentations and change software packages accordingly. <\/p>\n\n\n\n<p>Following steps are fine to be executed under <code>root<\/code>. If not using <code>root<\/code>, use <code>sudo<\/code>. Update and upgrade software packages:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>apt-get update\napt-get upgrade<\/code><\/pre>\n\n\n\n<p>Install packages:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>apt-get install unzip nginx mariadb-server mariadb-client php7.4 php7.4-fpm php7.4-mysql php-common php7.4-cli php7.4-common php7.4-json php7.4-opcache php7.4-readline php7.4-mbstring php7.4-xml php7.4-gd php7.4-curl<\/code><\/pre>\n\n\n\n<p>make mysql installation secure:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mysql_secure_installation<\/code><\/pre>\n\n\n\n<p>Create database and database user, using password set in previous step:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mysql -u root<\/code><\/pre>\n\n\n\n<p>SQL queries to be executed in MySQL, replace <code>your-password<\/code> with your database password:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE DATABASE wordpress;\nGRANT ALL privileges ON wordpress.* to wpuser@localhost IDENTIFIED BY 'your-password';\nEXIT;<\/code><\/pre>\n\n\n\n<p>Next steps are better executed with non-root user. To create and switch to new user:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>adduser <em>username<\/em>\nusermod -aG sudo <em>username<\/em>\nsu -<em> username<\/em><\/code><\/pre>\n\n\n\n<p>Create website root directory:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo mkdir -p \/var\/www\/your.domain<\/code><\/pre>\n\n\n\n<p>Download latest wordpress and extract to web root:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>wget https:\/\/wordpress.org\/latest.zip\nsudo unzip latest.zip -d \/var\/www\/your.domain<\/code><\/pre>\n\n\n\n<p>Set owner of web root directory:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo chown -R www-data:www-data \/var\/www\/your.domain<\/code><\/pre>\n\n\n\n<p>Create new nginx config:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo nano \/etc\/nginx\/sites-available\/your.domain<\/code><\/pre>\n\n\n\n<p>Example config:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>server {\n\n        listen 80;\n        listen &#91;::]:80;\n\n        root \/var\/www\/your.domain;\n\n        server_name your.domain;\n\n        # Add index.php to the list if you are using PHP\n        index index.html index.htm index.php index.nginx-debian.html;\n\n        location ~ \\.php$ {\n                include snippets\/fastcgi-php.conf;\n\n                # With php-fpm (or other unix sockets):\n                fastcgi_pass unix:\/var\/run\/php\/php7.4-fpm.sock;\n                # With php-cgi (or other tcp sockets):\n                #fastcgi_pass 127.0.0.1:9000;\n        }\n\n        # deny access to .htaccess files, if Apache's document root\n        # concurs with nginx's one\n        #\n        location ~ \/\\.ht {\n                deny all;\n        }\n\n}<\/code><\/pre>\n\n\n\n<p>Put above content into nano and hit Ctrl-O then Y to save and exit. Then create symlink to enable config:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ln -s \/etc\/nginx\/sites-available\/your.domain \/etc\/nginx\/sites-enabled\/your.domain<\/code><\/pre>\n\n\n\n<p>Test nginx config:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo nginx -t<\/code><\/pre>\n\n\n\n<p>If test is successful, reload nginx<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo systemctl restart nginx<\/code><\/pre>\n\n\n\n<p>Create new wordpress config by copying sample config then edit it:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cd \/var\/www\/your.domain\nsudo cp wp-config-sample.php wp-config.php\nsudo nano wp-config.php<\/code><\/pre>\n\n\n\n<p>Find the following lines and replace the texts with the database name, username and password you created in the previous step.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/** The name of the database for WordPress *\/\ndefine('DB_NAME', 'database_name_here');\n\n\/** MySQL database username *\/\ndefine('DB_USER', 'username_here');\n\n\/** MySQL database password *\/\ndefine('DB_PASSWORD', 'password_here');<\/code><\/pre>\n\n\n\n<p>Now you should be able to start wordpress installation by going to your domain in a browser:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>your.domain<\/code><\/pre>\n\n\n\n<p>Enable SSL for server using certbot:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt-get install certbot python3-certbot-nginx\nsudo certbot --nginx --agree-tos --redirect --hsts --staple-ocsp --email your.email@example.com -d your.domain<\/code><\/pre>\n\n\n\n<p>Add certbot renewal to crontab:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo nano \/etc\/crontab<\/code><\/pre>\n\n\n\n<p>put in a new line:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>00 3    1 * *   root    certbot renew\n<\/code><\/pre>\n\n\n\n<p>This means to execute <code>certbot renew<\/code> as root on 1st of every month at 3:00 in the morning.<\/p>\n\n\n<h1 class=\"wp-block-heading\" id=\"use-cloudflare-cdn\">Use CloudFlare CDN<\/h1>","protected":false},"excerpt":{"rendered":"<p>This post shows how to start a new Wordpress site with Ubuntu, Nginx, PHP, MariaDB\/MySQL which is the LNMP stack. It assumes you have basic knowledge of how to use command line Linux.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[22,14,15,10],"class_list":["post-86","post","type-post","status-publish","format-standard","hentry","category-tech","tag-server","tag-software","tag-web","tag-writeup"],"_links":{"self":[{"href":"https:\/\/www.ddzheng.cc\/index.php?rest_route=\/wp\/v2\/posts\/86","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ddzheng.cc\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ddzheng.cc\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ddzheng.cc\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ddzheng.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=86"}],"version-history":[{"count":5,"href":"https:\/\/www.ddzheng.cc\/index.php?rest_route=\/wp\/v2\/posts\/86\/revisions"}],"predecessor-version":[{"id":102,"href":"https:\/\/www.ddzheng.cc\/index.php?rest_route=\/wp\/v2\/posts\/86\/revisions\/102"}],"wp:attachment":[{"href":"https:\/\/www.ddzheng.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=86"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ddzheng.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=86"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ddzheng.cc\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=86"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}