Install WordPress 4.7 using Apache in Debian, Ubuntu and Linux Mint

Writing an Apache or WordPress introduction will do no good due to the fact that both of them, combined together, are one of the most used Open Source platforms in Internet today, in fact...

Spread the love

Writing an Apache or WordPress introduction will do no good due to the fact that both of them, combined together, are one of the most used Open Source platforms in Internet today, in fact Apache runs on 46.41% world web servers and WordPress on one of every 6 websites – Apache with MYSQL and PHP providing the dynamic server gateway interface for WordPress Publishing Content Management.

This topic explains the steps needed to be processed in order to install latest version of WordPress on top of LAMP, which stands for Linux, Apache, MySQL/MariaDB, PHP and PhpMyAdmin on Debian, Ubuntu and Linux Mint, with basic Apache Virtual Host configurations and MySQL database access through CLI or PhpMyAdmin Web Interface, but be aware that does not cover other important network service configurations, like an IP name mapping provided by DNS server and simply uses the rudimentary system hosts file for IP name transactions (DNS query).

Suggested Read: How to Install WordPress Using Apache or Nginx on RHEL/CentOS/Fedora

Also the forward settings are available on almost all Debian systems with slight differences (most of them regarding apache paths), which will be noted on proper time.

Step 1: Server Basic Configurations

1. First of all, due to fact that there’s no authoritative DNS server on network, and for this setup Apache Virtual Host is used. We need to map server IP to our virtual (fake) domain name to be able to access it like a real domain name from any browser.


To complete this job open and edit ‘/etc/hosts‘ on local server and your preferred domain name on “127.0.0.1 localhost” line end. In my case, I’ve taken domain name as ‘wordpress.lan‘.

$ sudo nano /etc/hosts
Setup Local Domain

Setup Local Domain

After your record has been added you can test it by issuing a ping command on your new domain name.

$ ping wordpress.lan
Resolve Local Domain

Resolve Local Domain

2. If your server is designed for production and runs only from command line ( and it should ) and you need to access WordPress domain from a Windows station somewhere on your network then open and modify with notepad that Windows hosts file located on ‘C:\Windows\System32\drivers\etc‘ path and on last line add your Apache Server LAMP IP and your virtual domain name.

Add Hostname in Host File

Add Hostname in Host File

Again issue a ping command line against your WordPress domain name and the server should response back.

3. Now it’s time to install LAMP stack, here are the instructions to do so in all Ubuntu versions and its major distribution families:

  1. Instal LAMP in Ubuntu 14.04
  2. Instal LAMP in Ubuntu 14.10
  3. Instal LAMP in Ubuntu 15.04
  4. Instal LAMP in Ubuntu 15.10
  5. Instal LAMP in Ubuntu 16.04
  6. Instal LAMP in Ubuntu 16.10

To verify that Apache, MySQL, PHP are installed run again a LAMP installation command line through ‘apt-get’ and accept installing missing packages if is the case.

------------------ On Ubuntu 14.04-14.10 ------------------ $ sudo apt-get install apache2 apache2-utils php5 php5-mysql mysql-client mysql-server
------------------ On Ubuntu 15.04-16.10 ------------------ $ sudo apt-get install apache2 apache2-utils php5 php5-mysql mariadb-client mariadb-server
Install LAMP Stack

Install LAMP Stack

4. If you are good with MySQL command line you can skip this step, else install PhpMyAdmin Web Interface.

A tool that can help you with administering MySQL databases. Run the following command line, select Apache web server and do not configure database for phpmyadmin with dbconfig-common.

$ sudo apt-get install phpmyadmin
Install PhpMyAdmin in Ubuntu

Install PhpMyAdmin

Choose Web Server

Choose Web Server

Configure Database for PhpMyAdmin

Configure Database for PhpMyAdmin

5. After PhpMyAdmin had been installed is time to make it accessible for web browsing and for that Apache web server needs to read its configurations file.

To enable PhpMyAdmin you must copy ‘apache.conf’ PhpMyAdmin configuration to ‘conf-available‘ Apache path and enable new configuration. For this, run the following series of commands on Ubuntu and Linux Mint systems.

$ sudo cp /etc/phpmyadmin/apache.conf /etc/apache2/conf-available/
$ sudo mv /etc/apache2/conf-available/apache.conf /etc/apache2/conf-available/phpmyadmin.conf
$ sudo a2enconf phpmyadmin

On Debian systems, issue the following commands.

$ sudo cp /etc/phpmyadmin/apache.conf /etc/apache2/conf.d/
$ sudo mv /etc/apache2/conf.d/apache.conf /etc/apache2/conf.d/phpmyadmin.conf
Copy PhpMyAdmin Configuration

Copy PhpMyAdmin Configuration

Enable Configuration for PhpMyAdmin

Enable Configuration for PhpMyAdmin

6. The next step is to create a Virtual Host on Apache web server that will host WordPress new domain. To create and activate a new Virtual Host, open a text editor and create a new file named, suggestive, ‘wordpress.conf‘ on ‘/etc/apache2/sites-available/‘ path by running the following command.

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

Add the following directives at the bottom of the file. Save and Close the file.

<VirtualHost *:80>
ServerName wordpress.lan
ServerAdmin [email protected]
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Create WordPress Virtual Host

Create WordPress Virtual Host

Then activate the new virtual host with this command.

$ sudo a2ensite wordpress.conf
$ sudo service apache2 restart
Active WordPress Virtual Host

