If you’re looking to experiment with WordPress, develop a custom theme, or test plugins before launching a live site, setting up WordPress locally on your Ubuntu machine is a great option. Running WordPress on your local machine allows you to make changes without worrying about breaking a live site, and it’s an ideal environment for learning and development.
Run a quick update by running the following command in a terminal window before installing Apache Server.
sudo apt update
sudo apt upgrade
Install the Apache Server.
sudo apt install apache2
Enable Apache Server to start on boot and start the service:
sudo systemctl enable apache2
sudo systemctl start apache2
Install MYSQL Server.
sudo apt install mysql-server
Secure MYSQL installation.
sudo mysql_secure_installation
Follow the prompts to set a root password and secure your MySQL installation.
- Enter
2
to select strong password - Enter
y
to remove anonymous user - Enter
y
to disallow root login remotely - Enter
y
to remove test database and access to it - Enter
y
to reload privilege tables now
Log in to the MySQL.
sudo mysql -u root -p
Create a database and user for wordpress.
CREATE DATABASE wordpress;
CREATE USER 'larry'@'localhost' IDENTIFIED BY 'your_strong_password';
GRANT ALL PRIVILEGES ON wordpress.* TO 'larry'@'localhost';
FLUSH PRIVILEGES;
EXIT;
Install PHP and Necessary PHP Extensions.
sudo apt install php libapache2-mod-php php-mysql php-cli php-curl php-gd php-mbstring php-xml php-xmlrpc php-zip
Navigate to the ‘/tmp
‘ folder and download latest WordPress by running the following command.
cd /tmp
wget https://wordpress.org/latest.tar.gz
Extract the WordPress archive.
tar -xzvf latest.tar.gz
Move the extracted files to the Apache web directory.
sudo mv wordpress /var/www/html/
Set the appropriate ownership and permissions.
sudo chown -R www-data:www-data /var/www/html/wordpress
sudo chmod -R 755 /var/www/html/wordpress
Create an Apache configuration file for WordPress.
sudo nano /etc/apache2/sites-available/wordpress.conf
Add the following configuration.
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot /var/www/html/wordpress
ServerName example.com
ServerAlias www.example.com
<Directory /var/www/html/wordpress/>
Options FollowSymlinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Save the file by pressing ctrl x then y.
Enable the WordPress site and the rewrite module.
sudo a2ensite wordpress.conf
sudo a2enmod rewrite
sudo systemctl reload apache2
sudo systemctl restart apache2
Open your web browser and navigate to http://localhost/wordpress
then select your language (e.g. English
) and click Continue.
Click Let’s Go.
Enter the database details.
- Database Name:
wordpress
- Username:
larry
- Password:
your_strong_password
- Database Host:
localhost
- Table Prefix:
wp_
Click Submit.
Click Run the Installation.
Enter your WordPress Site Title
, Username
, Password
, and Your Email
then click Install WordPress.
You’ve now installed and configured WordPress on your Ubuntu server.
Enter your Username and Password then click Log In.
You can now customize your site.