<\/p>\n
WordPress is a very popular CMS and it remains the easiest and best open-source application for building websites. People mostly use WordPress for blogging, although actually it also supports other types of CMS like e-commerce, forums, etc.<\/p>\n
It offers you the freedom to build anything you want, it has thousands of plugins and themes that you can use to customize your website. The installation is fairly easy, you can simply follow the steps in this tutorial and you will learn how to install WordPress on Ubuntu 22.04<\/a>.<\/p>\n
Table of Contents<\/p>\n
First, you will need to log in to your Ubuntu 22.04 VPS via SSH as the root user:<\/p>\n
ssh root@IP_Address -p Port_number<\/pre>\nYou will need to replace ‘IP_Address’ and ‘Port_number’ with your server’s actual IP address and SSH port number. Additionally, replace ‘root’ with the username of the system user with sudo privileges.<\/p>\n
You can check whether you have the proper Ubuntu version installed on your server with the following command:<\/p>\n
# lsb_release -a<\/pre>\nIt will return an output like this.<\/p>\n
No LSB modules are available.\r\nDistributor ID: Ubuntu\r\nDescription: Ubuntu 22.04 LTS\r\nRelease: 22.04\r\nCodename: jammy<\/pre>\nWe will use ‘root’ in this article when running the shell commands. If you want to use your regular user with sudo privileges to run the commands, make sure to append ‘sudo’ in front of the commands.<\/p>\n
<\/span>Step 2: Update the system<\/span><\/h2>\n
Before starting, you have to make sure that all Ubuntu 22.04 packages installed on the server are up to date. You can do this by running the following commands:<\/p>\n
# apt update\r\n# apt upgrade<\/pre>\n<\/span>Step 3: Install SSL Certificate<\/span><\/h2>\n
In this article, WordPress will be installed on the secured protocol (HTTPS). So, we need to install an SSL certificate before we can proceed with the other steps.<\/p>\n
# apt install python3-certbot-nginx -y<\/pre>\nPrior to generating a new SSL certificate for your wordpress.example.com, make sure you pointed the domain\/subdomain DNS A record to your server IP address already. If Certbot is unable to generate a free SSL certificate, most likely the DNS update is not fully propagated.<\/p>\n
# certbot certonly --non-interactive --agree-tos -m you@example.com -d wordpress.example.com --standalone<\/pre>\nIf successful, you will see an output like this:<\/p>\n
Saving debug log to \/var\/log\/letsencrypt\/letsencrypt.log\r\nRequesting a certificate for wordpress.example.com\r\n\r\nSuccessfully received certificate.\r\nCertificate is saved at: \/etc\/letsencrypt\/live\/wordpress.example.com\/fullchain.pem\r\nKey is saved at: \/etc\/letsencrypt\/live\/wordpress.example.com\/privkey.pem\r\nThis certificate expires on 2022-08-06.\r\nThese files will be updated when the certificate renews.\r\nCertbot has set up a scheduled task to automatically renew this certificate in the background.\r\n\r\n- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\r\nIf you like Certbot, please consider supporting our work by:\r\n* Donating to ISRG \/ Let's Encrypt: https:\/\/letsencrypt.org\/donate\r\n* Donating to EFF: https:\/\/eff.org\/donate-le\r\n- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -<\/pre>\n<\/span>Step 4: Install PHP 8.1<\/span><\/h2>\n
Ubuntu 22.04 ships with PHP 8.1 as the default PHP version. We are going to use this PHP version for our WordPress website<\/a>. Run this command below to install PHP 8.1 and its required extensions.<\/p>\n
# apt install php-{curl,fpm,imagick,mbstring,mysql,xml,zip}<\/pre>\nOnce completed, the PHP-FPM service will be running automatically. We are not going to edit the PHP-FPM configuration. We will use the default PHP-FPM www.conf file. To ensure PHP-FPM is running, you can verify it with this command:<\/p>\n
# systemctl status php8.1-fpm<\/pre>\n<\/span>Step 5: Install and Configure Web Server<\/span><\/h2>\n
Nginx is a fast and secure web server and one of the most popular and widely used web servers in the world. To install the Nginx web server on Ubuntu 22.04 run the following command:<\/p>\n
# apt install nginx<\/pre>\nNext, let’s create a new nginx server block for our WordPress website.<\/p>\n
# nano \/etc\/nginx\/conf.d\/wprdpress.conf<\/pre>\nPaste the following into the new file.<\/p>\n
upstream php-handler {\r\nserver unix:\/run\/php\/php8.1-fpm.sock;\r\n}\r\n\r\nserver {\r\nlisten 80;\r\nserver_name wordpress.example.com;\r\nreturn 301 https:\/\/$server_name$request_uri;\r\n}\r\n\r\nserver {\r\nlisten 443 ssl http2;\r\nserver_name wordpress.example.com;\r\n\r\n# Path to the root of your installation\r\nroot \/var\/www\/wordpress;\r\nindex index.php;\r\n\r\nssl_certificate \/etc\/letsencrypt\/live\/wordpress.example.com\/fullchain.pem;\r\nssl_certificate_key \/etc\/letsencrypt\/live\/wordpress.example.com\/privkey.pem;\r\n\r\n# Prevent nginx HTTP Server Detection\r\nserver_tokens off;\r\n\r\naccess_log \/var\/log\/nginx\/wordpress_access.log;\r\nerror_log \/var\/log\/nginx\/wordpress_error.log;\r\n\r\nclient_max_body_size 64M;\r\n\r\nlocation \/ {\r\ntry_files $uri $uri\/ \/index.php?$args;\r\n}\r\n\r\nlocation ~ \\.php$ {\r\ntry_files $uri =404;\r\ninclude \/etc\/nginx\/fastcgi_params;\r\nfastcgi_read_timeout 3600s;\r\nfastcgi_buffer_size 128k;\r\nfastcgi_buffers 4 128k;\r\nfastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;\r\nfastcgi_pass php-handler;\r\nfastcgi_index index.php;\r\n}\r\n\r\n}<\/pre>\nMake sure to replace wordpress.example.com with your actual domain or subdomain name. Save and close the file.<\/p>\n
<\/span>Step 6: Install MariaDB Server and Create a Database<\/span><\/h2>\n
The next step is to install the MariaDB server which will be used for the data storage of your WordPress site.<\/p>\n
To install the MariaDB server, invoke this command:<\/p>\n
# apt install mariadb-server<\/pre>\nAfter the installation is completed, we can proceed with creating a new database and database user.<\/p>\n
# mysql<\/pre>\nOnce logged in to the MySQL shell, we can run the following commands.<\/p>\n
mysql> CREATE DATABASE wordpress_db;\r\nmysql> CREATE USER wordpress_user@localhost IDENTIFIED BY 'm0d1fyth15';\r\nmysql> GRANT ALL PRIVILEGES ON wordpress_db.* TO wordpress_user@localhost;\r\nmysql> FLUSH PRIVILEGES;\r\nmysql> \\q<\/pre>\n<\/span>Step 7: Install WordPress using WP-CLI<\/span><\/h2>\n
In this step, we are going to download WP-CLI and use it to install WordPress. WP-CLI is a tool to manage your WordPress installation through a command-line interface.<\/p>\n
# wget https:\/\/raw.githubusercontent.com\/wp-cli\/builds\/gh-pages\/phar\/wp-cli.phar -O \/usr\/local\/bin\/wp<\/pre>\nThe command above will download wp-cli.phar file and save it as \/usr\/local\/bin\/wp, so you can just type ‘wp’ in your command. But first, let’s make the file executable.<\/p>\n
# chmod +x \/usr\/local\/bin\/wp<\/pre>\nNow, you should be able to run ‘wp’, for example<\/p>\n
# sudo -u www-data wp --info<\/pre>\nThis will return an output like this:<\/p>\n
root@ubuntu22:\/var\/www\/html# sudo -u www-data wp --info\r\nOS: Linux 5.15.0-1004-gcp #7-Ubuntu SMP Wed Apr 20 04:26:07 UTC 2022 x86_64\r\nShell: \/usr\/sbin\/nologin\r\nPHP binary: \/usr\/bin\/php8.1\r\nPHP version: 8.1.2\r\nphp.ini used: \/etc\/php\/8.1\/cli\/php.ini\r\nMySQL binary: \/usr\/bin\/mysql\r\nMySQL version: mysql Ver 15.1 Distrib 10.6.7-MariaDB, for debian-linux-gnu (x86_64) using EditLine wrapper\r\nSQL modes: \r\nWP-CLI root dir: phar:\/\/wp-cli.phar\/vendor\/wp-cli\/wp-cli\r\nWP-CLI vendor dir: phar:\/\/wp-cli.phar\/vendor\r\nWP_CLI phar path: \/var\/www\/html\r\nWP-CLI packages dir: \r\nWP-CLI global config: \r\nWP-CLI project config: \r\nWP-CLI version: 2.6.0<\/pre>\nNext, let’s create a directory for our WordPress website’s document root then download the latest version of WordPress.<\/p>\n
# mkdir \/var\/www\/wordpress \r\n# cd \/var\/www\/wordpress \r\n# chown -R www-data: \/var\/www\r\n<\/pre>\nTo download WordPress core files, simply run this command below.<\/p>\n
# sudo -u www-data wp core download<\/pre>\nYou can see that \/var\/www\/wordpress\/ has WordPress core files, you can list them with ‘ll’ command.<\/p>\n
root@ubuntu22:\/var\/www\/wordpress# ll\r\ntotal 224\r\ndrwxr-xr-x 5 www-data www-data 4096 May 8 11:27 .\/\r\ndrwxr-xr-x 4 root root 4096 May 8 11:27 ..\/\r\n-rw-r--r-- 1 www-data www-data 405 May 8 11:27 index.php\r\n-rw-r--r-- 1 www-data www-data 19915 May 8 11:27 license.txt\r\n-rw-r--r-- 1 www-data www-data 7437 May 8 11:27 readme.html\r\n-rw-r--r-- 1 www-data www-data 7165 May 8 11:27 wp-activate.php\r\ndrwxr-xr-x 9 www-data www-data 4096 May 8 11:27 wp-admin\/\r\n-rw-r--r-- 1 www-data www-data 351 May 8 11:27 wp-blog-header.php\r\n-rw-r--r-- 1 www-data www-data 2338 May 8 11:27 wp-comments-post.php\r\n-rw-r--r-- 1 www-data www-data 3001 May 8 11:27 wp-config-sample.php\r\ndrwxr-xr-x 4 www-data www-data 4096 May 8 11:27 wp-content\/\r\n-rw-r--r-- 1 www-data www-data 3939 May 8 11:27 wp-cron.php\r\ndrwxr-xr-x 26 www-data www-data 16384 May 8 11:27 wp-includes\/\r\n-rw-r--r-- 1 www-data www-data 2496 May 8 11:27 wp-links-opml.php\r\n-rw-r--r-- 1 www-data www-data 3900 May 8 11:27 wp-load.php\r\n-rw-r--r-- 1 www-data www-data 47916 May 8 11:27 wp-login.php\r\n-rw-r--r-- 1 www-data www-data 8582 May 8 11:27 wp-mail.php\r\n-rw-r--r-- 1 www-data www-data 23025 May 8 11:27 wp-settings.php\r\n-rw-r--r-- 1 www-data www-data 31959 May 8 11:27 wp-signup.php\r\n-rw-r--r-- 1 www-data www-data 4747 May 8 11:27 wp-trackback.php\r\n-rw-r--r-- 1 www-data www-data 3236 May 8 11:27 xmlrpc.php<\/pre>\nAs you can see, there is no wp-config.php in the directory. Let’s proceed with creating the wp-config.php file. but before running the command below, make sure you replace the database name, database username, and password.<\/p>\n
# sudo -u www-data wp core config --dbhost=localhost --dbname=wordpress_db --dbuser=wordpress_user --dbpass=m0d1fyth15<\/pre>\nYou will see a message that the wp-config.php file is generated.<\/p>\n
Now we have the wp-config.php file, and we can proceed with installing WordPress. Let’s run this command to install it, you can modify the information in the command below before running it.<\/p>\n
# sudo -u www-data wp core install --url=https:\/\/wordpress.example.com\/ --title=\"New WordPress Website\" --admin_name=wrdpadmin --admin_password=m0d1fyth15 --admin_email=you@yourdomain.com<\/pre>\nYou will see a successful message like this:<\/p>\n
Success: WordPress installed successfully.<\/pre>\nThat’s it. You have successfully installed WordPress<\/a> at https:\/\/wordpress.example.com\/ and you can open it using any web browser you like, then build and customize it.<\/p>\n
If you are one of our web hosting customers and use our managed Linux Hosting, you don\u2019t have to follow this tutorial and install WordPress on Ubuntu 22.04<\/a> yourself, our Linux admins will set up and configure a WordPress VPS for you. They are available 24\u00d77 and will take care of your request immediately, and all you need to do is to submit a ticket.<\/p>\n