GNU/Linux {docs}

LAMP + Wordpress

This tutorial explain how to install Wordpress in a LAMP stack and local Virtual Host .

If you haven't installed LAMP, visit the tutorial about LAMP.

If you haven't set up a local Virtual Host yet for your particular domain, visit the tutorial about Local VPS right now!!! Then come back here.

Important files and directories:

  • /etc/hosts
  • /etc/apache2/sites-available/
  • /var/www/mydomain.com/public_html/wp-config.php

Download and configure Wordpress directory

$ cd /tmp
$ wget https://wordpress.org/latest.tar.gz
$ tar xzvf latest.tar.gz
$ touch /tmp/wordpress/.htaccess
$ chmod 660 /tmp/wordpress/.htaccess
$ cp /tmp/wordpress/wp-config-sample.php /tmp/wordpress/wp-config.php

We can also create the upgrade directory, so that WordPress won't run into permissions issues when trying to do this on its own following an update to its software:

$ mkdir /tmp/wordpress/wp-content/upgrade

Now, we can copy the entire contents of the directory into our document root. We are using the -a flag to make sure our permissions are maintained. We are using a dot at the end of our source directory to indicate that everything within the directory should be copied, including hidden files (like the .htaccess file we created):

$ sudo cp -a /tmp/wordpress/. /var/www/html/example.com
$ sudo chown -R www-data:www-data /var/www/html/example.com

Next, we will set the setgid bit on each of the directories within the document root. This causes new files created within these directories to inherit the group of the parent directory (which we just set to www-data) instead of the creating user's primary group. This just makes sure that whenever we create a file in the directory on the command line, the web server will still have group ownership over it.

We can set the setgid bit on every directory in our WordPress installation by typing:

$ sudo find /var/www/html/example.com -type d -exec chmod g+s {} \;

There are a few other fine-grained permissions we'll adjust. First, we'll give group write access to the wp-content directory so that the web interface can make theme and plugin changes:

$ sudo chmod g+w /var/www/html/example.com/wp-content

As part of this process, we will give the web server write access to all of the content in these two directories:

$ sudo chmod -R g+w /var/www/html/example.com/wp-content/themes
$ sudo chmod -R g+w /var/www/html/example.com/wp-content/plugins

This should be a reasonable permissions set to start with. Some plugins and procedures might require additional tweaks.

Setting up the WordPress Configuration File

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

edit:

. . .
define('DB_NAME', 'example_database');
/** MySQL database username */
define('DB_USER', 'wpuser');
/** MySQL database password */
define('DB_PASSWORD', 'mypassword');
. . .

and append:

define('FS_METHOD', 'direct');

The above line will allow us to install Plugins and Themes in Wordpress.

Additional step:

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

Copy the generated values and replace the dummy values at /var/www/html/example.com/wp-config.php

Create a MariaDB database

# mariadb -u root -p
MariaDB> CREATE DATABASE example_database;
MariaDB> GRANT ALL PRIVILEGES ON example_database.* TO "wpuser"@"localhost" IDENTIFIED BY "mypassword";
MariaDB> FLUSH PRIVILEGES;
MariaDB> EXIT

Installing Wordpress

  • Go to http://example.com and fill the form (be sure to type wpuser in user's field in the form)

Adjust Apache's Configuration to Allow for .htaccess Overrides and Rewrites

Enable .htaccess Overrides

Open the primary Apache configuration file to make our first change:

$ sudo nano /etc/apache2/apache2.conf

To allow .htaccess files, we need to set the AllowOverride directive to All within a Directory block pointing to our document root. Towards the bottom of the file, add the following block:

<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>

Alternatively, you can edit /etc/apache2/sites-available/example.com.conf and add the following lines :

<Directory />
Options FollowSymLinks
AllowOverride None
Require all denied
</Directory>
<Directory /var/www/example.com/public_html>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>

Restart the Apache server:

$ sudo systemctl restart apache2

Next, we can enable mod_rewrite so that we can utilize the WordPress permalink feature:

$ sudo a2enmod rewrite

Updating Wordpress

$ sudo chown -R www-data /var/www/example.com/public_html

Now, go back the WordPress administration panel and apply the update.

When you are finished, lock the permissions down again for security:

$ sudo chown -R $USER /var/www/example.com/public_html

This should only be necessary when applying upgrades to WordPress itself.

Wordpress Initial Setup

  • Dashboard -> Settings -> Permalinks -> Post name

Home Page setup

Settings -> Reading -> Your homepage displays -> A static page -> Homepage: <select your page>

Prevent Search Engine indexation

When initially creating the website, it is recommended to turn off Search Engine indexation:

Settings -> Reading -> Search Engine Visibility -> Discourage search engines from indexing this site

Anchors

Clickeable Component -> Content -> Link -> #target_anchor

Target anchor component -> Advanced -> CSS ID -> target_anchor (without hash symbol)

Useful Themes and Plugins

  • A good starter theme is OceanWP
  • A must have plugin for OceanWP theme is Ocean Extra
  • A must have plugin for editing pages in general is Elementor
  • Hummingbird Page Speed Optimization
  • Smush Image Compression and Optimization
  • Yoast SEO

Removing OceanWP Top Bar

Appearance -> Customize -> Top Bar -> General -> Enable Top Bar (uncheck)

Pages: How to clean default screen layout for OceanWP theme

  1. Main -> Content Layout -> 100% Full Width
  2. Header -> Display Header -> Disable
  3. Title -> Display Page Title -> Disable
  4. Click on "Update" button on the right

Yoast SEO - RSS

Content to put before each post in the feed: %%POSTLINK%%

Content to put after each post in the feed: <p>Original article at <a href="https://mydomain.com/" rel="nofollow">My Site</a></p>

Appearance -> Menus -> Menu Structure -> Affected Page -> Disable link

Astra Theme and Plugins

Note: For the Astra Them and Plugins to work, php-xml extension must be installed in the server.

Themes -> Add New -> search for 'Astra' -> Install Now -> Activate

Plugins -> Add New -> search for 'Astra Starter Sites' -> Install Now

Appearance -> Astra Sites -> Elementor -> select Site -> Install Plugins -> Import This Site