Build WordPress on the server in 10 minutes

Build WordPress on the server

WordPress is the most popular open source blog system and CMS on the network. It is based on PHP and MySQL. And the function of WordPress is very powerful, which can be extended with various free plug-ins and themes.

This article will introduce how to build WordPress on the server, taking Ubuntu Server 20.04 LTS as an example. (skip the steps of purchasing server, domain name, filing, etc.)

Install PHP and Apache related packages

$ sudo apt update
$ sudo apt install apache2 \
                 ghostscript \
                 libapache2-mod-php \
                 mysql-server \
                 php \
                 php-bcmath \
                 php-curl \
                 php-imagick \
                 php-intl \
                 php-json \
                 php-mbstring \
                 php-mysql \
                 php-xml \
                 php-zip

Install wordpress

Create a folder / srv/www, / srv is generally used to store relevant website data provided by the system, such as network server data and scripts. Where - p means that if there is no / srv directory, create the \ srv directory first, and then create www.

$ sudo mkdir -p /srv/www

Change the file owner and group (chown - change owner). The general usage is chown [OPTION]... [OWNER][:[GROUP]] FILE.... if only one owner is given (user name or user ID can be used), the user is called the owner of the file, and the file group will not be changed. If the owner is followed by a colon and the group name is added, and note that there is no space in the middle, the group of the file will also change. If there is a colon but no group name, the group of the file is changed to the group when the user logs in.

$ sudo chown www-data: /srv/www

Download the installation package from the WordPress official website and unzip it.

$ curl https://wordpress.org/latest.tar.gz | sudo -u www-data tar zx -C /srv/www

Configuring Apache

Open the / etc / apache2 / sites available / wordpress.conf configuration file and paste the following code into the configuration file.

#Open profile
$ sudo vim /etc/apache2/sites-available/wordpress.conf
<VirtualHost *:80>
    DocumentRoot /srv/www/wordpress
    <Directory /srv/www/wordpress>
        Options FollowSymLinks
        AllowOverride Limit Options FileInfo
        DirectoryIndex index.php
        Require all granted
    </Directory>
    <Directory /srv/www/wordpress/wp-content>
        Options FollowSymLinks
        Require all granted
    </Directory>
</VirtualHost>

Make the web page work properly.

$ sudo a2ensite wordpress

Rewrite the URL.

$ sudo a2enmod rewrite

Cancel the "It Works" page pop-up.

$ sudo a2dissite 000-default

Finally, reload Apache 2 to make the above changes work properly.

$ sudo service apache2 reload

Configuration database

First, create a MySQL database.

$ sudo mysql -u root
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.7.20-0ubuntu0.16.04.1 (Ubuntu)

Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> CREATE DATABASE wordpress;
Query OK, 1 row affected (0,00 sec)

mysql> CREATE USER wordpress@localhost IDENTIFIED BY '<your-password>';
Query OK, 1 row affected (0,00 sec)

mysql> GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP,ALTER
    -> ON wordpress.*
    -> TO wordpress@localhost;
Query OK, 1 row affected (0,00 sec)

mysql> FLUSH PRIVILEGES;
Query OK, 1 row affected (0,00 sec)

mysql> quit
Bye

Start MySQL to make it work normally.

$ sudo service mysql start

Note: < your password > remember to add single quotation marks' 'when using your password, and remember to add' 'for each command; end. Except for the password part, it is not recommended to change other parts.

$ CREATE USER wordpress@localhost IDENTIFIED BY '<your-password>';

Connect wordpress to the server

Copy the configuration template provided by WordPress to the wp-config.php file

$ sudo -u www-data cp /srv/www/wordpress/wp-config-sample.php /srv/www/wordpress/wp-config.php

Then, add the database qualification in the configuration file.

$ sudo -u www-data sed -i 's/database_name_here/wordpress/' /srv/www/wordpress/wp-config.php
$ sudo -u www-data sed -i 's/username_here/wordpress/' /srv/www/wordpress/wp-config.php
$ sudo -u www-data sed -i 's/password_here/<your-password>/' /srv/www/wordpress/wp-config.php

**Note: * * do not replace the database_name_here and username_here section. However, you need to replace < your password > with the password set by yourself above. Note that single quotation marks' 'are not required here.

Open the configuration file with nano and make changes.

$ sudo -u www-data nano /srv/www/wordpress/wp-config.php
  • Find the location of the following code
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' );
  • Delete these lines. ctrl+k can delete a line, and then replace it with the following code. ctrl + u can paste.
define('AUTH_KEY',         '5=2SboNBpg!B pou6_t;Jb5i8#Eeg3+g-i2s}#]QvhB2qjHF;~N7!Y<_:tV+!dbo');
define('SECURE_AUTH_KEY',  '_O6G{,|sG_)Gm2R]K]y7P~{_>.(B%J;KePQ|0: QQ2mTLSieaBJ qQ]N^s1uH$VE');
define('LOGGED_IN_KEY',    'K5.apRH=o!/xDP+&7x_->KL/C|+G_8i~:/)}gold>4Uyl</nUXBA^b:uJ5v9`C%_');
define('NONCE_KEY',        'IXqE/F.8@XWzF6MN^@0W+;k5bo5k_]jciEEU__N:xn-+r;Qp_6,s5ga+d#)R$u~#');
define('AUTH_SALT',        'Bg-1QPsU+F>ZQ|O+r_3@h$*P-hhu%YimL{=5 ^8 @x>|`rN)>$gce{]flZ7XMm|K');
define('SECURE_AUTH_SALT', '<M(]Ibs3[ *bJq)CPW-zlcU`,DK<]+)/T)!wx]j>)q66#JdQ;8J,;Qmsn~c!+]3w');
define('LOGGED_IN_SALT',   'kp8M0 AJY6Ym3L{-.A#E%>G{o*H2W-xm*Wf|]Nv-9%^{BkG[AA;jxYYPN=%g[}To');
define('NONCE_SALT',       'DH5X`Ix2a SX&:GC(&2-/Y&V:QdnN-n QXIzCG*hg).m]b tktT{d701hrX7cPZU');
  • Save and close ctrl+ b, then press y and finally enter.

Open your web page

Now that all your configuration on the server has been completed, you can log in to the WordPress page deployed on your server through your browser.

Open the browser and enter the address of your server. If you have added domain name resolution and pointed the domain name to the IP address of the server, you can also enter your domain name directly.

First, you will see the language interface of WordPress. Select the language. Take English as an example. You can change it later.

Next, you need to make some settings for your website, including the theme of the website and manager related settings. The most important thing is the manager's name and password. Don't forget it, otherwise you won't be able to log in to your website console and modify the website.

After entering the relevant setting information, click Install WordPress. After the system installation is completed, you will jump to a login page again. This login screen is a login interface for the website manager. You can modify the website only after logging in.

After entering the correct user name and password, you will enter the console of your website. You can set the theme for your home page and add home page and application plug-ins here. Just now, WordPress supports Chinese. You can change the language to simplified Chinese in the Site language column of settings.

Click the small house in the upper left corner, and the name next to it is the theme of your website you set before. Next, you will enter the theme page set for you by default in WordPress. At this point, WordPress is officially deployed on your server. Next, you can make your website look more beautiful and richer by setting themes, installing plug-ins and publishing content.

If you want to modify your website anywhere, you can. As mentioned earlier, once you deploy WordPress on the server, you can enter your website through the IP address or domain name of the server, and then you can enter the administrator login panel by adding / WP admin after the URL of the website, Then you can modify your website anywhere and at any time.

Tags: PHP Database MySQL wordpress

Posted on Mon, 27 Sep 2021 23:59:44 -0400 by Gasolene