Setting Up a WordPress Website (Linux)
Application Scenarios
The best practices for ECS guide you through the setup of LNMP on a Linux ECS and deploy WordPress on the website. WordPress (WP for short) is initially a blog system and gradually evolved to a free CMS or website setup system. The CentOS 7.2 64bit OS is used as an example in this section.
Architecture
Advantages
- A website with a simple networking architecture can be quickly set up.
- The website is secure and easy to use.
Resource and Cost Planning
Resource |
Description |
Cost |
---|---|---|
VPC |
VPC CIDR block: 192.168.0.0/16 |
Free |
Subnet |
|
Free |
Security group |
Inbound rule:
|
Free |
ECS |
|
The following resources generate costs:
For billing details, see Billing Modes. |
Nginx |
A high-performance HTTP and reverse proxy server. You can download it from: http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm |
Free |
MySQL |
An open-source relational database software. You can download it from: http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm |
Free |
PHP |
An open-source software used for web development. You can download it from: |
Free |
WordPress |
An open-source blogging software. You can download it from: |
Free |
Domain name |
Used to access the created website. |
The price of a domain name is subject to that provided by the domain name registrar. For details, see the help document of the domain name registrar. |
Process
Procedure
Preparations
- A VPC and an EIP are available.
- A domain name is available if you plan to configure a domain name for the website.
- The rule listed in Table 2 has been added to the security group which the target ECS belongs to. For details, see Configuring Security Group Rules.
- The image source has been updated to a Huawei Cloud image source. For details, see How Can I Use an Automated Tool to Configure a Huawei Cloud Image Source (x86_64 and Arm)? This facilitates obtaining and updating the system and software.
Procedure
- Install Nginx.
- Log in to the target ECS.
- Run the following command to download the Nginx package:
wget http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
- Run the following command to create the Nginx yum repository:
- Run the following command to install Nginx:
- Run the following commands to start Nginx and enable it to start automatically upon ECS startup:
systemctl enable nginx
- Check the startup status.
- Enter http://Public IP address of the Nginx server in the address bar of the browser to access Nginx. If the following page is displayed, Nginx has been installed.
Figure 2 Accessing Nginx
- Install MySQL.
- Run the following commands in sequence to install MySQL:
wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
yum -y install mysql57-community-release-el7-10.noarch.rpm
yum -y install mysql-community-server --nogpgcheck
- Run the following commands in sequence to start MySQL and enable it to start automatically upon ECS startup:
systemctl enable mysqld
- Check the MySQL status.
systemctl status mysqld.service
[root@ecs-adc3 ~]# systemctl status mysqld.service ● mysqld.service - MySQL Server Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled) Active: active (running) since Mon 2021-08-16 19:33:40 CST; 36s ago Docs: man:mysqld(8) http://dev.mysql.com/doc/refman/en/using-systemd.html Main PID: 7916 (mysqld) CGroup: /system.slice/mysqld.service └─7916 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid Aug 16 19:33:35 ecs-adc3 systemd[1]: Starting MySQL Server... Aug 16 19:33:40 ecs-adc3 systemd[1]: Started MySQL Server.
- Run the following commands to obtain the root user's password that is automatically set during MySQL installation:
grep 'temporary password' /var/log/mysqld.log
Information similar to the following is displayed:2021-08-16T11:33:37.790533Z 1 [Note] A temporary password is generated for root@localhost: ;8nPd29lhs,k
- Run the following command and follow the prompts to harden MySQL:
Securing the MySQL server deployment. Enter password for user root: #Enter the obtained password of user root. The existing password for the user account root has expired. Please set a new password. New password: #Enter a new password of user root. Re-enter new password: #Enter the new password again. The 'validate_password' plugin is installed on the server. The subsequent steps will run with the existing configuration of the plugin. Using existing password for root. Estimated strength of the password: 100 Change the password for root ? ((Press y|Y for Yes, any other key for No) : N #Press N. ... skipping. By default, a MySQL installation has an anonymous user, allowing anyone to log into MySQL without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y #Press Y to remove anonymous users. Success. Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? (Press y|Y for Yes, any other key for No) : Y #Press Y to disallow remote logins of user root. Success. By default, MySQL comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. Remove test database and access to it? (Press y|Y for Yes, any other key for No) : Y #Press Y to delete the test database and remove access to it. - Dropping test database... Success. - Removing privileges on test database... Success. Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y #Press Y to reload privilege tables. Success. All done!
- Run the following commands in sequence to install MySQL:
- Install PHP.
- Run the following command to install the EPEL repository:
- Run the following command to install the REMI repository:
yum -y install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
- Run the following command to install the yum repository management tool:
- Run the following command to install PHP 7.4:
yum -y install php74-php-gd php74-php-pdo php74-php-mbstring php74-php-cli php74-php-fpm php74-php-mysqlnd
- Run the following command to check the version of the installed PHP:
If information similar to the following is displayed, PHP has been installed:
PHP 7.4.33 (cli) (built: Jun 6 2023 15:55:08) ( NTS ) Copyright (c) The PHP Group Zend Engine v3.4.0, Copyright (c) Zend Technologies
- Run the following commands to start PHP and enable it to start automatically upon ECS startup:
systemctl enable php74-php-fpm
- Modify the Nginx configuration file to support PHP.
- Run the following command to open the /etc/nginx/nginx.conf file:
vim /etc/nginx/nginx.confFigure 3 nginx.conf
According to the nginx.conf, the configuration file is directed to /etc/nginx/conf.d/*.conf.
- Enter :quit to exit nginx.conf.
- Run the following command to open the /etc/nginx/conf.d/default.conf file:
vim /etc/nginx/conf.d/default.conf
- Press i to enter insert mode.
- Modify the default.conf file.
Find the server paragraph and configure it as follows:
server { listen 80; server_name localhost; #access_log /var/log/nginx/host.access.log main; location / { root /usr/share/nginx/html; index index.php index.html index.htm; } location ~ \.php$ { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name; include fastcgi_params; }
Figure 4 shows the configuration after modification.
- Press Esc to exit insert mode. Then, enter :wq to save the settings and exit.
- Run the following command to open the /etc/nginx/nginx.conf file:
- Run the following command to reload the Nginx configuration file:
- Test the LNMP deployment.
- Create the info.php test file in /usr/share/nginx/html.
- Run the following command to create and open the info.php test file:
vim /usr/share/nginx/html/info.php
- Press i to enter insert mode.
- Modify the info.php file and add the following to the file:
<?php phpinfo(); ?>
- Press Esc to exit insert mode. Then, enter :wq to save the settings and exit.
- Run the following command to create and open the info.php test file:
- Enter http://Server IP address/info.php in the address bar. If the following page is displayed, the website has been set up.
- Create the info.php test file in /usr/share/nginx/html.
- Create a database.
- Run the following command and enter the user root password of MySQL as prompted to log in to the MySQL CLI:
mysql -u root -p
- Run the following command to create a database:
In the preceding command, wordpress is the database name, which can be customized.
- Run the following command to create a user for the database and assign full permissions to the user:
GRANT ALL ON wordpress.* TO wordpressuser@localhost IDENTIFIED BY 'xxxxx';
In the preceding command, wordpressuser is the name of the database user, and xxxxx is the configurable user password.
- Run the following command to exit the MySQL CLI:
- (Optional) Run the following commands to verify the creation of the database and user and then exit the MySQL CLI:
SHOW DATABASES;
exit
In the preceding command, wordpressuser is the created username for logging in to the database.
- Run the following command and enter the user root password of MySQL as prompted to log in to the MySQL CLI:
- Install WordPress.
- Obtain the WordPress software package and upload it to the /usr/share/nginx/html directory. For details, see How Can I Use WinSCP to Transfer Files from a Local Windows Computer to a Linux ECS?
The WordPress software package wordpress-6.4.2.tar.gz is used as an example.
- Run the following commands to go to the /usr/share/nginx/html/ directory and decompress the software package:
cd /usr/share/nginx/html
tar zxvf wordpress-6.4.2.tar.gz
After the decompression, the folder wordpress is obtained.
- Run the following commands to go to the WordPress installation directory, copy the wp-config-sample.php file to the wp-config.php file, and retain the original sample configuration file as a backup:
cd /usr/share/nginx/html/wordpress
cp wp-config-sample.php wp-config.php
- Run the following command to open and edit the created configuration file:
- Press i to enter insert mode. Find MySQL configurations in the file and modify them to those in step 5.
Figure 5 Modifying MySQL configurations
- Press Esc to exit insert mode. Then, enter :wq to save the settings and exit.
- Enter http://Server IP address/wordpress in the address bar of the browser to access the installation wizard.
- Set the site title, administrator username, password, and email address. Then, click Install WordPress.
Table 3 Configuration parameters Parameter
Description
Site title
Name of the WordPress website.
Username
Name of the WordPress administrator.
Password
Default or user-defined password.
Do not reuse an existing password and keep your password secure.
Email address
Email address for receiving notifications.
- Check that the installation is successful.
- Click Log In. Alternatively, enter http://Server IP address/wordpress/wp-login.php in the address bar of the browser, enter the username or email address and password, and click Log In.
- Obtain the WordPress software package and upload it to the /usr/share/nginx/html directory. For details, see How Can I Use WinSCP to Transfer Files from a Local Windows Computer to a Linux ECS?
- Purchase a domain name.
Configure a unique domain name for website access. You need to obtain an authorized domain name from the domain name registrar first.
- Configure DNS records.
Your website can be visited using the registered domain name only after DNS records are configured. For details, see Routing Internet Traffic to a Website.
For example, if the domain name is www.example.com, enter http://www.example.com in the address bar of the browser to access the website.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot