Posted by : at

Category : wordpress   web-development   ubuntu   devops

In this tutorial on how to install wordpress on Ubuntu 16.04 LTS VPS Server. Follow this guide step by step if your VPS doesnot provides a cPanel to install the LAMP Stack or Wordpress directly.

  1. Login to your server using the terminal

It will ask password for the root server

// Enter Password

  1. Once you are inside. We need to create directory for our website
[email protected]:~# cd ..
[email protected]:~# cd var/www
[email protected]:~# mkdir yourwebsite.com
[email protected]:~# cd yourwebsite.com
  1. Now we are ready to install wordpress, for wordpress we have some prerequisites like Apache Web Server and Mysql Server

Install Wordpress

Step 1. Install Apache Web Server

[email protected]:~# apt-get install apache2 

After the installation is complete, you should start and enable Apache to start automatically upon server reboot with:

[email protected]:~# systemctl start apache2
[email protected]:~# systemctl enable apache2

To check the status of your Apache server and make sure it is up and running, you can run the following command

[email protected]:~# systemctl status apache2 

To verify that Apache is running, you can also open your web browser and enter your server IP address, (e.g. http://your_server_ip_address). If Apache is successfully installed you should see the Apache default welcome page. (your_server_ip_address will look something like 139.163.2.1)

Step 3. Install the MySQL Database Server

The next step is to install the MySQL database server which will be used for the data storage of your WordPress site. MySQL is one of the most popular database management systems. To install MySQL on your system, execute the following command and press Y to continue:

[email protected]:~# apt-get install mysql-server

During the installation, you will be asked to enter a password for the MySQL root user. Make sure you enter a strong password.

In order to improve the security of your MySQL server, we recommend that you run the mysql_secure_installation script by typing the following command:

[email protected]:~# mysql_secure_installation 

This script will help you to perform important security tasks like setting up a root password, disable remote root login, remove anonymous users etc.

After you have answered all the questions you can now go ahead and start the database server and enable it to automatically start upon boot, with:

[email protected]:~# systemctl start mysql 
[email protected]:~# systemctl enable mysql

Step 4. Install PHP

You proceed with this tutorial for installing PHP 7.1 Setting up PHP 7.1 on Ubuntu 16.04

Step 5. Install phpMyAdmin

Once Apache, PHP and MySQL are installed, we can go ahead and install phpMyAdmin, The package is included in the official Ubuntu 16.04 repository and it can be easily installed with the command below:

[email protected]:~# apt-get install phpmyadmin

phpMyAdmin will be installed along with its dependencies and all necessary PHP modules.

When you will be prompted to select a web server to configure, hit the space bar to select Apache2 and Enter to confirm and continue

lqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqu Configuring phpmyadmin tqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq
x Please choose the web server that should be automatically configured to run phpMyAdmin.  x
x                                                                                          x
x Web server to reconfigure automatically:                                                 x
x                                                                                          x
x    [ ] apache2                                                                           x
x    [ ] lighttpd                                                                          x
x                                                                                          x
x                                                                                          x
x                                                                                      x
x                                                                                          x
mqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj

On the next screen, select YES to configure a database for phpMyAdmin with dbconfig-common

qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq Configuring phpmyadmin qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq
x                                                                                                           x
x The phpmyadmin package must have a database installed and configured before it can be used.               x
x  This can be optionally handled with dbconfig-common.                                                     x
x                                                                                                           x
x If you are an advanced database administrator and know that you want to perform this configuration        x
x  manually, or if your database has already been installed and configured, you should refuse this option   x
x Details on what needs to be done should most likely be provided in /usr/share/doc/phpmyadmin.             x
x                                                                                                           x
x Otherwise, you should probably choose this option.                                                        x
x                                                                                                           x
x Configure database for phpmyadmin with dbconfig-common?                                                   x
x                                                                                                           x
x                                                                                                  x
x                                                                                                           x
mqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq

Step 6. Set the password for the phpMyAdmin User

and finally set a password for the ‘phpmyadmin’ user in MySQL

With this step, the installation of phpMyAdmin is completed.

phpMyAdmin

Step 7. Test and verify phpMyAdmin installation

You can access it at http://yourIPaddress/phpmyadmin and logi with your MySQL username and password.

Finally phpMyAdmin is installed !

With this last step, our LAMP stack installation and configuration has been completed.

Step 8. Intall Wordpress

We can now move on to the Wordpress Installation. We will download and place the Wordpress Installation in the default web server document root directory (/var/www/html)

Let’s move to this directory with:

# cd /var/www/html

And Download the latest Wordpress installation from the official wordpress.org.site with wget:

# wget -c http://wordpress.org/latest.tar.gz

Then, extract the file with:

# tar -xzvf latest.tar.gz

All the WordPress files will be now placed in the wordpress directory in /var/www/html/wordpress

This will extract all the wordpress files in wordpress folder

So we need to rename this wordpress folder to match our domain, otherwise the wordpress will be installed to yourdomain.com/wordpress. So to use wordpress with yourdomain.com we need to rename wordpress.

To rename :

# mv /var/www/html/wordpress /var/www/html/yourdomain.com

This will create a new folder “yourdomain.com” and inside it will be with the extracted wordpress files.

We also need to set the correct permissions of this directory so our Apache web server can access these files. To give ownership of the WordPress files to our Apache web server, run the following command:

# chown -R www-data:www-data /var/www/html/yourdomain.com

Step 6: Create a database for Wordpress

Now, we will create our MySQL database for our Wordpress site. Login to your MySQL server with the following command and enter your MySQL root password:

# mysql -u root -p

To create a new databas for our Wordpress installation, run the following commands:

CREATE DATABASE my_db;
GRANT ALL PRIVILEGES ON YOUR_DB_NAME.* TO 'YOUR_NAME'@'localhost' IDENTIFIED BY 'YOUR_PASSWORD';
FLUSH PRIVILEGES;
exit;

You can replace the database name (YOUR_DB_NAME) and the MySQL user name (YOUR_NAME) with your own names. Also, make sure to replace “YOUR_PASSWORD” with an actual, strong password.

Once the database is created, we will need to add this information to the WordPress configuration file.

Make sure you are inside the /var/www/html/yourdomain.com directory and run the following command to rename the sample configuration file:

[email protected]:~# mv wp-config-sample.php wp-config.php

Now open the wp-config.php file with your favourite text editor, for example:

# nano wp-config.php

And update the database settings, replacing database_name_here, username_here and password_here with your own details:

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

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

/** 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', '');

Save and exit the file.

Restart your Apache and MySQL server with:

systemctl restart apache2
systemctl restart mysql

Now we need to connect our domain with the server.If you have a valid domain name, and you want to use it to access your Wordpress, you will need to create a bew Apache Virtual Host File.

# nano /etc/apache2/sites-available/yourdomain.com.conf

And add the following content to the file ( you can replace mydomain.com with your actual domain name):

<VirtualHost *:80>

ServerAdmin [email protected]
ServerName yourdomain.com
ServerAlias www.yourdomain.com
DocumentRoot /var/www/html/yourdomain.com/

ErrorLog ${APACHE_LOG_DIR}/yourdomain.com_error.log
CustomLog ${APACHE_LOG_DIR}/yourdomain.com_access.log combined

RewriteEngine on
RewriteCond %{SERVER_NAME} =yourdomain.com [OR]
RewriteCond %{SERVER_NAME} =www.yourdomain.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]

</VirtualHost>

Then we need to enable the virtual host we have just created, run the following commands: (there are two ways to do so) :

Either run this command :

# a2ensite yourdomain.com.conf

or

Another alternative way to do this is by creating a symbolic link for your virtual host in /etc/apache2/sites-enabled:

# ln -s /etc/apache2/sites-available/yourdomain.com.conf /etc/apache2/sites-enabled/

Once you enable the virtual host, using either of above methods, you will need to restart the Apache web server:

[email protected]:~# systemctl restart apache2

Step - Connect the domain to ip address

In order to connect our domain to our wordpress, we need to change the DNS settings for our domain to redirect to our servers ip address.

We need to create a A record and point it to servers IP Address

should change your DNS setting something like this

TYPE     NAME         VALUE                TTL
 
A         @      YOUR_SERVER_IP_ADDRESS    600s

CNAME     www          @                    1hr

Now the domain is connected, and should be up and running the Wordpress Setup !

Hurray ! We did it. We just installed Wordpress for your Website

Related Posts