代做INFO386 T1 2022 Workshop 4 Wordpress代做留学生SQL 程序
- 首页 >> Algorithm 算法INFO386 T1 2022
Workshop 4
Wordpress
For this workshop you will need to connect to your Virtual machine from labs.azure.com . The instructions to do this are in workshop Guide 1. As in Guide 1, you will have to start your Virtual machine and connect via RDP. If the IP has changed, you will need to download a new RDP file. Once you’re within your Virtual machine, turn on Apache. We will be installing WordPress today, which needs both PHP and a database
WordPress
WordPress is an open-sourced content management system largely used for blogs. It is written in PHP which should have been installed as part of guide 3. It also utilizes either MySQL or MariaDB. MySQL also should have been installed as part of guide 3.
For this workshop, we will besetting up a database for WordPress. This requires a few more stepson top of setting up PHP and MySQL in the last guide. These steps include creation of a database specifically for WordPress in MySQL, configuring Apache to use index.php by default, andreconfiguring the php.ini file in php.
Creating a database for WordPress
For this guide, you’ll need to loginto your Azure VM. Once you’ve logged in, you’ll need to open up the MySQL 8.0 command line client as in guide 3 and start your Apache server. You will then need to enter the root password, also set in guide 3. This should look like fig 1.
Figure 1: MySQL Root Password
Once you’ve entered the password, we’ll check the existing databases using the following command:
show databases;
This will show a table including some of the default databases and the database(s) created for guide 3 as shown in fig 2.
Figure 2: Existing databases
Given that there should be no existing database for WordPress in this list, we will need to create one. This can be done with the following command:
create database wordpress;
This will create an empty database with the name “wordpress” . Remember that MySQL is case sensitive, so a database called ‘wordpress’ is not the same as one called ‘WordPress’ .
Creating the database should only give the output “Query OK, 1 row affected” and a count of how long it took to create. To check that it is in fact created, we can use “show databases;” again to produce Fig 3.
Figure 3: wordpress database created
Now that we’ve created the database ‘wordpress’, we’re able to access it and manipulate it using the root account. However, for WordPress to use it, we will need to create an account that WordPress can use.
Enter the following command substituting username for the username you want. Make sure not to use WordPress as the username. I recommend using your first name for the username as that is easy to remember. You will also need to substitute in the password. Note that the password needs to match your SQL password. Also note that the apostrophe symbols are included. This should look like Fig 4. CREATE USER 'username'@'localhost' IDENTIFIED BY ' password';
Figure 4: MySQL user created for WordPress
With the account created, we next have to give it permission to use the wordpress database with the following SQL command, using yourusername and password:
GRANT ALL ON wordpress.* TO ‘ username’@’localhost’;
Figure 5: Giving privileges to your wordpress account
With this applied, we can exit MySQL command line with the following code:
EXIT
With MySQL sorted out,we can move on to configuring index.php to be the default in Apache.
Setting index.php to Apache default
Previously we’ve put php into the index.html file to run php inside html. This can also be done the other way around, using a .php file to run both html and php. Since WordPress uses an index.php file, we need to change the Apache conf file to permit index.php files as well as index.html files. To do this, navigate back to the conf folder in Apache24 and open httpd.conf with your text editor.
Figure 6: Opening httpd.conf
Inside the httpd.conf folder, you should be able to find the following code:
<IfModule dir_module>
DirectoryIndex index.html
</IfModule>
This sets the default file to open when going to the website. We will want the server to use index.php files first, so we insert ‘index.php’ before ‘index.html’ as shown in Fig 7.
Figure 7: Setting default to index.php before index.html
Make sure to save this change before closing the file. Now that the change is implemented, you need to restart Apache.
Last week we created a php.ini file to configure php. This week, we are going to make some changes to it and enable some extensions that will be helpful for creating our WordPress.org blog.
Start by going to the c:\php folder. Next, open the php.ini (Previously php.ini-production) file with notepad or your downloaded text editor. This should look like Fig 8.
Figure 8: Inside of php.ini file
Now, scroll down to Resource Limits. Here, we will increase the resource limit for max_execution_time to 180 as shown in Fig 9.
Figure 9: Increasing max_execution_time from 30 to 180.
The reason for this is to give the VMs more time to install the plugins before timing out and reporting an error. Depending on your VM size, you may need to increase this further.
Next, scroll down further to ‘Dynamic extensions’ and find ;extension=mysqli and ;extension=openssl. We want to remove the semicolon ‘;’ at the start to change it from a code comment to normal code. This enables the extension. With the semicolon removed, it should look like Fig 9.
Figure 10: Semicolon removed to enable extension mysqli
The reason we are enabling the mysqli extension is to act in place of an old php function called
“mysql_Connect” . PHP no longer includes this by default so extension mysqli allows this function to work again. Without this extension, WordPress will run into a ‘critical error’ . The openssl extension simply makes downloading WordPress plugins and updates easier.
To apply these changes to PHP, make sure to restart your Apache server.
With the php.ini files switched and extensions enabled, and max_execution_time set to 180, we are now set up to setting up WordPress itself.
Downloading WordPress
To download wordpress, goto wordpress.org/download/ and select Download WordPress 5.9.3 as shown in Fig 11.
Figure 11: wordpress.org/download/
Once this button is clicked the download will start and an alert will popup saying “Hooray …” and
providing links to documentation. While the documentation is very thorough, we will be skipping this and going straight to saving the download as shown in Fig 12.
Figure 12: Save WordPress download
Once this is downloaded, you can navigate to the download folder. If you are using another browser, the default save location may be somewhere else.
Figure 13: WordPress in downloads folder (note, you will have a different version)
Once you’ve found the folder, extract it. This will extract the contents, leaving you with a folder called wordpress-5.9.3. Open this folder, and the wordpress folder within it (shown in Fig 14).
Figure 14: wordpress folder
Within the wordpress folder, we should see a number of files, including one called ‘index.php’ as shown in Fig 15.
Figure 15: wordpress folder contents
We want to copy them all using ‘Ctrl+A’ and ‘Ctrl+C’ or ‘Command+A’ and ‘Command+C’ . Next we want to move to our htdocs folder in Apache24 and delete the existing files. If you want to keep them, you can instead create another folder on your desktop and move them there. The intention is to have an
empty htdocs folder to copy the wordpress files into.
Figure 16: Empty htdocs folder
Now we can paste the files in using ‘Ctrl+V’ or ‘Command+V’, producing Fig 17.
Figure 17: wordpress files in htdocs folder
With the files in place,we can now open the browser and visit localhost. This will redirect you to
localhost/wp-admin/setup-config.php. You may also be redirected to a similar page rather than the languageselection page, which is fine. If it does not work at all, restarting your VM will likely fix this.
Figure 18: localhost wordpress language select
Select English (United States) and Continue. The following page (Fig 19) explains the purpose of this stage; put simply this is to enter the details of the database we created for WordPress.
Figure 19: wp-config explanation
Once you’ve read this page, select “Let’sgo!” . This will take you to Fig 20.
Figure 20: Entering database details
Enter the following details:
● Database Name: wordpress (This is the database we created at the start of this guide)
● Username: (This is the username defined in MySQL earlier in this guide)
● Password: (This is the password defined in MySQL earlier after ‘IDENTIFIED BY’)
● Database Host: localhost
● Table Prefix: wp_
Upon completing this and clicking ‘Submit’, you maybe greeted with an error page similar to Fig 21.
Figure 21: Error, can’t write the wp-config.php file.
Alternatively, you maybe met with the text “All right, sparkly!” as shown in Fig 22.
Figure 22: Success for WordPress setup
If you have received the page with “All right, Sunshine”, as shown above in Fig 22, you can click ‘ Run the installation’ and skip toInstalling WordPressas your database will already be configured. If you
received an error message like Fig 21, continue toError: Can’t write wp-config.php. If youran into a critical error, seeReconfiguring php.ini.
Error: Can’t write wp-config.php
If you received an error saying that WordPress could not configure the wp-config.php folder for you,
don’t worry. This error message is common and is easy to fix. You will want to copy all of this text inside of the box (CTRL+A, then CTRL+C). Next, we want to create a configuration file for WordPress. Navigate back to your htdocs folder as shown in Fig 23.
Figure 23: Navigating back to htdocs to create wp-config.php
Once in this folder, create a new text document as shown in Fig 24.
Figure 24: Creating a new text document
Then, name the new file wp-config.php as shown in Fig 25.
Figure 25: Naming new file wp-config.php
Opening the new wp-config.php file with your text editor will show an empty file. Note that it maybe sorted to a new location once it is renamed. Once inside, paste the contents copied from the Fig 21 box. Make sure to save the file. You should now be able to install as normal by visiting localhost again.
Congratulations, you’ve made it to the actual installation phase. Hopefully you have been met with the welcome page as shown in Fig 26. Here, you need to set the following details:
● Site Title: Workshop
● Username: Owner
● Password: (The same password you set for MySQL, which you will need to confirm if it was a weak password)
● Your Email: (The email you want to use for the owner accountblank@blank.com)
You can change these if necessary. Ignore the search engine visibility and proceed by clicking ‘Install WordPress’ .
You will now be able to sign into your WordPress account using the username Owner and password set. Once signed in, you should see the dashboard as shown in Fig 27 (InUsing WordPress).
Figure 26: WordPress site and account creation
With WordPress downloaded and installed, we can finally start using it. WordPress is essentially a
blogging tool which you can use to create your own blogging site with multiple users. The main view for the blog owner account is the dashboard view.
Figure 27: WordPress dashboard
Formatting WordPress for online
By default, WordPress is set up to work on the server. This means it looks for the CSS files (Makes the website look pretty) under the assumption that the user is on the website computer. We will need to rely on this and edit Wordpress from within the VM. If you had an alternative DNS, we would be able to change the settings on your site, to allow it to be accessed from the internet more generally.
You should familiarise yourself with the WordPress dashboard.
To get an idea of how WordPress works, navigate to it using localhost. It should look like Fig 29.
Figure 29: WordPress website as seen from non-owner
This view is what it looks like to those who do not have permission to access the dashboard. If you want to sign into WordPress from another computer, you can do so by adding /wp-login.php to the end of the localhost in your browser. Now, let’s customise our WordPress site.
To make a post, you must be signed in as the user ‘owner’ . On your dashboard you should see Posts as shown in Fig 29. Hover your mouse over ‘Posts’, and click on ‘Add New’ .
Figure 29: Add New Post
You will then be brought to the block editor as shown in Fig 30. Here, you can construct your blog post. The content of your first post is at your discretion.
Figure 30: Block Editor
Once you are happy with your post, select ‘Publish’ in the top right as shown in Fig 31.
Figure 31: Publish new blog post
Figure 32: Confirm publication new blog post
Confirm the publication by selecting ‘Publish’ as shown in Fig 32. With the post published, we can follow the provided link to view the blog post or by going to localhost/.
You can toggle between the Dashboard and Blog view by selecting the blog name (‘Workshop’) on the
top left.
Figure 34: Navigating back to the Dashboard
WordPress also allows the administrator/owner to add ‘Plugins’ to the WordPress blog. These plugins extend the normal functionality of WordPress. This functionality can be anything from payment options to gathering website statistics.
When choosing and using different plugins, be aware that the plugins may come with their own complexity and problems. They’re built largely by WordPress community members upon the changing foundation of PHP, MySQL, Apache, and WordPress. It will be up to you to find out if the plugins you want to use have ongoing problems and try to find possible solutions. For now, we’ll install a working plugin.
For this workshop we will show you how to install wpforms, a plugin that supports wordpress forms. To install it, navigate to ‘ Plugins’ on the home page and select ‘Add New’ .
Figure 35: Add New Plugins
You should now betaken to Fig 36, which shows featured plugins by default. To find specific plugins, you can use the ‘Search plugins’ bar at the top right. Search for wpforms and select ‘ Install Now’ as shown in Fig 36.
Figure 36: Add Plugins page
Installing may take a few minutes. Once it is installed, click on activate in the same location. This should take you to the downloaded plugins page as shown in Fig 37. If it produces an error describing ‘ no
transports’ or ‘ Maximum execution time exceeded’ seereconfiguring php.ini. Otherwise, proceed as normal.
Upon activating WPForms, it should take you to the welcome page shown in Fig 37.
Figure 37: Welcome to WPForms
You can follow the WPForms guide to creating their forms, or select WPForms and Add New as shown in Fig 38.
From here, you should see the form. templates as shown in Fig 38. You can use this to create a variety of different forms. For now, let’s create a blank form.
Figure 38: WPForms templates
From this page, you can build any form. that you want. It may take sometime to get the hang of the
layout. I’ve chosen to build a poll for preferences between MAC and PC as shown in Fig 39. Once you’re satisfied, select save, then submit a shown in Fig 39.
Figure 39: MAC vs PC form.
After clicking save and EMBED, you will be given the option to use an existing page or to create a new page. Click Use an Existing Page and use the following dropdown menu to select Sample Page. Then click Let’s Go!
You should betaken to the sample page. From here you can add the form by clicking the + button and searching for WPForms as shown in Fig 40.
Figure 40: Add WPForms to sample page
This should add a WPForms widget with a drop down selection of different forms. Select your form as shown in Fig 41.
Figure 41: Selecting the form in the WPForms widget.
Once you’ve selected your chosen form, it should show up as it will in the webpage. For the guide I created, this looks like Fig 42. You can then use the preview to try it out.
Figure 42: Completed MAC vs PC form.
Once you’re satisfied with your form in the sample page, select Update in the top right to save the changes and select the wordpress logo in the top left to return to the dashboard as shown in Fig 43.
Figure 43: Updating sample page and returning to dashboard
Now that we’ve returned to the dashboard, we can manage downloaded plugins by selecting Plugins on the navigation menu as shown in Fig 44. From here, you can Activate, Deactivate, Delete, and Update your plugins.
Figure 44: Downloaded Plugins management
With the end of this guide, you’ve created a WAMP web server using Azure cloud computing, Windows, Apache, MySQL, PHP, and on top of it all, WordPress. You also have a basic understanding of how to
create new WordPress blog posts as well as manage, and use a WordPress plugin. You can now tryout plugins you may want to use for your Inquiry Topic Blog due shortly.
● To improve your familiarity with the dashboard, find all the different ways to create a new blog post. There are at least four different ways.
● Create a few blog posts talking about something you like on a new page
● Find three different plugins to enhance the page