Skip to main content

Setup a digital download site on WordPress

 This sample site was built on Azure VM, ubunti 18.04


Here're steps for setup:

  1. Update Ubuntu packages 
  2. Install Apache
  3. Check disk space
  4. Start/ Reload/ Stop service on Azure Ubuntu
  5. Install MySQL
  6. Install PHP and WordPress
  7. Setup SSL
  8. Check Apache Role
  9. Setup FTP on Azure VM



Update Ubuntu packages before installation 

Ref: https://tecadmin.net/upgrading-ubuntu-packages-command-line/

sudo update; sudo upgrade 


Install Apache 

Ref: https://ubuntu.com/tutorials/install-and-configure-apache#1-overview


sudo apt install apache2


When installation complete, 

Root path of the website: /var/www/html/

Apache config folder: /etc/apache2/

On tutorial, it shows you how to create a virtual host. (We could see command a2ensite (to apply new config file) when setting up a WordPress Site.) I have blog sites hosted on blogspot.com which provide domain name reassignment. I setup their domain names on Google Domains (https://domains.google.com/), and use redirection on .access file. 

Access control : /var/www/.htaccess

Redirect /index.html https://eblog.atfuture.ca/


Check disk space 

Ref: https://www.linux.com/training-tutorials/6how-check-disk-space-linux-command-line/

Check current condition 

df -H --output=source,size,used,avail

Check specific path

du -h /var/www/html


Start/ Reload/ Stop service on Azure Ubuntu

Ref: https://vitux.com/how-to-start-stop-or-restart-services-in-ubuntu/

Actually, Azure or AWS VM users don't really own root password. Command service might be out of reach. systemctl is practical one.


sudo systemctl start apache2 
sudo systemctl status apache2 
sudo systemctl restart apache2 
sudo systemctl reload apache2



Install MySQL

Ref: https://www.digitalocean.com/community/tutorials/how-to-install-mysql-on-ubuntu-18-04



sudo update; sudo upgrade
sudo apt install mysql-server
sudo mysql_secure_installation


setup password for MySQL root, and press 'Y' to the rest of questions



sudo mysql
....
mysql> SELECT user,authentication_string,plugin,host FROM mysql.user;

mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
mysql> FLUSH PRIVILEGES;
mysql> SELECT user,authentication_string,plugin,host FROM mysql.user;
mysql> CREATE USER 'db_mgr'@'localhost';
mysql> ALTER USER 'db_mgr'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
mysql> GRANT ALL PRIVILEGES ON *.* TO 'db_mgr'@'localhost' WITH GRANT OPTION;
mysql> exit

TEST:


sudo systemctl status mysql.service
sudo mysqladmin -p -u root version

MySQL Warning related:

Ref: https://dev.mysql.com/doc/refman/8.0/en/show-warnings.html

mysql> SHOW WARNINGS;



Install PHP and WordPress

Ref:  https://ubuntu.com/tutorials/install-and-configure-apache#1-overview

(DON'T INSTALL WORDPRESS HERE. IT'S OUT OF DATE.)


sudo apt update; sudo apt upgrade;
sudo apt install php libapache2-mod-php php-mysql


Ref: https://wordpress.org/download/


wget --url of wordpress zip file-- 
(unzip to the folder you want to install)
sudo mkdir /usr/share/wordpress
sudo unzip -d /usr/share/wordpress

sudo vi /etc/apache2/sites-available/wordpress.conf

(ref: https://ubuntu.com/tutorials/install-and-configure-wordpress#3-configure-apache-for-wordpress)

sudo a2ensite wirdoress
sudo a2enmod rewrite 
sudo systemctl reload apache2


sudo mysql -u root
 
mysql> CREATE DATABASE wordpress;
mysql> CREATE USER 'wordpress'@'localhost';
mysql> ALTER USER 'wordpress'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
mysql>  GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP,ALTER
    -> ON wordpress.*
    -> TO wordpress@localhost;
mysql> FLUSH PRIVILEGES;
mysql> quit

sudo cp /usr/share/wordpress/wp-config-sample.php /usr/share/wordpress/wp-config.php 

sudo vi /usr/share/wordpress/wp-config.php 
(find the following definition) 

<?php
define('DB_NAME', 'wordpress');
define('DB_USER', 'wordpress');
define('DB_PASSWORD', '<your-password>');
define('DB_HOST', 'localhost');
define('DB_COLLATE', 'utf8_general_ci');
?>

sudo systemctl start mysql 


Then open browser, go to the URL of your wordpress. It will start setup the owner's account. 


Setup SSL


You may want to see https on your site.

Ref: https://letsencrypt.org/
Ref: https://certbot.eff.org/lets-encrypt/ubuntubionic-apache


Check Apache Role


When wordpress encounter file system permission:

 WordPress was run by PHP, which work under Apache. Setup WordPress folder to allowing the access from Apache's group. Usually online QAs would recommend to set the access mode to 755 which means wordpress run by the login account. It may be true if you're the client of wordpress.com. If you install the server on your own, the owner probably be root@localhost. The process executor is Apache. If you also use ftp, which, again, another account on server. It's not realistic to set wordpress access mode to 755. 775 (g+w) is more reasonable. 



ps -ef | egrep '(httpd|apache2|apache)' | grep -v `whoami` | grep -v root | head -n1 | awk '{print $1}'
sudo chown www-data:www-data  /usr/share/wordpress/
sudo chmod -R 775 /usr/share/wordpress/


If WP still cannot find folder while install theme or plugin (usually folder permission resolves image/media uploading problems), adding additional filter works for me:

add_filter('filesystem_method', create_function('$a', 'return "direct";'));
define('FS_CHMOD_DIR', 0751);
define('WP_TEMP_DIR', ABSPATH.'wp-content/tmp');



Setup FTP on Azure VM

Ref: https://dev.to/aloneguid/setting-up-ftp-server-on-microsoft-azure-2npb

Create an account for WordPress Owner


sudo adduser wpmgr
(setup password ...etc.)


Setup port allowed on Azure Portal

Move on to VM

sudo apt update; sudo apt upgrade
sudo apt install vsftpd

sudo vi /etc/vsftpd.conf

---under editor
chroot_local_user=YES
user_sub_token=$USER
local_root=/home/$USER/ftp

pasv_enable=YES
pasv_min_port=10000
pasv_max_port=10010
(ports set in Azure)

seccomp_sandbox=NO
allow_writeable_chroot=YES



add_filter('filesystem_method', create_function('$a', 'return "direct";' ));

define( 'FS_CHMOD_DIR', 0751 );

define('WP_TEMP_DIR', ABSPATH . 'wp-content/tmp');



Comments

Popular posts from this blog

Bookmark service (MongoDB & Spring REST) -2/2

    I accidentally deleted my development VM. I got lucky having the habit of taking notes. This blog is useful. Development VM is doom to be lost. Rebuild it waste time, but having a clean slate is refreshing~. What concerns me more is my AWS free quota this month is reaching 85%. The second VM I launched but never being used might be the one to blame. (Of course, my mistake.) I terminated the wrong VM. Now I got Linux 2 built. Great, just threw away everything happened on AMI.  1st layer: Page Page class   Originally, I need to prepare getter/setter for all class properties for Spring. By using lombok, I only need to create constructors. lombok will deal with getter/setter and toString(). But there are chances to call getter/setter, but how? .......Naming convention.... Capitalize the 1st character with the prefix get/set.  Annotation @Data was used on this class.  Repository class Spring Docs: Repository https://docs.spring.io/spring-data/mongodb/docs/3....

gamer's interview

This project simulates a gamer's interview. Based on NodeJS+ ReactJS The setting is interviewing a gamer/journalist what's his/her plan of March 2020? The gamer answers his/her game list in plan, how many reviews on demand and how many hours expected. Games selected for review take 5 hours for each, while others take one. This project is designed to practice render html, jsx, component, props introduced in  https://www.w3schools.com/REACT/default.asp . Also fixed other issues to make it work. When trying to modualize objects and tools, my design developed to separate views and processes. And it is quite similar to the initialized structure NodeJS+ReactJS provided. Furthermore, since include local module files are banned by browsers, use NodeJS service seems to be the best option. view file main process object tool

Comments for my Server/Client Web API samples

        Finally, I finished the comments for python/07 and 09 projects. I almost forgot to put the date on source code which is used to note how long it took me. Not precisely in hours….. I didn’t include source code in my previous post. If choosing code-section for this post…… maybe I want to mark out my comment….. (Really?!)          Once my work was developing websites for enterprises, including ERP, CRM or content sites. The sustainability of network and security are important issues. There are 2 methods for HTML Form submission: GET and POST. Submit via POST is secure, compared to GET which piles parameters on URL. RESTful API is mainly using GET.         Yup, even if you have a certification key, if you put the value on the URL, it is visible data. When writing socket-communication, client-server sockets are a pair; both follow the agreement on commands and structures; and there are countless ports for usa...