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....

Guide to Preserving HuggingFace Models in Google Colab Environments

Conclusion:  Step 1:  find the model path: ls ~/.cache  Step 2:  Copy the entire folder to Google Drive:  Step 3:  Set model path to the subfolder under snapshot: My Story: I initially began exploring Generative AI (GAI) and Google Colab through Stable Diffusion. In the past, as I mainly wrote server services and console applications, I was less familiar with data science modes like R and Jupyter that can maintain a paused state. I didn't quite understand the heavy burden on Colab of creating a temporary Stable Diffusion WebUI with .ipynb, as suggested by popular guides. I just found it troublesome that connections often took a long time and then dropped, requiring a restart. Recently, while testing new versions of the Stable Diffusion model, and facing challenges due to Colab's policies making various versions of WebUI difficult to run successfully, I started researching how to write my own test programs in Colab. Eventually, I understood that Colab is ess...

Setup Maven and two basic projects

    The interesting implementation of Java I proceed to is Spring. And, only getting Java running is not enough. I also need to set up Maven. This name is new to me, and I found many Spring tutorials just skip this part. At least I need Maven to generate templates for me. I should learn it more. ( I knew there is a great tool -- Eclipse -- can make tedious things disappear. I’m taking a strategy to install all experiments I want to try and throw away when it's full. And that's an external VM, not my PC. I, not yet, want to do research about installing Eclipse on AMI. )    Upgrade to Java 8     First is to upgrade Java on AMI to Java8. AWS provides advanced tools for Linux 2. And DIY for Linux2. At least there are solutions for my choice.  Amazon Corretto 8 Installation Instructions for Amazon Linux 2 https://docs.aws.amazon.com/corretto/latest/corretto-8-ug/amazon-linux-install.html Here are commands I used: >wget */amazon-corretto-8-x64-linux-jdk.d...