Beta 42

Research and Development

Menu

Setup LAMP for WordPress

Install a LAMP Stack with Virtual Hosts and secure it with Let's Encrypt Certbot.

Create a MySQL Database and User for WordPress

The first step that we will take is a preparatory one. WordPress uses MySQL to manage and store site and user information. We have MySQL installed already, but we need to make a database and a user for WordPress to use.

To get started, log into the MySQL root (administrative) account by issuing this command:

mysql -u root -p

First, we can create a separate database that WordPress will control. You can call this whatever you would like, but we will be using wordpress in this guide to keep it simple. Create the database for WordPress by typing:

mysql> CREATE DATABASE wordpress DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;

Next, we are going to create a separate MySQL user account that we will use exclusively to operate on our new database. Creating one-function databases and accounts is a good idea from a management and security standpoint. We will use the name wordpressuser in this guide.

CREATE USER 'wordpressuser'@'%' IDENTIFIED BY 'very_complex_password';

We are going to create this account, set a password, and grant access to the database we created. We can do this by typing the following command:

mysql> GRANT ALL ON wordpress.* TO 'wordpressuser'@'localhost' IDENTIFIED BY 'password';

You now have a database and user account, each made specifically for WordPress. We need to flush the privileges so that the current instance of MySQL knows about the recent changes we’ve made:

mysql> FLUSH PRIVILEGES;

Exit out of MySQL by typing:

mysql> EXIT;

Install Additional PHP Extensions

We can download and install some of the most popular PHP extensions for use with WordPress by typing:

sudo apt update
sudo apt install php-curl php-gd php-mbstring php-xml php-xmlrpc php-soap php-intl php-zip

Note: Each WordPress plugin has its own set of requirements. Some may require additional PHP packages to be installed. Check your plugin documentation to discover its PHP requirements. If they are available, they can be installed with apt as demonstrated above.

We will restart Apache to load these new extensions in the next section. If you are returning here to install additional plugins, you can restart Apache now by typing:

sudo systemctl restart apache2

Adjust Apache’s Configuration

Enable .htaccess Overrides

The use of .htaccess files is disabled by default. WordPress and many WordPress plugins use these files extensively for in-directory tweaks to the web server’s behavior.

Open the Apache configuration file for your website:

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

To allow .htaccess files, we need to set the AllowOverride directive within a Directory block pointing to the document root. Add the following block of text inside the VirtualHost block in your configuration file, being sure to use the correct web root directory:

<Directory /var/www/wordpress/>
    AllowOverride All
</Directory>

Enable the Rewrite Module

Enable mod_rewrite so that we can utilize the WordPress permalink feature:

sudo a2enmod rewrite

Restart Apache to implement the changes:

sudo systemctl restart apache2