WordPress on LAMP

CMS (Content Management System) is an application or computer software that uses database to manage and publish web/digital contents. It provides version management and keeps workflow to keep our sites and content consistent. It is mainly used for ECM (Enterprise Content Management) and Web Content Management (WCM). ECM typically includes a WCM function. Most content management system solutions are usually open source, so they can be accessible by everyone and are free.

Enterprise Content Management (ECM)system provides a systematic collection and organization of data and information that is used by a certain business, company, etc. Some examples of ECM are Alfresco Software, Box platform, IBM Cloud Pak for automation, iManage, etc. Web Content Management (WCM) is the program that helps in maintaining, controlling, changing, and reassembling the contents on webpage. Some examples of WCM are WordPress, Adobe Express Manager, Drupal, etc.

In this blog, we are going to learn about installing WordPress on Ubuntu with LAMP stack. WordPress is web software that helps to create as well as manage websites, blogs, and applications. It is a free open-source blog hosting platform. This is one of the most used WCM in the world. It enables users to build any type of website they want and offers many customizations of the website. Furthermore, it also makes the users easier to move between systems (if they must) as it supports users to download content in XML format.

Prerequisites:

There are a few conditions that are necessary before we can begin with the installation of the WordPress and they are:

  • Ubuntu Server : You need to have a Ubuntu server.
  • sudo enabled user: In order to install and configure we will need a sudo user in the Ubuntu server.
  • Installation of LAMP stack : LAMP stack is the short abbreviation of Linux Operating System, Apache web server, MySQL and PHP.

Step 1 - Creating MySQL database

MySQL is a database management system and we need to have this package to manage and store sites and user information of WordPress. Since on the previous blog, we already installed MySQL, so we only need to have a user and a database for our WordPress website.

Now, we can being the configuration of MySQL. So, let’s get started:

Firstly, login in as the MySQL root account, for this run:

				
					mysql -u root -p
				
			

If the prompt says access denied, for this run:

				
					sudo mysql -u root
				
			

You will get access to the MySQL root user, now to update a new password for the root user, for this run:
(Change the Password to your own strong password that you would like.)

				
					ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'Password';
				
			

Exit the MySQL window and then Login to the root user, for this run:

				
					msql -u root -p
				
			

Now, we should be able to login to the MySQL user account. So, to create the database for the WordPress, run :

				
					CREATE DATABASE wordpress DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
				
			

Step2 - Create user for WordPress Database.

In order to access the database and have full control of the database, we will need a user within MySQL as we cannot always have and give access of the root user to other users. By creating specific user for our database, we will have a great help in management and security of the webpage. For this blog, I have used ‘wordpressuser’ as my username.(You can user any )

Now, to create a user for our database, run:

				
					CREATE USER 'wordpress'@'%' IDENTIFIED WITH mysql_native_password BY 'Password';
				
			

Since, we need all the access of the WordPress database for our WordPress user. We need to grant those access.
We also need to ensure that the changes that are made are implemented, so we need to flush the privileges. For all this run:

				
					GRANT ALL ON wordpress.* TO 'wordpressuser'@'%';
FLUSH PRIVILEGES;
EXIT;
				
			

Step3 - Installation of additional PHP extensions

In order to create a dynamic website and use dynamic functions for our website. One of the major components we need are PHP extensions. Basically, PHP extensions are compiled libraries that are installed in the PHP installation folder and we do not need to have PHP programming knowledge for creating websites in WordPress. However, we need to be aware of just the required extensions. When we configured LAMP stack no our Ubuntu server, we only installed the basic package for PHP so that PHP can communicate with our MYSQL. But in order for us to use WordPress we need to install various PHP extensions. For this, run:

(To update the local repository)

				
					sudo apt update
sudo apt install php-curl php-gd php-mbstring php-xml php-xmlrpc php-soap php-intl php-zip
				
			

This will install all the required plugins for the WordPress website. Now, we need to restart the apache2 server to load these new extensions. For this run:

				
					sudo systemctl restart apache2
				
			

Step4- Adjusting the Apache's configuration to allow for .htaccess overrides and rewrites

A server and a client communicates via the HTTP protocol and web server is responsible for the smooth and secure connection between the server and the client. There are mainly two popular web server: Apache and nginx. As in the previous blog, we have already installed Apache server, we will be using Apache server to host our WordPress.

Since, we only need to add the WordPress configuration file now. We will use /etc/apache2/sites-available/astroprolific.conf for our configuration file and /var/www/astroprolific/ as the root directory of our WordPress installation.

