Nature Wapuu Wallpaper Collection: Wapuu sitting on the red fence

Install WordPress On Ubuntu22.04 Using LAMP Stack With HTTPS




1 / 7

[Refer To] https://ubuntu.com/tutorials/install-and-configure-wordpress#1-overview

This tutorial assume you own domain name is example.com, and want to access WordPress via port other then 80/443.

Install Dependencies

Bash
sudo apt update && sudo apt install apache2 ghostscript libapache2-mod-php mysql-server php php-bcmath php-curl php-imagick php-intl php-json php-mbstring php-mysql php-xml php-zip

Install WordPress

Bash
sudo mkdir -p /srv/www
sudo chown www-data: /srv/www
curl https://wordpress.org/latest.tar.gz | sudo -u www-data tar zx -C /srv/www

Configure Apache for WordPress

Create Apache site for WordPress. Create /etc/apache2/sites-available/wordpress.conf with following lines:

Apache
<VirtualHost *:8080>
    ServerName example.com:8080
    ServerAlias www.example.com:8080
    Redirect permanent / https://astro-tech.top:8443/
</VirtualHost>

<VirtualHost *:8443>
    ServerName example.com:8443
    ServerAlias www.example.com:8443
    DocumentRoot /srv/www/wordpress

    SSLEngine on
    SSLCertificateFile /example.com/example.com.cer
    SSLCertificateKeyFile /example.com/example.com.key
    SSLCertificateChainFile /example.com/fullchain.cer

    RewriteEngine On
    RewriteCond %{HTTPS} off
    RewriteRule ^(.*)$ https://%{HTTP_HOST}:8443%{REQUEST_URI} [L,R=301]

    <Directory /srv/www/wordpress>
        Options FollowSymLinks
        AllowOverride Limit Options FileInfo
        DirectoryIndex index.php
        Require all granted
    </Directory>
    <Directory /srv/www/wordpress/wp-content>
        Options FollowSymLinks
        Require all granted
    </Directory>
</VirtualHost>

NOTE: You probably need DNS-01 challenge to request a certificate from Let’s Encrypt.

Enable the site with:

Bash
sudo a2ensite wordpress

Enable URL rewriting with:

Bash
sudo a2enmod rewrite

Enable SSL/TLS with:

Bash
sudo a2enmod ssl

Disable the default “It Works” site with:

Bash
sudo a2dissite 000-default

Finally, reload apache2 to apply all these changes:

Bash
sudo service apache2 reload

P.S. You need to modify apache2 listen port in /etc/apache2/ports.conf:

Apache
# If you just change the port or add more ports here, you will likely also
# have to change the VirtualHost statement in
# /etc/apache2/sites-enabled/000-default.conf

Listen 8080

<IfModule ssl_module>
        Listen 8443
</IfModule>

<IfModule mod_gnutls.c>
        Listen 8443
</IfModule>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

Configure database

Bash
$ sudo mysql -u root
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.7.20-0ubuntu0.16.04.1 (Ubuntu)

Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> CREATE DATABASE wordpress;
Query OK, 1 row affected (0,00 sec)

mysql> CREATE USER wordpress@localhost IDENTIFIED BY '<your-password>';
Query OK, 1 row affected (0,00 sec)

mysql> GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP,ALTER
    -> ON wordpress.*
    -> TO wordpress@localhost;
Query OK, 1 row affected (0,00 sec)

mysql> FLUSH PRIVILEGES;
Query OK, 1 row affected (0,00 sec)

mysql> quit
Bye

Enable MySQL with sudo service mysql start.

Configure WordPress to connect to the database

Now, let’s configure WordPress to use this database. First, copy the sample configuration file to wp-config.php:

Bash
sudo -u www-data cp /srv/www/wordpress/wp-config-sample.php /srv/www/wordpress/wp-config.php

Modify /srv/www/wordpress/wp-config.php. First, change <DATABASE_NAME> / <DATABASE_USER> / <DATABASE_PASSWORD> to your own. Then, get random key from https://api.wordpress.org/secret-key/1.1/salt/ and replace them in <key>.(This address is a randomiser that returns completely random keys each time it is opened.) This step is important to ensure that your site is not vulnerable to “known secrets” attacks:

PHP
<?php
/**
 * The base configuration for WordPress
 *
 * The wp-config.php creation script uses this file during the installation.
 * You don't have to use the web site, you can copy this file to "wp-config.php"
 * and fill in the values.
 *
 * This file contains the following configurations:
 *
 * * Database settings
 * * Secret keys
 * * Database table prefix
 * * ABSPATH
 *
 * @link https://wordpress.org/documentation/article/editing-wp-config-php/
 *
 * @package WordPress
 */

define( 'WP_SITEURL','https://example.com:8443' );
define( 'WP_HOME','https://example.com:8443' );

// ** Database settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define( 'DB_NAME', '<DATABASE_NAME>' );

/** Database username */
define( 'DB_USER', '<DATABASE_USER>' );

/** Database password */
define( 'DB_PASSWORD', '<DATABASE_PASSWORD>' );

/** Database hostname */
define( 'DB_HOST', 'localhost' );

/** Database charset to use in creating database tables. */
define( 'DB_CHARSET', 'utf8mb4' );

/** The database collate type. Don't change this if in doubt. */
define( 'DB_COLLATE', '' );

/**#@+
 * Authentication unique keys and salts.
 *
 * Change these to different unique phrases! You can generate these using
 * the {@link https://api.wordpress.org/secret-key/1.1/salt/ WordPress.org secret-key service}.
 *
 * You can change these at any point in time to invalidate all existing cookies.
 * This will force all users to have to log in again.
 *
 * @since 2.6.0
 */
define( 'AUTH_KEY',         '<key>' );
define( 'SECURE_AUTH_KEY',  '<key>' );
define( 'LOGGED_IN_KEY',    '<key>' );
define( 'NONCE_KEY',        '<key>' );
define( 'AUTH_SALT',        '<key>' );
define( 'SECURE_AUTH_SALT', '<key>' );
define( 'LOGGED_IN_SALT',   '<key>' );
define( 'NONCE_SALT',       '<key>' );

/**#@-*/

/**
 * WordPress database table prefix.
 *
 * You can have multiple installations in one database if you give each
 * a unique prefix. Only numbers, letters, and underscores please!
 */
$table_prefix = 'wp_';

/**
 * For developers: WordPress debugging mode.
 *
 * Change this to true to enable the display of notices during development.
 * It is strongly recommended that plugin and theme developers use WP_DEBUG
 * in their development environments.
 *
 * For information on other constants that can be used for debugging,
 * visit the documentation.
 *
 * @link https://wordpress.org/documentation/article/debugging-in-wordpress/
 */
define( 'WP_DEBUG', false );

/* Add any custom values between this line and the "stop editing" line. */



/* That's all, stop editing! Happy publishing. */

/** Absolute path to the WordPress directory. */
if ( ! defined( 'ABSPATH' ) ) {
        define( 'ABSPATH', __DIR__ . '/' );
}

/** Sets up WordPress vars and included files. */
require_once ABSPATH . 'wp-settings.php';

Configure WordPress

Now, you can configure WordPress via https://example.com:8443

That’s all!



Leave a Reply

Your email address will not be published. Required fields are marked *

Exit mobile version