Intro
In this article, we will install WordPress as fast as we can. We will be using the LAMP environment we just setup in the previous article. This is on Ubuntu 18.04 and the WordPress version we are using will be 5.0.2. If have not set this up yet, feel free to visit the LAMP installation article.
Database
The database by default won’t allow you to run some of the commands below with the user and password arguments. To fix this, let’s run
sudo mysql
Then once you are the console, run (remember to replace CHANGEME with the password):
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'CHANGEME';
FLUSH PRIVILEGES;
Now we can start setting up the database by running the command below (change the password section and YOUSITENAME to the site or database name that you want):
mysql --user="root" --password="CHANGEME" -e "CREATE DATABASE YOURSITENAME DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;"
This creates the database that we will be using for the website.
Note:
For this tutorial, we will be using the root user in our local environment, but you can create your own user if you wish. We will be migrating this project to a free hosting service in the later articles so this doesn’t matter too much for our purposes.
Server Configurations
Let’s create our website folder for the server to use by running:
sudo mkdir /var/www/YOURSITENAME
Then we can download the the WordPress files in a temp folder.
cd /tmp
curl -O https://wordpress.org/latest.tar.gz
tar xzvf latest.tar.gz
touch /tmp/wordpress/.htaccess
mkdir /tmp/wordpress/wp-content/upgrade
Permissions
Finally, we can copy the folders to the correct place and set its permissions so that everything goes smoothly.
sudo cp -a /tmp/wordpress/. /var/www/YOURSITENAME
sudo chown -R www-data:www-data /var/www/YOURSITENAME
sudo find /var/www/YOURSITENAME/ -type d -exec chmod 750 {} \;
sudo find /var/www/YOURSITENAME/ -type f -exec chmod 640 {} \;
Then we can change the document root in the configuration file to point to your website’s folder. Open up the file at /etc/apache2/sites-available/000-default.conf. You will need to run it with elevated priviledges, so if you are using the Nano text editor you can add sudo at the beginning like this:
sudo nano /etc/apache2/sites-available/000-default.conf
Or with Vim:
sudo vi /etc/apache2/sites-available/000-default.conf
Then change the line after Document root to be /var/www/YOURWEBSITEFOLDER
Then restart the web server by running:
sudo systemctl restart apache2
Now you can visit the website at http://localhost
The page that opens up should look like this:
Note:
There is a section in the wp-config.php file that you can change to make it more secure.
For this part, we need to generate some texts with the ‘Curl’ program. You can install Curl by running:
sudo apt install curl
Then make sure you copy or save the text you get from running this:
curl -s https://api.wordpress.org/secret-key/1.1/salt/
Now we can open up then config file in /var/www/wp-config.php (using sudo) and replace the section that looks similar to what we just generated above.
Before opening the file, you might also need to change the permissions of your folder at /var/www/YOURWEBSITENAME by running:
sudo chmod 777 /var/www/YOURWEBSITENAME
This makes it less secure if you are hosting the website on your current machine, but shouldn’t matter if you are just testing around.
Installation
To finish the installation, you can just follow through the instructions on the localhost page. After that, you are done, WordPress is now installed on your machine!
Navigation
The next article can be found here. Previous article is here.