jharttech logo
How to set up WordPress on top of Ubuntu 18 using Command Line

How to set up WordPress on top of Ubuntu 18 Using Command Line

How To


Setting up WordPress on your local Ubuntu 18.x Machine with Apache2

This tutorial is designed to help with the installation of WordPress on top of Ubunut 18.x


NOTE: This tutorial will not be covering how to install LAMP/LEMP and will be using Apache2 instead.


1. The first thing we need to do is to update our Ubuntu and then install the needed packages. To do this use the following commands in your terminal:


$ sudo apt update
$ sudo apt install php php-curl php-gd php-mbstring php-xml php-xmlrpc mysql-server php-mysql

2. Next, we need to create the database. Unless you created a database specifically for WordPress during a LAMP/LEMP setup, you are going to need to create a new one for WordPress to use.

Sign into MySQL as your root database user. Use the following command to log into mysql as root for the first time:
NOTE: This next step is for first time mysql use, if you have mysql set up already then just log into mysql as your root user and password as normal.

$ sudo mysql -u root

3. Once you are into your mysql console, create a new database for use with WordPress:

$ mysql> CREATE DATABASE wordpress;

4. Create a new user for use with the new database:
NOTE: CHANGE *yourpass* TO YOUR DESIRED DATABASE PASSWORD!

$ mysql> CREATE USER `wp_admin`@`localhost` IDENTIFIED BY 'yourpass';

5. The next step is to grant our new database user the needed permissions to manage the database. Use the following command in your mysql console to do this:

$ mysql> GRANT ALL ON wordpress.* TO `wp_admin`@`localhost`;

6. Now we need to flush the database privileges and exit the mysql console:

$ mysql> FLUSH PRIVILEGES;
$ mysql> exit

7. We will now install Apache2 and a one more needed apache2/PHP package:

$ sudo apt install apache2 libapache2-mod-php

8. Install WordPress to your Ubuntu machine. To do this we will first change directory into your home directory, then we will download the latest version of WordPress. Next, we will cd into your web server file location (usually /var/www with apache), then we will extract the files:

$ cd
$ wget https://wordpress.org/latest.tar.gz
$ cd /var/www/html
$ sudo tar xpf ~/latest.tar

9. Now we will change the permissions of the newly extracted and created wordpress directory so that wordpress will have the correct access needed and be in the correct group:

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

10. The next step is to Configure your Apache2 webserver configuration for your wordpress site.

$ sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/wordpress.conf

11. Now open your new configuration file named "wordpress". To do this I use 'vim' text editor, but you may use nano or any editor that you prefer, just replace 'vim' in the following command to your editor:

$ sudo vim /etc/apache2/sites-available/wordpress.conf

Make the needed adjustments to your config file so that it looks similar to the following example:


  <VirtualHost *:80>
      # The ServerName directive sets the request scheme, hostname and port that
      # the server uses to identify itself. This is used when creating
      # redirection URLs. In the context of virtual hosts, the ServerName
      # specifies what hostname must appear in the request's Host: header to
      # match this virtual host. For the default virtual host (this file) this
      # value is not decisive as it is used as a last resort host regardless.
      # However, you must set it for any further virtual host explicitly.
      #ServerName www.example.com
       
        ServerAdmin webmaster@localhost
	DocumentRoot /var/www/html/wordpress
       
        <Directory>
            Options +FollowSymlinks
            AllowOverride All
            Require all granted
        </Directory>
         
        # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
        # error, crit, alert, emerg.
        # It is also possible to configure the loglevel for particular
        # modules, e.g.
        #LogLevel info ssl:warn
       
	    ErrorLog ${APACHE_LOG_DIR}/error.log
	    CustomLog ${APACHE_LOG_DIR}/access.log combined
       
      # For most configuration files from conf-available/, which are
      # enabled or disabled at a global level, it is possible to
      # include a line for only one particular virtual host. For example the
      # following line enables the CGI configuration for this host only
      # after it has been globally disabled with "a2disconf".
      #Include conf-available/serve-cgi-bin.conf
</VirtualHost>

NOTE: This setup is for using the localhost only, you may need to make further adjustments for sites using a ServerName.
When you are done adjusting your config file save and exit your file.

12. Now "turn on" your site and reload apache2 by running:

$ sudo a2ensite wordpress.conf
$ sudo systemctl reload apache2

13. Finally adjust your WordPress configurations and start using your new wordpress site. The areas that need edited in the wp-config.php file at this time is the 'dbname', 'db username', and 'db pass'. I also recommend changing the Authentication and Unique Keys and Salts which are towards the bottom of the config file (I do not show these in the example below):

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

NOTE: I will show an example of the wp-config.php file with the needed changes for this tutorial:

...
// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'wordpress'); #change the value in the second set of quotes to your database name
 
/** MySQL database username */
define('DB_USER', 'wp_admin'); #change the value in the second set of quotes to your db user
 
/** MySQL database password */
define('DB_PASSWORD', 'password'); #change the value in the second set of quotes to your db password
...

Finally, you now have wordpress installed on your local Ubunut 18.x machine and can see your new local website by going to ://localhost/wordpress/ . To log into your new wordpress dashboard and learn the basics of using wordpress to design your site go to ://localhost/wordpress/wp-admin.php


I will make another tutorial on how to get your wordpress site set up on an amazon web server at a later time.


IN NO EVENT WILL WE BE LIABLE FOR ANY DIRECT, INDIRECT, CONSEQUENTIAL, INCIDENTAL, SPECIAL OR EXEMPLARY DAMAGES FOR ANY USE OF THIS SITE, OR USE OF ANY OTHER LINKED SITE, OR SOFTWARE, EVEN IF WE ARE ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.

With over 10 years of experience in the Technology field, I have solved my fair share of technical issues and problems.u00a0

Leave a Reply

Close Menu