WordPress is a popular content management software based on PHP programming language paired with MySQL or MariaDB database.
In this tutorial we will guide you on how to install Wordpress using the LAMP stack.
Let’s proceed with the steps on how to install WordPress on Ubuntu 20.04 with LAMP stack.
1. Installing PHP and PHP extension
First we need to install PHP and PHP extensions needed to run WordPress. To do that let us first update our system.
sudo apt update
Let us proceed with the PHP and PHP extensions installation.
sudo apt install php php-curl php-gd php-mbstring php-xml php-xmlrpc php-soap php-intl php-zip
2. Creating Database and Database user
In this step we will create a Database and Database user for our WordPress site. To do that we first we need to enter to the MySQL terminal.
mysql -u root -p
Let’s create a database.
MariaDB [(none)]> create database wordpress;
Let’s create a user and grant all privileges to the database wordpress.
MariaDB [(none)]> grant all privileges on wordpress.* to 'wordpress_user'@'localhost' identified by 'mypassword';
Please don’t forget to change ‘mypassword‘ to your desired password.
Let us save the chages we made and exit;
MariaDB [(none)]> flush privileges;
MariaDB [(none)]> exit;
3. Download WordPress
Now that PHP and MySQL is setup we will now download WordPress.
First we need to change directory.
cd /var/www/
Let us download WordPress.
wget https://wordpress.org/latest.tar.gz
Let’s extract the file.
tar -xvzf latest.tar.gz
Now we need to create an .htaccess file.
sudo touch /var/www/wordpress/.htaccess
Then open the .htaccess file.
sudo nano /var/www/wordpress/.htaccess
Add the following to the .htaccess file.
# BEGIN WordPress
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress
Then save and exit.
Let us change the ownership to the Apache user www-data.
chown -R www-data:www-data /var/www/wordpress/
Let us fix the permission of the WordPress directory. To do that run the 2 commands below.
sudo find /var/www/wordpress/ -type d -exec chmod 755 {} \;
sudo find /var/www/wordpress/ -type f -exec chmod 644 {} \;
The first command will find and set all directories to 755 and the second will look for all the files and set the permission to 644.
4. Creating Apache Virtual Host
Let us create a virtual host for our WordPress site.
sudo nano /etc/apache2/sites-available/wordpress.com.conf
Add the following on the wordpress.com.conf file.
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot /var/www/wordpress
ServerName domain.com
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /var/www/wordpress/>
Options +FollowSymlinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
Don’t forget to change the Servername directive to your domain.
Then save and exit.
Before we restart the Apache web server we need to enable the Apache mod_rewrite. To do that run this command.
sudo a2enmod rewrite
Now Let’s enable the virtual host we created.
sudo a2ensite wordpress.com.conf
Then restart the Apache webserver.
sudo systemctl restart apache2
5. Finalizing the WordPress Installation
Now that the Apache virtual host is setup you can now access your site to finalize the wordpress installation. To do that you need to open your Web Browser and access your site http://domain.com.
Choose your preferred Language then click continue.
Click Let’s go.
Provide the Database name, the Database Username, and the Database user password that we created in step 2 and just leave the Database host is the Table Prefix as it is then click submit.
Click Run the installation.
Fill up the forms and click Install WordPress.
Congratulation the installation was successful. Now you can start blogging.
Conclusion
You have learned how easy to install WordPress on Ubuntu 20.04 with the LAMP stack. If you like this article you might like also our article on Drupal.
If you have questions, feel free to leave a comment and we will try to answer it.
Thank you and hope you enjoy our tutorial ?