How to Install WordPress on Ubuntu
WordPress is a popular content management system (CMS), and installing it on an Ubuntu server is a straightforward process. This guide will walk you through the steps to install WordPress on Ubuntu.
1. Install Required Packages
First, make sure your system is updated.
sudo apt update
sudo apt upgrade
Then, install the necessary software packages, including Apache, MySQL, and PHP (LAMP stack):
sudo apt install apache2 mysql-server php libapache2-mod-php php-mysql
2. Install and Configure MySQL
After installing MySQL, you need to secure it and create a database for WordPress.
Run the MySQL secure installation script:
sudo mysql_secure_installation
Follow the prompts to set the root password and secure your database. Then, log in to MySQL as the root user:
sudo mysql -u root -p
Create a new database for WordPress:
CREATE DATABASE wordpress_db;
CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON wordpress_db.* TO 'wpuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;
Replace wordpress_db
, wpuser
, and password
with your desired database name, username, and password.
3. Install WordPress
Navigate to the Apache root directory and download WordPress:
cd /var/www/html
sudo curl -O https://wordpress.org/latest.tar.gz
Extract the WordPress files and change the ownership of the directory:
sudo tar -xvzf latest.tar.gz
sudo chown -R www-data:www-data wordpress/
sudo chmod -R 755 wordpress/
4. Configure Apache
Create an Apache configuration file for WordPress:
sudo nano /etc/apache2/sites-available/wordpress.conf
Add the following content to the file:
<VirtualHost *:80>
ServerAdmin admin@example.com
DocumentRoot /var/www/html/wordpress
ServerName your_domain_or_IP
<Directory /var/www/html/wordpress/>
AllowOverride All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Replace your_domain_or_IP
with your domain name or IP address. Then, enable the configuration file and the rewrite
module:
sudo a2ensite wordpress.conf
sudo a2enmod rewrite
sudo systemctl restart apache2
5. Configure the wp-config.php File
Navigate to the WordPress directory and copy the wp-config-sample.php
file:
cd /var/www/html/wordpress
sudo cp wp-config-sample.php wp-config.php
Open the wp-config.php
file and edit the database information:
sudo nano wp-config.php
Find the following lines and replace them with your database information:
define( 'DB_NAME', 'wordpress_db' );
define( 'DB_USER', 'wpuser' );
define( 'DB_PASSWORD', 'password' );
define( 'DB_HOST', 'localhost' );
6. Complete the WordPress Installation
You can now access WordPress through your browser. Open a web browser and enter your IP address or domain name:
http://your_domain_or_IP
You will see the WordPress installation interface. Choose your language and follow the prompts to complete the installation.
7. Secure WordPress
- Install SSL: You can install a free SSL certificate using Let’s Encrypt:
sudo apt install certbot python3-certbot-apache
sudo certbot --apache -d your_domain
- Regular Updates: Always keep WordPress and its plugins updated to ensure security.
Good luck with your WordPress installation on Ubuntu! If you have any questions, feel free to leave a comment.