ubuntu 20.04 how to install wordpress code example

Example: install wordpress ubuntu 20.04

Once the LAMP stack (Apache, MariaDB, and PHP) 
  installed and configured on the Ubuntu 20.04 server, 
  you can proceed further to download the latest version 
  of WordPress using the following wget command.

$ wget -c http://wordpress.org/latest.tar.gz

  Once the download is complete, extract the archived 
  file using the tar command as shown.

$ tar -xzvf latest.tar.gz

  Next, move the extracted WordPress directory
  into your document root i.e. /var/www/html/ 
  and under your website as shown
  (replace mysite.com with your website’s name or domain name). 
  The following command will create a mysite.com directory 
  and move WordPress files under it.

$ sudo cp -R wordpress /var/www/html/mysite.com

  Now set appropriate permissions on the website
  (/var/www/html/mysite.com) directory. 
  It should be owned by the Apache2 user and group called www-data.

$ sudo chown -R www-data:www-data /var/www/html/mysite.com
$ sudo chmod -R 775 /var/www/html/mysite.com


---- Creating a WordPress Database for Website ---

   To get started, log into your MariaDB database shell using
   the following mysql command with -u flag to supply the username 
   which should be root and -p to enter a password that you 
   set for the MySQL root account when you
   installed the MariaDB software.
 
$ sudo mysql -u root -p

   After login, run the following commands to
   create your site’s database and a database 
   user with privileges as shown. Remember to 
   replace “mysite”, “mysiteadmin” and “SecureP@ssHere!” 
   with your database name, database username,
   and the user’s password.
 
 
CREATE DATABASE mysite;
GRANT ALL PRIVILEGES ON mysite.* TO 'mysiteadmin'@'localhost' IDENTIFIED BY 'SecureP@ssHere!';
FLUSH PRIVILEGES;
EXIT

  Next, move into your website’s document root,
  create a wp-config.php file from the sample 
  configuration file provided as shown.

$ cd /var/www/html/mysite.com
$ sudo mv wp-config-sample.php wp-config.php


  Then open the wp-config.php configuration file for editing.

$ sudo vim wp-config.php


  and update the database connection parameters 
  (database name, database user, 
  and the user’s password created above)
  
  
  
  
  ---- Creating Apache VirtualHost for WordPress Website ---
  
   Next, you need to configure Apache webserver to serve
   your WordPress site using your fully qualified domain name,
   by creating a Virtual Host for it under the Apache configuration.
   To create and activate a new Virtual Host, create a new 
   file under the /etc/apache2/sites-available/ directory. 
   In this example, we will call the file mysite.com.conf 
   (it should end with the .conf extension).
   

$ sudo vim /etc/apache2/sites-available/mysite.com.conf

  Then copy and paste the following configuration 
  in it (replacing the ServerName and ServerAdmin 
  emails with your values).
  
<VirtualHost *:80>
	ServerName mysite.com
	ServerAdmin webmaster@localhost
	DocumentRoot /var/www/html/mysite.com
	ErrorLog ${APACHE_LOG_DIR}/error.log
	CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>


  Save the file and close it.

    Then check the Apache configuration 
    for syntax correctness. 
    If the syntax is OK, 
    enable the new site and reload the 
    apache2 service to apply the new changes.

$ apache2ctl -t
$ sudo a2ensite mysite.com.conf
$ sudo systemctl reload apache2


    Also, disable the default virtual host to allow 
    your new site to load properly from a web browser.

$ sudo a2dissite 000-default.conf
$ sudo systemctl reload apache2

    The final section demonstrates how 
    to complete the WordPress installation 
    using the web installer. 
    So open your browser and navigate 
    using your site’s domain name:
    
    
http://mysite.com