UPDATED on JUNE 2018!
In this post we will install the well known WordPress on a linux machine. Worpress is the most popular Content Management System that allows you to create a flexible website with a small effort.

This guide requires a LAMP (Linux Apache MySQL and PHP) stack installed on you linux machine. You can follow the steps provided in how to set up a Lamp stack and go ahead.

Download wordpress

Download the archive from the official webpage

or execute in a terminal:

pi@webpi ~$ wget https://wordpress.org/latest.tar.gz

Now move and extract the compressed file in /var/www/ or /var/www/html with the following command:

pi@webpi ~$ sudo mv latest.tar.gz /var/www/ && cd /var/www
pi@webpi /var/www$ sudo tar xzvf latest.tar.gz
pi@webpi /var/www$ sudo mv wordpress/* .

Ok the installation is almost finished. Let’s configure MySQL to host a database for our website.

Create a MySQL database

Let’s login and create a database that will host all the tables required for wordpress to run. Insert your username and password, then create a new user, we will use wpuser, for the WordPress installation and grant the newly created access to the database. Finally flush the privileges and exit.

pi@webpi /var/www$ mysql -u RooT -p PassworD
mysql> CREATE DATABASE wordpress;
Query OK, 1 row affected (0.00 sec)

mysql> CREATE USER wpuser@localhost IDENTIFIED BY 'ziaFlora';
Query OK, 0 rows affected (0.00 sec)

mysql> GRANT ALL PRIVILEGES ON wordpress.* TO wpuser@localhost;
Query OK, 0 rows affected (0.00 sec)

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

mysql> exit

Configuration

Now, we need to set the correct credentials in the configuration file. Go to the wordpress folder and create a file called wp-config.php. This is a special file, it contains important informations about the database used by wordpress. Hackers love it, it must be hard to get. We will use a template provided by the WordPress team.

pi@webpi /var/www/$ sudo cp wp-config-sample.php wp-config.php

Now open the file and change the DB_NAME, DB_USER and DB_PASSWORD values according to the ones you chose before.

pi@webpi /var/www/$ sudo nano wp-config.php

Now let’s change the permissions of the /var/www/ folder.

pi@webpi /var/www/$  sudo chown -R pi:www-data *

Please note that the user I’m using to connect to the server is pi, assuming that you are not logged in as root, change it to the one you are using in this process.

Now, we need to create a last directory, uploads. If we allow the webserver to write to this folder, we will be able to upload content to the server. Run the follwing command:

pi@webpi /var/www/$ sudo mkdir /var/www/wp-content/uploads
pi@webpi /var/www/$ sudo chown -R :www-data /var/www/wp-content/uploads

Complete the installation

Now that we have all set up we can continue the installation through the web interface.

If you are installing wordpress on a home pc or a Raspberry Pi, open a browser and go to http://yourLocalIpAddress/index.php. You can find it with ipconfig for exemple. If you have a remote server use your domain name or the public ip.

WordPress requires:

  • Site Title
  • username
  • Password
  • Your email

Remove the check from “Allow search engines to index the website“. You will allow google bots when the website is finished or when you have reached the minimum number of post suggested by the good sense. You don’t want you visitors to hit and run because your website is empty.

Now remove the index.html file in order to set the file index.php as default page.

pi@webpi /var/www/$ sudo rm index.html

Permalinks

Now that we have our wordpress installation set up we can change the way wordpress creates URLs. To remove the default option, we first need to modify the default file in the /etc/apache2/sites-available/ folder using:

pi@webpi /var/www $ sudo nano /etc/apache2/sites-available/000-default.conf

Add the ServerName and allow overrides in the /var/www/ folder.


        ServerAdmin webmaster@localhost
        ServerName your_IP_address
        DocumentRoot /var/www

        < Directory /var/www/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Order allow,deny
                allow from all
        < /Directory>
        
        
[...]

Enable the rewrite module and restart apache2

pi@webpi /var/www $ sudo a2enmod rewrite
pi@webpi /var/www $ sudo service apache2 restart

Now, open your wordpress Dashboard, go to settings in the left bar and open the Permalink option.
Choose the Post Name option and click “Save Changes” to generate the rewrite rules. At the bottom of the page, WordPress shoudl have provided the rewrite rules we need to add to the .htaccess file manually.

pi@webpi /var/www $ sudo nano .htaccess

And paste the rewrite rules.

# BEGIN WordPress
< IfModule mod_rewrite.c >
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
< / IfModule >

Now we need the web server to be the group owner.

pi@webpi /var/www $ sudo chown :www-data /var/www/.htaccess

once the ownership has been changed, we need to set the permissions to read write and execute the file.

pi@webpi /var/www $ sudo chmod 644 /var/www/.htaccess

Fix importing problems

If you get the following error when you create a new theme:

Unable to create directory wp-content/uploads/ Is its parent directory writable by the server?

you should give the following permission: (rwxr-xr-x) Read, write and execute permissions for the owner of the folder and for members of the group owning the folder. All other users may only read and execute the folder.

pi@webpi /var/www $ sudo chmod 775 /var/www/wp-content/uploads/

If you want to import the default content from a theme and you encounter a “Failed to import” or a “Invalid post type” error, consider the following workarounds.

  • Go to the info.php page we have created in the past tutorial and check the path to the php.ini file. In my case the path is /etc/php/7.0/apache2/php.ini. Open it and modify the default_socket_timeout to 300 or more.
  • Instead of importing the .xml file directly, compress it in a .gz archive. Try to import the compressed file.

If you get an error message like:

Sorry, there has been an error.
This does not appear to be a WXR file, missing/invalid WXR version number.

then open the .xml file you want to import and add the following line at the beginning.

1.1

Error while importing demo content
If WordPress Importer returns an error like this:

Sorry, there has been an error.
The uploaded file exceeds the upload_max_filesize directive in php.ini.

The default upload file size for WordPress is 2 MB, which is a problem if you want to upload a large media files. To fix it, open the php.ini file and change the following lines to:

; Maximum allowed size for uploaded files.
; http://php.net/upload-max-filesize
upload_max_filesize = 64M

; Maximum number of files that can be uploaded via a single request
max_file_uploads = 40

Now you should be good to go.

You can’t update plugin?

Set the ownership of all files in /var/www/html to www-data.

chown -R www-data:www-data ./*

Installing your theme

Once you’ve downloaded the installation file on ThemeForest, extract it and locate a file called your_theme.zip. You can install the theme by using one of two installation methods:

  • WordPress upload – This is probably the simplest way for most users. Here are the steps you need to take:
    • Login to WordPress admin
    • Go to admin panel > Appearance > Themes > Add New > Upload Theme
    • Click on “Choose File” and select Bridge.zip
    • Click on “Install Now”
  • FTP upload – If you wish to install via FTP, here are the steps you need to take:
    • Using FTP client, login to the server where your WordPress website is hosted
    • Using FTP client, navigate to the /wp-content/themes/ directory under your WordPress website’s root directory
    • Using FTP client, upload theme directory to themes directory on remote server

Once installation is complete, your Bridge theme will be ready to use. Just activate it from the the admin panel > Appearance > Themes.

Hope it helps! Enjoy your wordpress website!