Installing WordPress on Ubuntu 17.04 | 17.10 with Apache2, MariaDB and PHP
WordPress is the most popular content management systems in used today. This brief tutorial shows students and new users how to easily install WordPress on Ubuntu 17.04 | 17.10 with support for Apache2, MariaDB and PHP.
This post should be easy to read and understand.. even for new users. It should serve as a guide to anyone wanting to get WordPress quickly installed and ready to use on Ubuntu.
To get started with getting WordPress installed on Ubuntu, follow the steps below:
Step 1: Install Apache2
WordPress requires a webserver to function. Apache2 is the most popular webserver so let’s get it installed. To do that, run the commands below:
sudo apt-get update sudo apt-get install apache2
After installing Apache2, run the commands below to disable directory listing on Apache2
sudo sed -i "s/Options Indexes FollowSymLinks/Options FollowSymLinks/" /etc/apache2/apache2.conf
The commands below can be used to stop, start and enable Apache2 service to always start up when the server boots up.
sudo systemctl stop apache2.service sudo systemctl start apache2.service sudo systemctl enable apache2.service
STEP 2: INSTALL MARIADB
WordPress also requires a database server to function.. and MariaDB database server is a great place to start. To install it run the commands below.
sudo apt-get install mariadb-server mariadb-client
After installing, the commands below can be used to stop, start and enable MariaDB service to always start up when the server boots.
sudo systemctl stop mariadb.service sudo systemctl start mariadb.service sudo systemctl enable mariadb.service
After that, run the commands below to secure MariaDB server.
sudo mysql_secure_installation
When prompted, answer the questions below by following the guide.
- Enter current password for root (enter for none): Just press the Enter
- Set root password? [Y/n]: Y
- New password: Enter password
- Re-enter new password: Repeat password
- Remove anonymous users? [Y/n]: Y
- Disallow root login remotely? [Y/n]: Y
- Remove test database and access to it? [Y/n]: Y
- Reload privilege tables now? [Y/n]: Y
After that, continue below to install PHP.
STEP 3: INSTALL PHP AND RELATED MODULES
WordPress also requires PHP to function. To install PHP and related modules run the commands below
sudo apt-get install php php-common php-mbstring php-xmlrpc php-soap php-gd php-xml php-intl php-mysql php-cli php-mcrypt php-ldap php-zip php-curl
STEP 4: CREATE WORDPRESS DATABASE
Now that you’ve installed all the packages that are required, continue below to start configuring the servers. First run the commands below to create WordPress database.
Run the commands below to logon to the database server. When prompted for a password, type the root password you created above.
sudo mysql -u root -p
Then create a database called wpdatabase
CREATE DATABASE wpdatabase;
Create a database user called wpuser with new password
CREATE USER 'wpdatabase'@'localhost' IDENTIFIED BY 'new_password_here';
Then grant the wpuser account full access to the database.
GRANT ALL ON wpdatabase.* TO 'wpuser'@'localhost' IDENTIFIED BY 'user_password_here' WITH GRANT OPTION;
Finally, save your changes and exit.
FLUSH PRIVILEGES; EXIT;
STEP 5: DOWNLOAD WORDPRESS LATEST RELEASE
Next, run the commands below to download WordPress latest release.
cd /tmp && wget https://wordpress.org/latest.tar.gz
Then run the commands below to extract the download file to Apache2 default root.
sudo tar -zxvf latest.tar.gz -C /var/www/html
Change modify the directory permission.
sudo chown -R www-data:www-data /var/www/html/ sudo chmod -R 755 /var/www/html/
STEP 6: CONFIGURE APACHE2
Finally, configure Apahce2 site configuration file for WordPress. This file will control how users access WordPress’ content. Run the commands below to create a new configuration file called wordpress.conf
sudo nano /etc/apache2/sites-available/wordpress.conf
Then copy and paste the content below into the file and save it. Replace the highlighted line with your own domain name and directory root location.
<VirtualHost *:80> ServerAdmin admin@example.com DocumentRoot /var/www/html/wordpress/ ServerName example.com ServerAlias www.example.com ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost>
Save the file and exit.
STEP 7: ENABLE THE WORDPRESS SITE
After configuring the VirtualHost above, enable it by running the commands below
sudo a2ensite wordpress.conf
STEP 8 : RESTART APACHE2
To load all the settings above, restart Apache2 by running the commands below.
sudo systemctl restart apache2.service
Step 9: Configure WordPress
Now that Apache2 is configured, run the commands below to create WordPress wp-config.php file.
sudo mv /var/www/html/wordpress/wp-config-sample.php /var/www/html/wordpress/wp-config.php
Then run the commands below to open WordPress configuration file.
sudo nano /var/www/html/wordpress/wp-config.php
Enter the highlighted text below that you created for your database and save.
// ** MySQL settings - You can get this info from your web host ** // /** The name of the database for WordPress */ define('DB_NAME', 'wpdatabase'); /** MySQL database username */ define('DB_USER', 'wpuser'); /** MySQL database password */ define('DB_PASSWORD', 'user_password_here'); /** 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', '');
After that, open your browser and browse to your domain name to launch WordPress configuration wizard
ex. http://myexample.com

Follow the on-screen wizard until you’ve successfully installed WordPress.
You may also like the post below: