Install and Configure WordPress on Ubuntu 22.04

This tutorial intends to teach you How To Install and Configure WordPress on Ubuntu 22.04.

WordPress is an open-source content management system (CMS). It’s a popular tool for individuals without any coding experience who want to build websites and blogs. The software doesn’t cost anything. Anyone can install, use, and modify it for free.

How To Install and Configure WordPress on Ubuntu 22.04

To install WordPress on your server, you need some requirements.

Requirements

First, you need to log in to your server as a non-root user with sudo privileges and set up a basic firewall. To do this, check our guide on the Initial Server Setup with Ubuntu 22.04.

Then, you need to have the LAMP Stack installed on your server. To do this, you can follow our guide How To Install LAMP Stack on Ubuntu 22.04.

Also, you need to secure your site with SSL. To do this, you can visit our article How To Secure Apache with Let’s Encrypt on Ubuntu 22.04.

When you are finished with these requirements, follow the steps below to complete this guide.

Create WordPress Database and User on Ubuntu 22.04

WordPress needs a database to store and manage site information. As you installed MariaDB from the LAMP installation, log in to your MariaDB console with the command below:

sudo mysql -u root -p

Then, you can create a WordPress database on Ubuntu 22.04 by running the following command from your MariaDB console:

Here we named our database WordPress you can choose a different name.

MariaDB [(none)]> CREATE DATABASE wordpress DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;

Now you can create a WordPress user with the command below, here we named it orca, just remember to replace the password with a strong password:

MariaDB [(none)]> GRANT ALL ON wordpress.* TO 'orca'@'localhost' IDENTIFIED BY 'password';

Next, flush the privileges:

MariaDB [(none)]> FLUSH PRIVILEGES;

Exit from your MariaDB console with the command below:

MariaDB [(none)]> EXIT;

Install PHP extensions and Configure Apache on Ubuntu 22.04

At this point, you need to install some PHP exertions for your WordPress on Ubuntu 22.04.

First, update your local package index with the following command:

sudo apt update

Then, install the PHP extensions with the following command:

sudo apt install php-curl php-gd php-mbstring php-xml php-xmlrpc php-soap php-intl php-zip

Now you need to reload Apache to apply for the new extensions:

sudo systemctl restart apache2

Next, you need to make some configuration changes for Apache.

From the requirements, you should have a configuration file for your site in the /etc/apache2/sites-available/ directory.

Additionally, we will use /var/www/your-domain as the root directory of our WordPress install. You should use the webroot specified in your own configuration.

You need to open the Apache configuration file with your favorite text editor, here we use vi:

sudo vi /etc/apache2/sites-available/your-domain.conf

Add the following block inside the virtual host block in your configuration file:

Be sure to use the correct webroot directory.

<Directory /var/www/your-domain/>
AllowOverride All
</Directory>

When you are finished, save and close the file.

Now you need to enable the rewrite module with the following command:

sudo a2enmod rewrite

Make sure that you haven’t made any syntax errors:

sudo apache2ctl configtest

In your output you will see:

Output
Syntax OK

Then, restart Apache to apply the new changes:

sudo systemctl restart apache2

Set up WordPress on Ubuntu 22.04

At this point, once you have configured your server, you can download and install WordPress on your server.

We will download WordPress from its official site in the latest version.

First, switch to the /tmp directory:

cd /tmp

Then, use the curl command to download the WordPress on Ubuntu 22.04:

curl -O https://wordpress.org/latest.tar.gz

Extract your downloaded file with the following command:

tar xzvf latest.tar.gz

Now you need to add a dummy “.htaccess” file, that will be available for WordPress to use later. To do this, run the following command:

touch /tmp/wordpress/.htaccess

Next, copy over the sample configuration file to the filename that WordPress actually reads:

cp /tmp/wordpress/wp-config-sample.php /tmp/wordpress/wp-config.php

Also, you need to create an “upgrade” directory for WordPress that doesn’t get into trouble with permissions issues when trying to do this on its own following an update to its software:

mkdir /tmp/wordpress/wp-content/upgrade

Here you should copy the entire contents of the directory into your document root with the following command:

sudo cp -a /tmp/wordpress/. /var/www/your-domain

Configure WordPress on Ubuntu 22.04

At this point, that you have successfully installed WordPress onto your web server, you need to make some configuration changes in the WordPress directory.

First. update the ownership with the following command:

sudo chown -R www-data:www-data /var/www/your-domain

Then, you need to set the correct permissions on the WordPress directories and files on Ubuntu 22.04:

