
Setting up a WordPress website requires a web server, a database, and a scripting language. This combination is commonly known as a LAMP stack when using Linux, Apache, MySQL, and PHP. This guide will walk you through installing the latest WordPress version with a LAMP stack on Ubuntu 20.04.
Before you begin, ensure you have a non-root user with sudo privileges configured on your Ubuntu server.
Step 1: Update System Packages
Always start by updating your system’s package list and upgrading existing packages to their latest versions. Open your terminal and run:
sudo apt update
sudo apt upgrade -y
This ensures you have the latest software and security patches.
Step 2: Install Apache Web Server
Apache is the most popular web server for hosting websites. Install it by running:
sudo apt install apache2 -y
After installation, Apache should start automatically. You can check its status:
sudo systemctl status apache2
The output should show active (running)
. To allow web traffic, you need to open ports 80 (HTTP) and 443 (HTTPS) in your firewall. Assuming you are using UFW (Uncomplicated Firewall), enable the ‘Apache Full’ profile:
sudo ufw allow ‘Apache Full’
sudo ufw enable
sudo ufw status
You should now be able to see the default Apache welcome page by navigating to your server’s IP address in a web browser.
Step 3: Install MySQL Server
MySQL is a robust database management system needed to store WordPress data. Install the server package:
sudo apt install mysql-server -y
For a fresh MySQL installation, it’s highly recommended to run the security script to improve security:
sudo mysqlsecureinstallation
This script will prompt you to set a root password, remove anonymous users, disallow root login remotely, and remove the test database. Answer Y
for the prompts to enhance security.
Step 4: Install PHP and Required Modules
PHP is the scripting language that WordPress is built upon. Install PHP along with necessary modules for interacting with Apache and MySQL:
sudo apt install php libapache2-mod-php php-mysql php-cli php-curl php-gd php-intl php-json php-mbstring php-soap php-xml php-xmlrpc php-zip -y
After installation, restart Apache to ensure the PHP module is loaded:
sudo systemctl restart apache2
To verify PHP is working correctly, you can create a simple test file in the Apache webroot directory (/var/www/html
):
sudo nano /var/www/html/info.php
Add the following content to the file:
phpinfo();
?>
Save and close the file. Now, visit http://your_server_ip/info.php
in your browser. You should see a page displaying your PHP configuration details. Remember to remove this file after testing as it can expose sensitive information.
sudo rm /var/www/html/info.php
Step 5: Create a MySQL Database and User for WordPress
WordPress requires a database to store its content, user information, settings, and more. Log in to the MySQL shell as the root user:
sudo mysql
You will be prompted for the MySQL root password you set earlier. Inside the MySQL prompt, create a database for WordPress (replace wordpress_db
with your desired database name):
CREATE DATABASE wordpressdb DEFAULT CHARACTER SET utf8 COLLATE utf8unicode_ci;
Next, create a database user and grant them privileges on the new database. Replace wordpress_user
and your_strong_password
with your desired username and a strong password:
CREATE USER ‘wordpressuser’@’localhost’ IDENTIFIED WITH mysqlnativepassword BY ‘yourstrongpassword’;
GRANT ALL PRIVILEGES ON wordpressdb.* TO ‘wordpress_user’@’localhost’;
Apply the changes and exit the MySQL shell:
FLUSH PRIVILEGES;
EXIT;
Step 6: Download and Configure WordPress
Download the latest version of WordPress from the official website:
cd /tmp
wget https://wordpress.org/latest.tar.gz
Extract the downloaded archive:
tar -xvzf latest.tar.gz
Now, move the extracted WordPress files to the Apache webroot directory. It’s best practice to use a subdirectory, especially if you plan to host other sites. We’ll use /var/www/html/wordpress
:
sudo mv wordpress /var/www/html/
Set the correct permissions for the WordPress directory so Apache can access the files. The web server user (www-data
on Ubuntu) needs ownership:
sudo chown -R www-data:www-data /var/www/html/wordpress
sudo chmod -R 755 /var/www/html/wordpress
Step 7: Configure Apache Virtual Host for WordPress
To serve WordPress correctly, create an Apache virtual host configuration file. This tells Apache where to find the WordPress files and how to handle requests for your domain or IP.
Create a new configuration file:
sudo nano /etc/apache2/sites-available/wordpress.conf
Add the following configuration. Replace your_domain_or_server_ip
with your server’s domain name or IP address.
ServerAdmin webmaster@localhost
ServerName yourdomainorserverip
DocumentRoot /var/www/html/wordpress
AllowOverride All
Order allow,deny
allow from all
ErrorLog ${APACHELOGDIR}/error.log
CustomLog ${APACHELOGDIR}/access.log combined
Save and close the file. Now, enable the virtual host and the Apache rewrite module (needed for WordPress permalinks):
sudo a2ensite wordpress.conf
sudo a2enmod rewrite
Disable the default Apache site:
sudo a2dissite 000-default.conf
Finally, test the Apache configuration for syntax errors and reload the Apache service:
sudo apache2ctl configtest
sudo systemctl reload apache2
Step 8: Complete WordPress Installation via Web Browser
You are now ready to complete the WordPress installation through its web interface. Open your web browser and navigate to your server’s domain name or IP address (http://your_domain_or_server_ip
).
You should see the WordPress setup page. Follow the on-screen instructions:
- Select your language and click Continue.
- Click Let’s go! on the welcome screen.
- Enter your database details:
- Database Name:
wordpress_db
(or whatever you named it) - Username:
wordpress_user
(or whatever you named it) - Password:
your_strong_password
(the password you set) - Database Host:
localhost
- Table Prefix: You can leave this as
wp_
or change it for security.
- Database Name:
- Click Submit.
- If the connection is successful, click Run the installation.
- Provide your site title, create an administrator username and password, enter your email address, and choose whether to discourage search engines from indexing your site (you’ll likely want this unchecked for a live site).
- Click Install WordPress.
Once the installation is complete, you will see a success message and can log in to your WordPress dashboard.
Congratulations! You have successfully installed the latest version of WordPress with a LAMP stack on your Ubuntu 20.04 server. You can now start building your website.
Source: https://kifarunix.com/install-latest-wordpress-with-lamp-stack-on-ubuntu-20-04/