Wordpress Install
Wordpress Installation and Configuration Guide.
Prerequisites
- Create a sudo user on your server
- Install a LAMP stack
- Secure your site with SSL (can be done after)
Create a MySQL Database and User for WordPress
Log in to a MySQL administrative account (root):
sudo mysql -u root -p
Create wordpress database:
CREATE DATABASE wordpress DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
Create exclusive user for this database:
GRANT ALL ON wordpress.* TO 'wordpressuser'@'localhost' IDENTIFIED BY 'password';
Flush the privileges so that the current instance of MySQL knows about the recent changes:
FLUSH PRIVILEGES;
Exit the MySQL shell:
exit
Installing Additional PHP Extensions
Install some of the most popular PHP extensions for use with WordPress:
sudo apt install php-curl php-gd php-mbstring php-xml php-xmlrpc php-soap php-intl php-zip
Adjusting Apaches Configuration to Allow for .htaccess Overrides and Rewrites
Enabling .htaccess Overrides
Create a configuration file in /etc/apache2/sites-available/
directory, that will allow .htacess
files
in /var/www/wordpress
(it will be the root directory of our wordpress installation):
sudo vim /etc/apache2/sites-available/wordpress.conf
And add the following, changing the fields with yourdomain.com
and www.yourdomain.com
:
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/wordpress
ServerName yourdomain.com
ServerAlias www.yourdomain.com
<Directory /var/www/wordpress/>
AllowOverride All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
The Directory
tag allows .htacess
files and the VirtualHost
tag,
creates a virtual host to be able to host multiple domains from a single server.
When you are finished, save and close the file.
Enabling the Rewrite Module
Next, we can enable mod_rewrite
so that we can utilize the WordPress permalink feature
sudo a2enmod rewrite
Enabling the file
sudo a2ensite wordpress.conf
Disabling the default site
sudo a2dissite 000-default.conf
Enabling the Changes
Make sure we don’t have syntax errors:
sudo apache2ctl configtest
If the output has a AH00558
message ignore it.
We only care about the SYNTAX OK message.
Restart Apache
sudo systemctl restart apache2
Downloading WordPress
Download latest version:
cd ~/Downloads
curl -O https://wordpress.org/latest.tar.gz
Extract the compressed file:
tar xzvf latest.tar.gz
Cd in the extracted directory:
cd wordpress
Create a dummy .htaccess
file:
touch .htacess
Copy over the sample configuration file to the filename that WordPress actually reads:
cp wp-config-sample.php wp-config.php
Create the following directory so as to not have permission issues later:
mkdir wp-content/upgrade
Cd out of the wordpress folder:
cd ..
Copy the entire contents of the directory into our document root:
sudo cp -a wordpress/. /var/www/wordpress
Configuring the WordPress Directory
Adjusting the Ownership and Permissions
Give ownership of all the files to the www-data
user and group (the user apache runs as):
sudo chown -R www-data:www-data /var/www/wordpress
We run two find commands to set the correct permissions on the WordPress directories and files:
sudo find /var/www/wordpress/ -type d -exec chmod 750 {} \;
sudo find /var/www/wordpress/ -type f -exec chmod 640 {} \;
Setting up the WordPress Configuration File
For the initial configuration, it requires the WordPress salt to be generated. This can be done using:
curl -s https://api.wordpress.org/secret-key/1.1/salt/
It will give a different output every time and will contain a list of salt values.
The output of the above command needs to be copied and added to the wp-config.php
file.
Open wp-config.php
:
sudo vim /var/www/wordpress/wp-config.php
Replace all the dummy values with the ones from the previous command.
Below are the dummy values from wp-config.php
to be replaced:
define( 'AUTH_KEY', 'put your unique phrase here' );
define( 'SECURE_AUTH_KEY', 'put your unique phrase here' );
define( 'LOGGED_IN_KEY', 'put your unique phrase here' );
define( 'NONCE_KEY', 'put your unique phrase here' );
define( 'AUTH_SALT', 'put your unique phrase here' );
define( 'SECURE_AUTH_SALT', 'put your unique phrase here' );
define( 'LOGGED_IN_SALT', 'put your unique phrase here' );
define( 'NONCE_SALT', 'put your unique phrase here' );
The wp-config.php file contains some Database configuration at the top.
Replace the DB_NAME
, DB_USER
, DB_PASSWORD
with values you have created for WordPress:
define('DB_NAME', 'wordpress');
/** MySQL database username */
define('DB_USER', 'wordpressuser');
/** MySQL database password */
define('DB_PASSWORD', 'password');
Also, you can add the file system method at the very bottom of the others:
define('FS_METHOD', 'direct');
Now the server configuration is complete! We can complete the installation through the web interface.
In your web browser, navigate to your servers domain name or public IP address:
https://server_domain_or_IP