• Skip to primary navigation
  • Skip to main content

Magda Sicknick

  • About me
  • Articles
  • Portfolio

Setting up WordPress on Ubuntu

Step 1: Get the latest Ubuntu updates

Run the following command to get the latest updates/patches:

  • sudo apt-get update

Step 2: Install Apache Web Server

To install Apache web server, type the following command:

  • sudo apt-get install apache2 apache2-utils

Next, enable the service to start at boot time, as well as start the service:

  • sudo systemctl enable apache2
  • sudo systemctl start apache2

To test whether the server is running, open your web browser and enter http://server_address. The Apache2 default index page will be displayed in case the web server is up and running.

Note: The Apache default root directory is /var/www/html, all your web files will be stored in this directory.

Step 3: Install MySQL Database Server

Next, we need to install MySQL database server with the following command:

  • sudo apt-get install mysql-client mysql-server

During the installation, you will be asked to set the root user password for mysql as shown below. Choose a secure password and hit the OK button twice to proceed.

The database server deployment is not yet secure, for this reason, issue the following command to harden it’s security:

  • sudo mysql_secure_installation

You will be asked to install the ‘validate_password’ plugin, so type in Y/Yes and press Enter and choose the default password strength level.

If you do not want to change the root password, then type N/No when prompted to do so. Answer Y/Yes for the rest of the subsequent questions.

Step 4: Install PHP

PHP 7.0

To install PHP 7.0 and all the necessary modules to work with the web and database servers, run the following command:

$ sudo apt-get install php7.0 php7.0-mysql libapache2-mod-php7.0 php7.0-cli php7.0-cgi php7.0-gd  
PHP 7.3

We will use the Ondřej Surý’s PPA to install PHP 7.3 version, so install the software-properties-common and python-software-properties packages:

  • sudo apt install software-properties-common python-software-properties

After the installation is complete, add the Ondřej PPA:

  • LC_ALL=C.UTF-8 add-apt-repository ppa:ondrej/php

and then update your sources:

  • sudo apt update

We can install PHP 7.3 with the following command:

  • sudo apt install php7.3 php7.3-cli php7.3-common

To check if PHP 7.3 is installed on your server, use the command below:

  • php -v

If you want to install a specific module for PHP 7.3, you can search with this command:

  • apt-cache search php7.3

Or, if you want to check all the PHP modules available in Ubuntu, run:

  • apt-cache search –names-only ^php

You can find the command below useful if you want to install the most frequently used PHP modules.

  • sudo apt install php-pear php7.3-curl php7.3-dev php7.3-gd php7.3-mbstring php7.3-zip php7.3-mysql php7.3-xml php7.3-fpm libapache2-mod-php7.3 php7.3-imagick php7.3-recode php7.3-tidy php7.3-xmlrpc php7.3-intl

To set PHP 7.0 as the default, run:

  • sudo update-alternatives –set php /usr/bin/php7.0

To set PHP 7.2 as the default, run:

  • sudo update-alternatives –set php /usr/bin/php7.2

To set PHP 7.3 as the default, run:

  • sudo update-alternatives –set php /usr/bin/php7.3

Before we can configure Apache to use PHP 7.3, we need to disable the old version of PHP 7.0 by typing:

  • sudo a2dismod php7.0

Now enable the newly installed PHP 7.3 version with the following command:

  • sudo a2enmod php7.3

Restart the Apache web server for the changes to take effect:

  • sudo systemctl restart apache2

To test your PHP installation, create a info.php file inside the /var/www/html directory with the following commands:

$ sudo nano /var/www/html/info.php

And paste the code below into the file

<?php 
    phpinfo();
?>

Note: To save and exit, press CTRL+X, confirm with a Y/y, and hit Enter to save.

You should then be able to navigate to http://server_address/info.php and see a page like the one below for successful confirmation of your PHP installation.

Step 4: Install phpMyAdmin

phpMyAdmin is the most common

$ sudo apt-get install phpmyadmin php-mbstring php-gettext

This will ask you a few questions in order to configure your installation correctly.

Warning: When the first prompt appears, apache2 is highlighted, but not selected. If you do not hit Space to select Apache, the installer will not move the necessary files during installation. Hit Space, Tab, and then Enter to select Apache.