Active WordPress Virtual Host

7. To avoid that future Apache error concerning, ServerName FQDN missing open main configuration file ‘/etc/apache2/apache2.conf‘, add the following line at the bottom of file and restart service.

ServerName wordpress.lan
Add ServerName FQDN

Add ServerName FQDN

$ sudo service apache2 restart
Restart Apache Service

Restart Apache Service

Step 2: Create WordPress Database

8. Now is time to create a new database and a new database user for WordPress. There are two ways of doing this, either though MySQL command line, which is also the most secure way, or by using PhpMyAdmin web tool. On this topic both methods will be covered.

But first of all, if you cannot access MySQL database with root account on both CLI and Web, run the following command and setup a password for MySQL root account.

Connect to MySQL

Connect to MySQL

$ sudo dpkg-reconfigure mysql-server-5.6
OR
$ sudo dpkg-reconfigure mysql-server-5.5
Configure MySQL Server

Configure MySQL Server

Confirm MySQL Password

Confirm MySQL Password

After Debian dpkg utility reconfigures MySQL Server Database, run the following command and answer YES on all questions to harden your SQL database security settings.

$ sudo mysql_secure_installation
Secure MySQL Server

Secure MySQL Server

Now is time to actually create WordPress database.

Using PhpMyAdmin

Point your browser to your server IP or virtual domain name and login to PhpMyAdmin using root account.

Login to PhpMyAdmin

Login to PhpMyAdmin

Once connected navigate to Databases tab, enter a name for your database and hit on Create button.

Create MySQL Database

Create MySQL Database

On left panel select your newly created database ( wordpress), than go to Privileges tab.

Grant Privileges to User

Grant Privileges to User

Here, click on Add user, enter the below values, then hit on Go.

  1. Username = your_database_user
  2. Host = localhost
  3. Password = a_strong_password_twice
  4. Database for user: select Grant all Privileges on database “wordpress”
  5. Global privileges: click on Check All
Add New MySQL User

Add New MySQL User

Enter User Details

Enter User Details

Grant All Rights for User

Grant All Rights for User

That’s all for creating and setting WordPress database and user through PhpMyAdmin. After the successfully message about your newly added user exit MySQL database.

Using Command Line

Connect to MySQL database and issue the following commands as root user.

# mysql -u root -p
mysql> CREATE DATABASE IF NOT EXISTS wordpress;
mysql> CREATE USER [email protected] IDENTIFIED BY "your_password_here";
mysql> GRANT ALL PRIVILEGES ON wordpress.* TO [email protected];
mysql> FLUSH PRIVILEGES;
mysql> quit

Step 3: Download and Install WordPress

9. After all Apache nasty server configurations had been made and MySQL database and administrative user had been created it’s now time to actually perform WordPress installation on our box.

First of all download latest WordPress archive by issuing the following command.

$ wget http://wordpress.org/latest.tar.gz
Download WordPress

Download WordPress

10. Next extract WordPress archive and copy all extracted files to Apache Virtual Host DocumentRoot, that will be ‘/var/www/html‘ on Ubuntu and Linux Mint systems.

$ sudo tar xvzf latest.tar.gz
$ sudo cp -r wordpress/* /var/www/html

On Debian systems, run the following commands.

$ sudo tar xvzf latest.tar.gz
$ sudo mkdir -p /var/www/html
$ sudo cp -r wordpress/* /var/www/html

11. Before starting WordPress installer make sure that Apache and MySQL services are running and also run the following commands to avoid ‘wp-config.php‘ error file creation – we will revert changes afterward.

$ sudo service apache2 restart
$ sudo service mysql restart
$ sudo chown -R www-data /var/www/html
$ sudo chmod -R 755 /var/www/html
Confirm Apache and MySQL Services

Confirm Apache and MySQL Services

12. Open a browser and enter your server’s IP or virtual domain name on URL using http protocol.

http://wordpress.lan/index.php
http://your_server_IP/index.php

13. On first prompt hit on Create a Configuration file -> Let’s go.

Create WP Configuration

Create WP Configuration

Proceed WordPress Installation

Proceed WordPress Installation

14. On next screen enter your MySQL wordpress database name, user, password and host, then hit on Submit.

Enter WordPress Database Details

Enter WordPress Database Details

15. After the installer successfully connects to MySQL database and completes ‘wp-config.php‘ file creation hit ‘Run‘ the install button and provide WordPress installer with a Site Title, an administrative username and password for your blog, email address and finally click on Install WordPress.

WordPress Installation

WordPress Installation

Enter WordPress Site Details

Enter WordPress Site Details

16. After the installation completes you can login to your newly WordPress website blog using your administrative credentials and start customize your blog from Dashboard or add new cool articles for millions of readers world-wide or just you!

WordPress Installation Success

WordPress Installation Success

Login into WordPress Dashboard

Login into WordPress Dashboard

17. One more last step is to revert changes made on ‘/var/www/html‘ directory and file permissions.

$ sudo chown -R root /var/www/html

That’s all the steps needed for a complete WordPress installation on Debian, Ubuntu, Linux Mint and most of all Debian based Linux distributions using Apache web server, but still this subject is so vast that only the basic part has been covered. For a complete environment you will also need to install and setup a DNS server, enable complex Apache ‘.htacccess‘ rules and, if security demands it, enforce SSL on Web server.

Facebook Comments
Spread the love

Posted by News Monkey