Introduction
WordPress is a free and open-source content management system (CMS) with a plugin architecture and customizable themes. The PHP-based platform is usually paired with a MySQL or MariaDB database and was originally designed for publishing blogs. It is available for free and considered easy to install, configure, and uses. This article explains how to install WordPress on Ubuntu.
Prerequisites
- A root or non-root user with
sudo
privileges. - A Ubuntu LAMP stack includes the Linux operating system, the Apache web server, MySQL, and the PHP programming language.
If the LAMP stack is not installed, then just follow the below steps to install LAMP on Ubuntu.
Install Apache
- Run the below command on the terminal to install apache.
apt install apache2
- To confirm that Apache is installed on a system, run the following command.
systemctl status apache2
Install Mysql
- You can install MySQL on Ubuntu via this link How to install Mysql on Ubuntu
Install PHP
- Run the below command on the terminal to install PHP and its dependencies
apt install php php-mysql
- To confirm that PHP is installed, created an info.php file at the
/var/www/html/
pathvim /var/www/html/info.php
- Append the following lines
<?php
phpinfo();
?>Open a browser and append /info.php to the server’s URL
https://ip-address/info.php
Install WordPress
After fully configuring the LAMP. now the system is ready to install and configure the WordPress follow the below instruction to download and install WordPress.
- Run the below command on the terminal to download
WordPress
packages.wget https://wordpress.org/latest.tar.gz
- Run the following command to Uncompress the tarball which will generate a folder called
wordpress
.tar -xvf latest.tar.gz
- Copy the
wordpress
folder to the/var/www/html/
path.cp -R wordpress /var/www/html/
- Next, create a
wp-config.php
file by copying thewp-config-sample.php
file.sudo cp /var/www/html/wordpress/wp-config-sample.php /var/www/html/wordpress/wp-config.php
- Run commands to change file permissions of the
wordpress
folder.chown -R www-data:www-data /var/www/html/
chmod 755 -R /var/www/html/ - Create an ‘uploads’ directory.
mkdir /var/www/html/wordpress/wp-content/uploads
- change permissions of the ‘uploads’ directory.
chown -R www-data:www-data /var/www/html/wordpress/wp-content/uploads/
- Create WordPress Database.
WordPress uses MySQL to manage and store site and user information so need to create a database and user for WordPress.
-
Login into MySQL shell using the below command
mysql -u root -p
-
Create a database for a WordPress installation.
CREATE DATABASE wordpress;
-
Create a new database user and assign it a password
CREATE USER wordpressuser@localhost IDENTIFIED BY 'password';
-
Now, grant the user full rights to the new WordPress database.
GRANT ALL PRIVILEGES ON wordpress.* TO wordpressuser@localhost IDENTIFIED BY 'password'
- Flush the privileges
FLUSH PRIVILEGES:
- Exit from MySQL
exit
-
- After creating the database and user for WordPress configure the database details in the wpconfig.php file. Run the below command to open the
wp-config.php
file and update the DB_NAME, DB_USER, DB_PASSWORD fields as show in below image.
vi /var/www/html/wordpress/wp-config.php
- Next, access the wp-config file and update the database details.
- Restart the apache server.
systemctl restart apache2
- Open your browser and go to the server’s URL and replace "server-ip" with your system IP in the below URL.
https://server-ip/wp-admin
- Follow the on-screen instructions to create a WordPress user.
- Once the WordPress installation is complete, click on login to access your site’s administrative login page.
- Authenticate with the user credentials and start accessing WordPress.