Categories
Code Linux Sysadmin WordPress

Basic LAMP & WordPress install & setup

There are many ways to setup and install WordPress, in this post I’ll cover how I setup a LAMP stack and install WordPress using the WP-cli.

Prerequisites:

  • A VPS / VM with Ubuntu install
  • A user with SSH and sudo permissions

I’ll be using an AWS EC2 with Ubuntu 18.04. To get started I’m going to make sure all my packages are updated.

sudo apt update
sudo apt upgrade

Next let’s get the “AMP” of the LAMP stack installed. Below we are installing Apache2, mySQL, PHP, and a few other useful helpers.

sudo apt install apache2 mysql-server php php-mysql libapache2-mod-php php-cli

Now let’s secure our mySQL install.

sudo /usr/bin/mysql_secure_installation

Now lets login to the mySQL cli by typing sudo mysql and create a user and database for our WordPress install.

CREATE USER 'YOUR-WP-DB-USERNAME'@'localhost' IDENTIFIED BY 'YOUR-WP-DB-PASSWORD';
CREATE DATABASE YOUR-WP-DB-NAME;
GRANT ALL PRIVILEGES ON YOUR-WP-DB-NAME.* TO 'YOUR-WP-DB-USERNAME'@'localhost';
FLUSH PRIVILEGES;

Once we have finished create the user, database, and flushing mysql privileges lets exit the mysql Cli by typing exit

Lets tweak Apache to ensure that our .htaccess for our WordPress install can actually be used.

sudo nano /etc/apache2/apache2.conf

Find:

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

and update it to

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

Finally lets enabled Apache2 mod rewrite and restart Apache2 so that are changes become active.

sudo a2enmod rewrite
sudo systemctl restart apache2

Now lets download and install the WP-cli which we will use to download our WordPress install files

curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar && chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp

Now lets head over to our web root directory and download WordPress Core

cd /var/www/html
sudo wp core download --allow-root

Before we began the install lets makes sure the Apache user www-data is the owner of our web root directory.

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

You should now be able to visit your server’s IP or DNS record and finish up installing WordPress using the database credentials we setup before.

Leave a Reply

Your email address will not be published. Required fields are marked *