Install WordPress on LAMP Stack

Quick Install of WordPress on Debian 10 / Ubuntu 20.04

Components you should already have:

  • Ubuntu 20.04 Server or Debian 10

Components we will be installing:

  • LAMP stack (Linux,Apache2,MySQL,PHP)
  • WordPress (latest version)

Installation Process

Before we begin let's fully update your server:

sudo apt update && sudo apt dist-upgrade -y

Install LAMP Stack

Installing the LAMP stack will be easy using a neat tool called Tasksel.

https://help.ubuntu.com/community/Tasksel

Install Tasksel

sudo apt-get install tasksel

Install LAMP using tasksel

sudo tasksel install lamp-server

That's it, now you should be able to browse to your server IP and see the Apache2 welcome screen. But we are not done yet so.

Install additional PHP extensions

We might need more than the core extensions installed in order to use most of the common wordpress plugins.

These are some of the more common I use:

sudo apt-get install -y imagemagick php-{cli,bz2,intl,gd,mbstring,mysql,zip,imagick,xml,curl,xmlrpc,soap,json,gmp,common,ldap}

Now you have to restart Apache2 so the new modules will load:

sudo systemctl restart apache2

Setup your WordPress Database

Secure your MySQL install

mysql_secure_installation is a shell script available on Unix systems, and enables you to improve the security of your MySQL installation.

https://dev.mysql.com/doc/refman/5.6/en/mysql-secure-installation.html

You can pretty much click on all the defaults and set your password.

sudo mysql_secure_installation

Using your new root password, login to the MySQL server and create a new Database and user for wordpress.

sudo mysql -u root -p

Now you should be in the Mysql cli prompt. Let's create a new database named wordpressdb (you can choose any name).

CREATE DATABASE wordpressdb DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;

Now we create a user to access the database on behalf of wordpress (Create your own a user and password).

CREATE USER 'wordpressuser'@'%' IDENTIFIED WITH mysql_native_password BY 'password';
GRANT ALL ON wordpressdb.* TO 'wordpressuser'@'%';
FLUSH PRIVILEGES;
EXIT;

Download WordPress

Let's download wordpress to the tmp folder and go from there:

cd /tmp
curl -O https://wordpress.org/latest.tar.gz
tar xzvf latest.tar.gz

Create the .htaccess file

touch /tmp/wordpress/.htaccess

Copy the sample configuration over to WordPress

cp /tmp/wordpress/wp-config-sample.php /tmp/wordpress/wp-config.php

Create the upgrade folder too

mkdir /tmp/wordpress/wp-content/upgrade

Configure WordPress Directory

Now copy the wordpress folder over to it's final destination.

You can change the /var/www/wordpress to a name you plan to use on your server

example: /var/www/choose-a-name

sudo cp -a /tmp/wordpress/. /var/www/wordpress

Set Ownership & Permissions

Set owner to the www-data which is the user that Apache Web Server runs as

Remember to use the actual folder name you selected!

sudo chown -R www-data:www-data /var/www/wordpress

Set the Permissions for Files & Folders in the WordPress directories

sudo find /var/www/wordpress/ -type d -exec chmod 750 {} \;
sudo find /var/www/wordpress/ -type f -exec chmod 640 {} \;

WordPress Configuration File Settings

We need to generate the secure values for our website using the WordPress secret key generator.

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

Your screen should be presented with a list of values that look like this:

DO NOT COPY THESE VALUES, USE THE ONES YOU GENERATED!!!

define('AUTH_KEY',         '1jl/vqfs<XhdXoAPz9 DO NOT COPY THESE VALUES c_j{iwqD^<+c9.k<J@4H');
define('SECURE_AUTH_KEY',  'E2N-h2]Dcvp+aS/p7X DO NOT COPY THESE VALUES {Ka(f;rv?Pxf})CgLi-3');
define('LOGGED_IN_KEY',    'W(50,{W^,OPB%PB<JF DO NOT COPY THESE VALUES 2;y&,2m%3]R6DUth[;88');
define('NONCE_KEY',        'll,4UC)7ua+8<!4VM+ DO NOT COPY THESE VALUES #`DXF+[$atzM7 o^-C7g');
define('AUTH_SALT',        'koMrurzOA+|L_lG}kf DO NOT COPY THESE VALUES  07VC*Lj*lD&?3w!BT#-');
define('SECURE_AUTH_SALT', 'p32*p,]z%LZ+pAu:VY DO NOT COPY THESE VALUES C-?y+K0DK_+F|0h{!_xY');
define('LOGGED_IN_SALT',   'i^/G2W7!-1H2OQ+t$3 DO NOT COPY THESE VALUES t6**bRVFSD[Hi])-qS`|');
define('NONCE_SALT',       'Q6]U:K?j4L%Z]}h^q7 DO NOT COPY THESE VALUES 1% ^qUswWgn+6&xqHN&%');

Now copy the values you generated to paste them in wp-config.php

sudo nano /var/www/wordpress/wp-config.php

Find & replace the following section with your generated values

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');

Find the MySQL settings section and complete the configuration with the Database information

/var/www/wordpress/wp-config.php

// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define( 'DB_NAME', 'wordpress' );

/** MySQL database username */
define( 'DB_USER', 'wordpressuser' );

/** MySQL database password */
define( 'DB_PASSWORD', 'password' );

/** MySQL hostname */
define( 'DB_HOST', 'localhost' );

/** Database Charset to use in creating database tables. */
define( 'DB_CHARSET', 'utf8' );

/** The Database Collate type. Don't change this if in doubt. */
define( 'DB_COLLATE', '' );

OPTIONAL: If you are using Hypertext Transfer Protocol Secure (HTTPS), add this setting at the top of the configuration

Paste this right above the MYSQL Settings: // ** MySQL settings - You can get this info from your web host ** //

/* SSL Reverse Proxy handle */

define('FORCE_SSL_ADMIN', true);
if (strpos($_SERVER['HTTP_X_FORWARDED_PROTO'], 'https') !== false){
$_SERVER['HTTPS']='on';
}

/* End of SSL Reverse Proxy */

OK, you can save the file and move to the next stage.

Setup the Apache Server for WordPress

I am assuming you have no other websites running on the server and will be running WordPress on the root URL.

So let's disable the default Apache Welcome Website and enable the new wordpress site. Remember that you can use a name that matches your folder.

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

Paste the following into the file:

Make sure to change the values to match your server, email, domain and wordpress folder

<VirtualHost *:80>
      DocumentRoot /var/www/wordpress
      ServerName wordpress.yourdomain.com
      ServerAdmin admin@yourdomain.com
      ErrorLog ${APACHE_LOG_DIR}/error.log
      CustomLog ${APACHE_LOG_DIR}/access.log combined

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

</VirtualHost>

After saving the file, lets enable it and disable the default one.

sudo a2dissite 000-default
sudo a2ensite wordpress

Also lets enable mod rewrite

a2enmod rewrite

Now we restart apache2

sudo systemctl restart apache2

That should be it, go to the server URL and complete your web based installation.

Leave a Reply