For the server selection, choose apache2.
Select yes when asked whether to use dbconfig-common to set up the database
You will be prompted for your database administrator’s password
You will then be asked to choose and confirm a password for the phpMyAdmin application itself
The installation process actually adds the phpMyAdmin Apache configuration file into the /etc/apache2/conf-enabled/ directory, where it is automatically read.

The only thing we need to do is explicitly enable the PHP mcrypt and mbstring extensions, which we can do by typing:

$ sudo phpenmod mcrypt
$ sudo phpenmod mbstring

Afterwards, you’ll need to restart Apache for your changes to be recognized:

$ sudo systemctl restart apache2

You can now access the web interface by visiting http://server_address/phpmyadmin

Step 5: Install WordPress CMS

Download the latest WordPress package and extract it by issuing the commands below on the terminal:

$ wget -c http://wordpress.org/latest.tar.gz
$ tar -xzvf latest.tar.gz

Then move the WordPress files from the extracted folder to the Apache default root directory, /var/www/html/:

$ sudo rsync -av wordpress/* /var/www/html/

Next, set the correct permissions on the website directory, that is give ownership of the WordPress files to the web server as follows:

$ sudo chown -R www-data:www-data /var/www/html/
$ sudo chmod -R 755 /var/www/html/

Step 6: Create WordPress Database

Execute the command below and provide the root user password, then hit Enter to move to the mysql shell:

$ mysql -u root -p 

You will be prompted to enter the password you created for the MySQL installation in Step 3.

At the mysql shell, type the following commands, pressing Enter after each line of a mysql command. Remember to use your own, valid values for database_name, database_user, and also use a strong and secure password as databaseuser_password:

mysql> CREATE DATABASE database_name;
mysql> GRANT ALL PRIVILEGES ON database_name.* TO 'database_user'@'localhost' IDENTIFIED BY 'databaseuser_password';
mysql> FLUSH PRIVILEGES;
mysql> EXIT;

Next, go the /var/www/html/ directory and rename existing wp-config-sample.php to wp-config.php with the following command:

$ sudo mv /var/www/html/wp-config-sample.php /var/www/html/wp-config.php

Open the file for editing:

$ sudo nano /var/www/html/wp-config.php

and update the file with your database information under the MySQL settings section in the highlighted spots:

// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'database_name_here'); /** MySQL database username */ define('DB_USER', 'username_here'); /** MySQL database password */ define('DB_PASSWORD', 'password_here'); /** MySQL hostname */ define('DB_HOST', 'localhost'); /** Database Charset to use in creating database tables. */ define('DB_CHARSET', 'utf8'); /** The Database Collate type. Don't change this if in doubt. */ define('DB_COLLATE', '');

Note: To save and exit, press CTRL+X, confirm with a Y/y, and hit Enter to save.

Afterwards, restart the web server and mysql service using the commands below:

$ sudo systemctl restart apache2.service 
$ sudo systemctl restart mysql.service

Open your web browser, then enter your server address: http://server-address to get the WordPress welcome page. Fill all requested on screen information, starting with your choice of language.

Step 7: Enable HTTPS and add an SSL Certificate

Note: Make sure you have HTTPS port 443 enabled in your hosts firewall. [Instructions here]

On Ubuntu systems, the Certbot team maintains a PPA. Once you add it to your list of repositories all you’ll need to do is apt-get the following packages.

$ sudo apt-get update
$ sudo apt-get install software-properties-common
$ sudo add-apt-repository ppa:certbot/certbot
$ sudo apt-get update
$ sudo apt-get install python-certbot-apache 

Certbot has a fairly solid beta-quality Apache plugin, which is supported on many platforms, and automates certificate installation.

$ sudo certbot --apache

The Certbot packages on your system come with a cron job that will renew your certificates automatically before they expire. Since Let’s Encrypt certificates last for 90 days, it’s highly advisable to take advantage of this feature. You can test automatic renewal for your certificates by running this command:

$ sudo certbot renew --dry-run
I hope this tutorial was helpful.

Published on April 8, 2018

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Let’s Talk

Looking to get your business a website or update your current online presence?

Please send me information about you project so that I can determine how to best fulfill your needs.

    Service Required *

    Copyright© 2023 · Magda Sicknick · All Rights Reserved · Powered by Wordpress and the Genesis Framework.