$ sudo find /var/www/your-domain/ -type d -exec chmod 750 {} \;
$ sudo find /var/www/your-domain/ -type f -exec chmod 640 {} \;

Now you need to get secure values from the WordPress secret key generator with the following command:

curl -s https://api.wordpress.org/secret-key/1.1/salt/

In your output, you will get unique values similar to this:

Output
define('AUTH_KEY', '@p&v$t.E6tve6|<M}C?CDfi-|:)YpW1``Qb!XO)N6BFII^[yO%KEo|ZpE?xQUXj(');
define('SECURE_AUTH_KEY', 'XkX[{_vaSesOq8|Sx5-Hh?`aF1_m!Fu/3A$/>WW:,WAVG3ZG[ZjT7XxO5K|MedM`');
define('LOGGED_IN_KEY', '{n_y/bE%)S44d9=A?{TvL3EW6w|@swJ{Z=Y~NZL^7?c=62X$}kB`!(OW|v-d.0u:');
define('NONCE_KEY', '[email protected],q-&k]q~B:+;X)(},[vSFh?E{J<&&3zC?)I<Fe+)x!{%G9+M0>UZr+/B');
define('AUTH_SALT', 'K||JNVt^L>E?+G$$8.W66e%[email protected]_e6R78xQ^7k 8lY3?e#[email protected]|p<47o!2');
define('SECURE_AUTH_SALT', 'qpfkk^fS^tTE`A97c}%<*9LP2Ij<y|VJ`K+[o(htd NV+U$gY-8WO?7q;9lf>a<(');
define('LOGGED_IN_SALT', 'qjJvr[V!t{*]=Y^D41Sg~OM+24^fh(ffGY_.i[er)WAHU3)];dFN=PNXa53,SuY+');
define('NONCE_SALT', '*dLi~44~Z-tp~#:B|YyCTa6*f5T$%6yL|^HEBl7`UXHR5E(_6^inPWPW~E)hGZ2[');

Note:  It is important that you request unique values each time. Do NOT copy the values shown above.

Now you need to open the WordPress main configuration file on Ubuntu 22.04 and paste the values directly to the file to set secure keys.

Open the file with your favorite text editor, here we use vi:

sudo vi /var/www/your-domain/wp-config.php

Find the section that contains the dummy values for those settings.

. . .
define('AUTH_KEY',         'put your unique phrase here');
define('SECURE_AUTH_KEY',  'put your unique phrase here');
define('LOGGED_IN_KEY',    'put your unique phrase here');
define('NONCE_KEY',        'put your unique phrase here');
define('AUTH_SALT',        'put your unique phrase here');
define('SECURE_AUTH_SALT', 'put your unique phrase here');
define('LOGGED_IN_SALT',   'put your unique phrase here');
define('NONCE_SALT',       'put your unique phrase here');
. . .

Delete the line and paste the unique values that you have copied from the command line.

Then, in the database connection settings at the top of the file, you need to set the database name, database user, and password.

. . .
define('DB_NAME', 'wordpress');
/** MySQL database username */
define('DB_USER', 'orca');
/** MySQL database password */
define('DB_PASSWORD', 'password');
. . .
Next, add the following line to the database connection settings or anywhere else that you want.
define('FS_METHOD', 'direct');

When you are done, save and close the file.

Access WordPress Web Interface

At this point, you can complete your WordPress installation on Ubuntu 22.04 through the web interface.

Type your domain name or your server’s IP address in your web browser:

https://server_domain_or_IP

On the first page, you need to select your desired language and click on the continue.

Select Language for your WordPress

In the next window, you will see the main setup page.

Select a name for your WordPress site and choose a username (it is recommended not to choose something like “admin” for security purposes). A strong password is generated automatically. Save this password or select an alternative strong password.

Enter your email address and select whether you want to discourage search engines from indexing your site.

WordPress info

Click on the install WordPress, you will see the page where you can log in to your WordPress:

WordPress successful installation

Enter your WordPress user and password, you will see the WordPress dashboard:

WordPress dashboard on Ubuntu 22.04

Congratulations, WordPress is now installed and is ready to be used.

At this point you may want to start doing the following:

  • Choose your permalinks setting for WordPress posts, which can be found in Settings > Permalinks.
  • Select a new theme in Appearance > Themes.
  • Install new plugins to increase your site’s functionality under Plugins > Add New.
  • If you are going to collaborate with others, you may also wish to add additional users at this time under Users > Add New.

For more information, you can visit the WordPress features Page.

Conclusion

At this point, you learn to Install and Configure WordPress on Ubuntu 22.04.

Hope you enjoy it.

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles

POPULAR TAGS

Most Popular