While I choose to develop for WordPress using LAMP there are alternatives such as MAMP, WAMP, XAMPP as well as services that provide a sandbox development environment such as Desktop Server and Local by Flywheel. This post only covers setting up WordPress using Ubuntu 20.04 Focal Fosa.
Installing WordPress for Local Development with LAMP
LAMP must be installed prior to these steps I enjoy using this old tutorial. However, package names for PHP and others are outdated, be sure use the latest packages available for Ubuntu 20.04 Focal Fosa.
Begin by creating a folder in your hosting environment
Feel free to substitute scratch for your own folder name.
cd /var/www/html/ sudo mkdir scratch cd scratch/
Download and expand an archive of the latest version of WordPress.
sudo wget -c http://wordpress.org/latest.tar.gz sudo tar -xzvf latest.tar.gz
After everything expands the files will be contained in a folder named wordpress. Now we can delete latest.tar.gz and move the files into our scratch folder then remove the wordpress folder itself.
Warning: This is a good time to warn you about the dangers of the rm command. It is a command to delete files, while superuser you can remove an entire directory and its contents so be sure you are in the scratch directory and targeting the correct wordpress folder.
sudo rm latest.tar.gz cd wordpress/ sudo mv * .. cd .. sudo rm -rf wordpress/
Setting folder permissions
This next couple commands will provide permission for WordPress to operate with read and write access in the scratch folder.
sudo chown -R www-data:www-data /var/www/html/scratch/ sudo chmod -R 755 /var/www/html/scratch/
Create a MySQL database for WordPress
sudo mysql -u root -p
Change your database name to match your naming convention. and use a unique and secure password in place of password used here.
CREATE DATABASE wp_scratch; CREATE USER 'scratch'@'localhost' IDENTIFIED BY 'password'; GRANT ALL PRIVILEGES ON wp_scratch.* TO 'scratch'@'localhost'; FLUSH PRIVILEGES; EXIT;
Configure Apache for WordPress
sudo vim /etc/apache2/apache2.conf
Editing the apache2.conf file to allow pretty permalinks.
<Directory /var/www/html/scratch/> Options Indexes FollowSymLinks AllowOverride All Require all granted </Directory>
Run the following commands in the terminal to finish setting up Apache and then restart it along with MySQL
sudo a2enmod rewrite sudo systemctl restart apache2.service sudo systemctl restart mysql.service
If everything worked correctly you now have a localhost ready for WordPress development in using LAMP.
Visit http://localhost/scratch/ or the folder you used in place of scratch to complete the WordPress setup using the information you provided to MySQL.
Warning: If this server is intended to be used in a production environment use secure and unique passwords.