This article is explaining how to install WordPress on Ubuntu OS without visual help from Cpanel or similar tools allowing one-click installs. With Ubuntu server access only via terminal, we need to use few Linux commands to make this happen.
WordPress Version: 5.4.2
OS Version: Ubuntu Os 18.04.3 (LTS) x64
MariaDB Version: 10.1.44
We’ll touch base with every step and every command so you can always get back to anything causing you trouble in the process. For the very start, let’s list out the bare minimum of access we should have in order to access the Linux server:
- An IP address (or hostname/domain)
- Username
- Password or ssh key
To make this easier we’ll breakdown the process into following subheadings: login to the server, prepare pre-installation requirements, download and install WordPress, and configure WordPress. Here we go!
Login to the server
With the above login details, we can access the Ubuntu server with the following command if we have a username (or domain), IP address, and password:
ssh username@ip-address(or domain)
Examples:
Or
If, however, instead of the password we have ssh key the login should look like this:
ssh username@ip-address(or domain)
Examples:
ssh [email protected] -i /path/to/the/ssh-key
Or
ssh [email protected] -i /path/to/the/ssh-key
Pre-installation requirement
When logged in to the server, we need to make sure that the operating system is up to date, PHP is installed, the database server is installed and all required services up and running.
Update operating system:
bluegrid-edu:~# apt-get update
Install Apache Webserver
bluegrid-edu:~# apt-get install apache2
Enable .htaccess override:
Open /etc/apache2/apache2.conf
and change AllowOverride None
to AllowOverride All
:
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
Create .htaccess
file in the document root directory (/var/www/html/
) and add the following line in it:
DirectoryIndex index.php
Install “upzip” using the following command:
bluegrid-edu:~# apt-get install unzip
Install PHP and apache PHP library:
Execute the following command to install PHP and necessary PHP library for apache:
bluegrid-edu:~# apt install php libapache2-mod-php
Install MySQL extension for PHP:
bluegrid-edu:~# apt-get install php-mysql
Restart apache2:
bluegrid-edu:~# systemctl restart apache2
Install Mariadb database Server:
bluegrid-edu:~# apt-get install mariadb-server
Create a database and database user:
- Login to MariaDB database server:
bluegrid-edu:~# mysql
- Create a database:
MariaDB [(none)]> create database wpdatabase;
- Create a database user:
MariaDB [(none)]> create user [email protected] identified by 'wppassword';
- Grant privileges to this user on the newly created database:
MariaDB [(none)]> grant all on wpdatabase.* to [email protected];
- Reload privileges:
MariaDB [(none)]> grant all on wpdatabase.* to [email protected];
Download the latest WordPress installation:
Use the URL https://wordpress.org/latest.zip
in the curl
command to download the latest WordPress installation:
bluegrid-edu:~# curl https://wordpress.org/latest.zip -o /var/www/html/latest.zip
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 12.6M 100 12.6M 0 0 9369k 0 0:00:01 0:00:01 --:--:-- 9369k
Change location to /var/www/html/
using the following command:
bluegrid-edu:~# cd /var/www/html/
Unpack the latest.zip
file using the following command:
bluegrid-edu:/var/www/html# unzip latest.zip
Now the WordPress files are placed in the /var/www/html/wordpress/
directory and we need them moved out of the wordpress
directory using the following command:
bluegrid-edu:/var/www/html# mv -f wordpress/* ./
Configure WordPress
Now we should be able to open the domain or the IP address of the server in the browser and the following screen should appear. In our case, we used the following domain http://test.bluegrid.io/
and below is the screen from it:
This looks good! Let’s continue. Hitting the “Let’s go!” button we open next form where the WordPress database details are asked:
Note: If you happen to get an exception like this:
There are two ways to fix this:
- You can manually create the
wp-config.php
file using the following command and paste copied content WordPress offered in above screen:
bluegrid-edu:/var/www/html# nano wp-config.php
When the wp-config.php
is saved we can proceed with installation by hitting the “Run the installation” button.
Or you can change the ownership on the document root directory in two steps:
Step #1: Find out apache user it runs as:
bluegrid-edu:/var/www/html# ps aux | egrep '(apache|httpd)'
Step #2: Apply new changes on the document root directory:
bluegrid-edu:/var/www/html# chown -R www-data:www-data /var/www/html/
When permissions are changed we can reload the current page and the following will appear:
We can proceed now by hitting the “Run the installation”.
The installation will stop on the following screen – Website details:
When “Install WordPress” is pressed WordPress will install and login form will pop up:
We are in! WordPress is installed and we are in the admin area. We can begin administering WordPress from this point.
Related article: How to manually migrate a WordPress Website