By default the use of .htaccess file is disabled. But since our WordPress uses this file in order to perform in-directory tweaks to the web server’s behavior. We will configure astroprolific.conf file, for this run:

				
					sudo nano /etc/apache2/sites-available/astroprolific.conf
				
			

Now, we enter the following block of text inside the VirtualHost block in the configuration file. We are basically setting ALLOWOVERRIDE directory within a DIRECTORY block which points to our root webpage folder which is /var/www/astroprolific.(It is your domain name folder.)

				
					<Directory /var/www/astroprolific/>
    AllowOverride All
</Directory>
				
			

Now, we need to enable the mod_rewrite so that we can utilize the WordPress permalink feature which allows us to create a more human-readable permalinks. For this run:

				
					sudo a2enmod rewrite
				
			

After this we need to see that if the config file has any syntax error or not, for this run:

				
					sudo apache2ctl configtest
				
			

The above message should appear.
The error that we see is due to not having entered our server name in the apache configuration file. This does not have any significance on our website or server, but if you want to avoid seeing this error. You can change the apache configuration and within it change the ‘ServerName’ to your domain name.

Again to implement all the changes above, we need to restart the apache2 service. For this run:

				
					sudo systemctl restart apache2
				
			

Now, the server’s configuration is done and we need to setup the WordPress.

Step5- Downloading WordPress

Finally, now we can begin the installation of the WordPress. As our server is now fully configured. Newer versions of WordPress usually comes up with new features and improved security, hence it is always advisable to use the latest version of WordPress.

We will be needing to download a few installation file which can be deleted later on after the installation is complete. So, navigating to temporary writable directory should be done.

Now, to download the configuration on the /tmp file, run:

				
					cd /tmp
curl -O https://wordpress.org/latest.tar.gz
				
			

Extract the compressed file, to do this run:

				
					tar xzvf latest.tar.gz
				
			

Now we will be moving these extracted file into our document root.Before we do that we can add a dummy .htaccess file so that this will be available for WordPress to use later, to do this run:

				
					touch /tmp/wordpress/.htaccess
cp /tmp/wordpress/wp-config-sample.php /tmp/wordpress/wp-config.php
				
			

To prevent WordPress running into permission issues we will create upgrade directory, for this run:

				
					mkdir /tmp/wordpress/wp-content/upgrade
				
			

Now we can copy the entire contents of the directory into our document root.

				
					sudo cp -a /tmp/wordpress/. /var/www/astroprolific
				
			

Step 6 - Configuring the WordPress Directory

We need to adjust some items in our WordPress directory. Firstly, we need to setup a reasonable file permissions and ownership. We will give ownership of all the files to the www-data user and group. This is the user that the Apache web server runs as, and Apache will need to be able to read and write WordPress files in order to server the website and perform automatic updates.

For this run:

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

Next, we will run two find commands to set the correct permissions on the WordPress directories and files. After this the WordPress should work effectively. For this run:

				
					sudo find /var/www/astroprolific/ -type d -exec chmod 750 {} \;
sudo find /var/www/astroprolific/ -type f -exec chmod 640 {} \;
				
			

Step 7 - Configuring the WordPress configuration file

To ensure a level of security for our installation, we need to able to adjust some secret keys. For this WordPress already provides a good security key generator which will be very convenient for us as well do not have to setup these values manually. So, first we need to grab the secure key values from the WordPress secret key generator, For this run:

				
					curl -s https://api.wordpress.org/secret-key/1.1/salt/
				
			

After this an output like this should appear:

The output that will be generate must be copied in the PHP configuration file. For this you can first copy the output in a dummy text file and then append the PHP configuration file as these output can be pasted anywhere in the wp-config.php file. The PHP configuration file is located at /var/www/astroprolific/wp-config.php.

After this we need to configure the PHP configuration file in order to connect to our database. For this run:

				
					nano /var/www/astroprolific/wp-config.php
				
			

The output must appear as shown in the image below, and in the configuration file change the name of database for WordPress, username and password according to your installation. After this is done, we can now install WordPress using the browser.

Now, we will continue installting the WordPress using the browser. In your browser when you enter the server’s IP. The installation window of WordPress should appear as shown below. Select your language of choice.

After choosing the language, you will be prompted to the another page ( as shown below) where you need to fill up the details of your site and WordPress. After filling up the details, click on Install WordPress.

After filling up the details. You will successfully have installed WordPress as it will show in the page below. Now, you can login to the WordPress using the credentials you have setup.

After, logging in with the credentials you have setup. You can view the dashboard as shown below.

Finally, You have successfully installed WordPress on LAMP stack.

Written By:

Vedant Agrawal

Founder,LD CLoud

Leave a Reply