How to Install WordPress on Ubuntu Server

This article will discuss how to install WordPress on an Ubuntu server on your VPS or dedicated server without using an admin panel like cPanel, Plesk, CyberPanel, and so on.

Requirements for Installing WordPress on Ubuntu

  • VPS or dedicated server with Ubuntu 20.04 LTS or Ubuntu 18.04 LTS OS
  • VPS with at least 512MB RAM and 10GB of disk space
  • Internet connection
  • Basic understanding of how to connect to a VPS using SSH

How to Install WordPress on Ubuntu Server

Example in this tutorial:

  • IP: 206.189.86.154
  • Domain: ubuntu.nasikin.my.id
  • OS: Ubuntu 18.04 LTS x64

*The example website will be shut down, so it cannot be checked after this article is created.

1. SSH Login

The first step you need to take is to log in to your SSH first using the PuTTY application (the method used in this tutorial) or directly using CMD with the following command:

ssh root@ip_server_kalian

2. Install PHP and Apache

Next, to run scripts and display them, you need to install PHP and Apache on your server. To install PHP and Apache, you can copy the code below, then press Enter.

sudo apt updatesudo 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
Cara Install WordPress di Ubuntu Server

After you run the command and the Yes or No option appears, simply use the Yes option by typing Y, then press Enter.

Cara Install WordPress di Ubuntu Server

Next, wait for the process to finish before moving on to the next step.

3. Install WordPress

After the PHP and Apache installation process is complete, you can then install WordPress on your server using the following command:

sudo mkdir -p /srv/wwwsudo chown www-data: /srv/wwwcurl https://wordpress.org/latest.tar.gz | sudo -u www-data tar zx -C /srv/www
Cara Install WordPress di Ubuntu Server

Note: If you want to install multiple WordPress sites in the /srv/www folder, it is recommended to change the file permissions on the file wp-config.php to read-only (chmod 400)

4. Configure Apache for WordPress

Next, you need to configure Apache so it can connect to the WordPress you just installed. To do this, first you need to create a file wordpress.conf using the following command

nano /etc/apache2/sites-available/wordpress.conf

After you use that command, fill the file wordpress.conf with the following data

<VirtualHost *:80>    DocumentRoot /srv/www/wordpress    <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>

After the data is added, press CTRL+X or Command+X to close the text editor, then when there is a warning about the file name to be used, just click enter.

Cara Install WordPress di Ubuntu Server

Next, you need to activate or turn on the website, URL Rewrite, and turn off the "It Works" message (the default Apache page).

Use the following command to turn on the website

sudo a2ensite wordpress

Then use the command below to activate the URL Rewrite feature

sudo a2enmod rewrite

Next, turn off the "It Works" message using the following command

sudo a2dissite 000-default

If all three features have been adjusted, then you need to restart Apache using this command

sudo service apache2 reload
Cara Install WordPress di Ubuntu Server

5. Create a Database

For WordPress to run, you certainly need a database, and here we will use a MySQL database.

First, open the database that was installed along with the Apache and PHP installation earlier using this command

sudo mysql -u root
Cara Install WordPress di Ubuntu Server

Next, you need to create a database that will be used to store data. For example, here I will create a database named nasikin

mysql> CREATE DATABASE nasikin;

You do not need to enter mysql> into the command, just start from CREATE

After the database is created, you need to add a user to manage all the data in that database. Here, as an example, I am creating a user nasikin_user using the password nasikindb4ps

mysql> CREATE USER nasikin_user@localhost IDENTIFIED BY 'nasikindb4ps';
Cara Install WordPress di Ubuntu Server

After the database and password have been successfully created, you need to grant access rights to that user to manage the database that will be used. To do this, you can use the following command

mysql> GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP,ALTER       ON nasikin.*       TO nasikin_user@localhost;

After the access rights are added, you need to perform Flush Privileges so that the user truly has access rights to the data.

mysql> FLUSH PRIVILEGES;

Because the access rights have been flushed, you can now exit the MySQL page using the following command:

mysql> quit

6. Connect WordPress to the Database

After all the setup is complete, you only need to connect WordPress to the database before the website can be visited online.

First, you can copy the default file wp-config.php using the following command

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

Next, add the database login details to the file wp-config.php using this command

sudo -u www-data sed -i 's/database_name_here/nasikin/' /srv/www/wordpress/wp-config.phpsudo -u www-data sed -i 's/username_here/nasikin_user/' /srv/www/wordpress/wp-config.phpsudo -u www-data sed -i 's/password_here/nasikindb4ps/' /srv/www/wordpress/wp-config.php

Do not change database_name_here, username_here, password_here. You only need to change nasikin, nasikin_user, nasikindb4ps and adjust it to your database

Cara Install WordPress di Ubuntu Server

The last step before your WordPress can run is to edit your wp-config file and delete some code. To edit the wp-config file, you can use the following command

sudo -u www-data nano /srv/www/wordpress/wp-config.php

Make sure your database settings are correct, then delete the code below

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' );

To delete quickly, you can use the shortcut CTRL+K to immediately delete one line of code.
To save the code, use the shortcut CTRL+X and Enter

Cara Install WordPress di Ubuntu Server
Cara Install WordPress di Ubuntu Server

7. Configure WordPress

Now your WordPress can be visited, but it has not been configured yet. To start the configuration, open your web browser and visit the address http://206.189.86.154 (Change the IP according to your server's IP).

Cara Install WordPress di Ubuntu Server

After the configuration is complete, you need to point your domain to that IP so that the website can be visited more easily and the address is easy to remember. To do this, open your DNS Manager or Zone Editor and change the A Record for the domain used and the www domain so that it becomes like this:

ubuntu.nasikin.my.id    A   206.189.86.154www.ubuntu.nasikin.my.id    A   206.189.86.154
Cara Install WordPress di Ubuntu Server
Cara Install WordPress di Ubuntu Server

Once you have changed the DNS on the domain, you can now log in to your WordPress using the address http://206.189.86.154/wp-admin or http://206.189.86.154/wp-login.php

After logging into WordPress, open the Settings > General page > Change WordPress Address (URL) and Site Address (URL) to your domain name.

Cara Install WordPress di Ubuntu Server
Cara Install WordPress di Ubuntu Server

Now your WordPress website can be accessed using the domain, and without needing to install an admin panel.

Cara Install WordPress di Ubuntu Server

Written by

Muhammad Khoirun Nasikin

I enjoy tinkering with WordPress, hosting, VPS, web development, and various small experiments related to websites. I have over 3 years of experience in the web hosting industry.

COMMENTS

Loading...