Ubuntu 18.04 install MySQL Server

Ubuntu 18.04 install MySQL Server

Installation for MySQL is slightly different in 18.04 as compared to 16.04.

sudo apt update
sudo apt install mysql-server -y
sudo mysql -uroot

Now in MySQL console, type the following to check the users.

select user,host,plugin from mysql.user;
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'NEWPASSWORD';
update mysql.user set host='%' where user='root';
exit;

Comment the line bind-address if you like to listen on all addresses.

sudo service mysql restart

 

Suppress Bash MySQL warning

Install Ubuntu MySQL client

I assume you already installed MySQL client in your Ubuntu 16.04. If you had not, then to install MySQL client in Ubuntu, type in the following commands. Having a MySQL client is useless if you do not have a MySQL server to query. To install MySQL server, you can refer to my Ubuntu install WordPress blog post.

sudo apt-get update
sudo apt-get install mysql-client -y

Execute MySQL statement in Bash

To execute a MySQL statement in Bash, simply type in the following. I assume your MySQL server is hosted locally using the user “root” and with the password “password”.

mysql --host=localhost --user=root --password=password --execute='select now()'

Alternatively, you can use the shorter version to execute the same statement with the syntax below.

mysql -hlocalhost -uroot -ppassword -e'select now()'

Suppress Bash MySQL warning

Executing your MySQL statement in Bash with your password revealed in plain text will cause a warning to appear each time you execute a statement. It is quite annoying if you are running a loop executing MySQL statements with its output in stdout.

To suppress the warning, type the following commands. Key in your password when it prompts you for the password.

mysql_config_editor set --login-path=localhost --host=localhost --user=root --password

After that execute your MySQL statements using the syntax below. Both statements are the same, one long and one short depending on your preference. By executing it this way, MySQL warning is no longer there.

mysql --login-path=localhost --execute='select now()'
mysql --login-path=localhost -e'select now()'
suppress mysql warning
Suppressing MySQL warning by executing MySQL statement using login path.

Ubuntu install WordPress

Install Apache

I assume you had already installed Apache into your Ubuntu elastic compute cloud ( EC2 ) instance. If you had not, then read my test Cloudflare DNS blog post, I had written about installing Apache. The entire guide below is using Ubuntu 16.04.

Configure Rewrite Module

This step is optional if you do not mind seeing “index.php” with query strings suffix after it. To remove it, you’ll need to configure the rewrite module in Apache. Go to /etc/apache2/sites-available/ and edit the file 000-default.conf and add the following codes in between the “VirtualHost” tag. After that type in the following commands to enable rewrite module.

<Directory /var/www/html>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Require all granted
</Directory>
sudo a2enmod rewrite
sudo service apache2 restart
ubuntu install wordpress
A sample rewrite module configuration.

Install MySQL server

To install MySQL server, type in the following commands in your Ubuntu terminal. During installation, it will prompt you for the root password. Type in your desired root password and repeat the same password in the next screen.

Next type in mysql_secure_installation. You will be prompted with a series of questions, you can answer accordingly as per my example. Create a database for WordPress use with the commands below. In my example, my database root user password is “password”. Replace the password with the password you entered earlier when you install MySQL server.

sudo apt-get update
sudo apt-get install mysql-server -y
ubuntu install wordpress
MySQL server installation prompting for “root” password.
ubuntu install wordpress
MySQL server installation prompting for root password confirmation.
mysql_secure_installation

Would you like to setup VALIDATE PASSWORD plugin? : n
Change the password for root ? : n
Remove anonymous users? : y
Disallow root login remotely? : y
Remove test database and access to it? : y
Reload privilege tables now? : y

mysql -uroot -ppassword -e 'create database wordpress'

Creating a database for WordPress by executing the MySQL statement with your password reveal in plain text will cause a warning. To suppress Bash MySQL warning you will need to store the password in the encrypted “.mylogin.cnf” file.

ubuntu install wordpress
A series of questions asked during mysql_secure_installation

Install PHP

To install PHP, type in the following commands. Once completed, to test if you had successfully installed PHP, open your web browser and go to “http://54.236.21.17/info.php”. Your IP address will be different from mine, replace the IP address with yours.

If you are unsure of your IP address, you can type in the curl command below to check. Make sure that you configure security group to allow inbound HTTP traffic.

sudo apt-get install php php-mysql libapache2-mod-php php-curl -y
echo '<?php phpinfo(); ?>' | sudo tee -a /var/www/html/info.php
curl checkip.amazonaws.com

ubuntu install wordpress

Ubuntu Install WordPress

To install WordPress, type in the following commands. Once completed, go to “http://54.236.21.17/index.php”. Your IP address will be different from mine, replace the IP address with yours. You should see the WordPress setup config page. Follow through the setup wizard to complete the WordPress setup.

cd /tmp/
wget https://wordpress.org/latest.tar.gz
tar -xzvf latest.tar.gz
cd /tmp/wordpress/
sudo mv * /var/www/html/
sudo chown -R www-data:www-data /var/www/html/
sudo chmod -R 755 /var/www/html/

ubuntu install wordpress
Choose your WordPress language.

ubuntu install wordpress

ubuntu install wordpress
In my example, my username is “root” and my password is “password”

ubuntu install wordpress

ubuntu install wordpress

ubuntu install wordpress

ubuntu install wordpress

ubuntu install wordpress
You have successfully completed WordPress setup once you see this WordPress admin dashboard.