{{announcement.body}}
{{announcement.title}}

Install Wordpress on Ubuntu 18.04

DZone 's Guide to

Install Wordpress on Ubuntu 18.04

Here at DZone, we love coder and bloggers. So what could make a better post for use than installing WordPress on Ubuntu? Read on to get started!

· Web Dev Zone ·
Free Resource

In this post, we will install WordPress on Ubuntu 18.04. The WordPress content management system is the leading platform for deploying websites today.

Over 31% of all websites use WordPress today.

WordPress is awesome because it lets you update websites using the WYSIWYG interface.

It is highly customizable through WordPress Themes and WordPress Plugins.

WordPress can be used for any type of website including:

  • Blogs
  • eCommerce
  • Professional Portfolios
  • More

In this post, we will install WordPress on Ubuntu Server 18.04.

Getting Started

We will begin with a fresh install of Ubuntu Server 18.04.

First, install all the updates and reboot.

apt update && apt upgrade -y
reboot

After the servers come back up we need to install a LAMP stack.

WordPress is a PHP-based application.

apt install apache2 mysql-server php -y

In order to install WordPress, we need to install a few PHP modules.

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

Next, we need to secure a MySQL server.

mysql_secure_installation

This script will ask you several questions.

The first question will ask you to install the Validate Password Plugin.

VALIDATE PASSWORD PLUGIN can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD plugin?

Press y|Y for Yes, any other key for No: N

I typically answer No to this question because I know my password is secure. You can answer Yes if you like here.

Next, the script will ask you to set a new password for the root MySQL user.

New password:

Re-enter new password:

The script will now ask you to remove anonymous users. Answer yes.

By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y

Next, it will ask you if you want to disallow root login remotely. We should always answer yes to this.

Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : Y

It will ask you to remove the test database and access to it. Answer yes.

By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.

Remove test database and access to it? (Press y|Y for Yes, any other key for No) : Y

Next, it will ask you to reload the privilege tables. Answer yes.

Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y

Finally, the script completes.

We are now ready to install WordPress.

Install WordPress on Ubuntu 18.04

To install WordPress, we need to create a database for WordPress, configure Apache2 and download the WordPress PHP application.

Create the Database

Now we need to create the database that WordPress will use.

First, log in to MySQL using the password we created earlier.

mysql -u root -p

Then, create the WordPress database with this command.

CREATE DATABASE wordpress DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;

Next, we need to create the WordPress user.

GRANT ALL ON wordpress.* TO 'wordpress'@'localhost' IDENTIFIED BY 'password';

Make sure to replace the password above with a more secure option.

Run the next command to make our changes take effect.

flush privileges;

Finally, exit.

exit;

Next, we will set up Apache to run WordPress.

Configure Apache2

First, we need to allow the use of an .htaccess file.

Open your favorite editor and load the /etc/apache2/sites-available/000-Default file.

Add the following snippet in between the VirtualHost tags.

<Directory /var/www/html>
        AllowOverride All
</Directory>

Save and exit.

Next, enable the rewrite module.

a2enmod rewite

Next, we need to tell Apache to serve PHP pages first.

Open the /etc/apache2/mods-enabled/dir.conf file and change it to have index.php listed first.

<IfModule mod_dir.c>
        DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm
</IfModule>

Restart Apache.

systemctl restart apache2

Downloading WordPress

Make sure you are in roots home directory.

cd ~

Run the following command to download the latest version of WordPress.

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

Untar the tarball.

tar -xzvf latest.tar.gz

Create an empty .htaccess file.

touch wordpress/.htaccess

Create a directory for WordPress to use for upgrades.

mkdir wordpress/upgrade

Copy everything to Apaches HTML directory.

cp -a wordpress/. /var/www/html

Next, we need to change the ownership of the WordPress files to the Apache service.

chown -R www-data:www-data /var/www/html

Now we need to fix the permissions.

find /var/www/html/ -type d -exec chmod 750 {} \;
find /var/www/html/ -type f -exec chmod 640 {} \;

Next, we need to configure WordPress

Configuring WordPress

Copy the configuration file with this command.

cp /var/www/html/wp-config-sample.php /var/www/html/wp-config.php

Run the following command.

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

This will give us several define lines.

Copy these lines and open the /var/www/html/wp-config.php file.

Scroll down where the sample defines are:

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

And change them to the defines you copied.

Next, scroll up to the database settings.

define('DB_NAME', 'database_name_here');

/** MySQL database username */
define('DB_USER', 'username_here');

/** MySQL database password */
define('DB_PASSWORD', 'password_here');

Change the settings to match the database information from earlier.

define('DB_NAME', 'wordpress');

/** MySQL database username */
define('DB_USER', 'wordpress');

/** MySQL database password */
define('DB_PASSWORD', 'password');

Save and exit.

Completing the Installation

Browse to the following URL to finish installing WordPress.

http://{your_server}

You should see the language selection screen.

Select your language and click on the Continue button.

Next fill in your web site's details.

After you enter all your information click on the Install WordPress button.

You can now log in and start using your new WordPress site.

Conclusion

In this article, we learned how to install WordPress on Ubuntu 18.04.

If you enjoyed this article then please share it and comment below.

Topics:
web dev ,wordpress ,ubuntu ,tutorial

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}