In this article, we are going to set up and host the WordPress website in a fresh virtual machine.
Update VM
After creating a VM don’t forget to update and upgrade the machine.
sudo apt update && sudo apt upgrade
Create a Swap Partition
When a large program makes the entire system needs extra memory. A significant number of the pages used by these large programs during its startup may only be used for initialization and then never used again. The system can swap out those pages and free the memory for other programs or even for the disk cache. In these cases, swap will be used to help the system handle any extra load.
Please click here to create a swap partition.
Install LAMP Stack (Linux, Apache, MySQL, and PHP)
sudo apt install tasksel
sudo tasksel install lamp-server
sudo apt install php-curl php-gd php-mbstring php-xml php-xmlrpc
Configure Domain
- Add your domain in the host file /etc/hosts at the end. for example (ip_address example.com)
- Copy 000-default.conf from /etc/apache2/sites-available/ to example.com.conf in the same directory.
- Update ServerName and add ServerAlias.
a2dissite 000-default.conf // Disable default conf file.
a2ensite example.com.conf // Enable the new conf file (example.com.conf).
systemctl reload apache2 // Reload the server.
Create a Database
mysql -u root // Login to mysql as a root user.
CREATE DATABASE my_wordpress_db; // Create a database.
GRANT ALL ON my_wordpress_db.* TO 'my_wordpress_user' IDENTIFIED BY 'seper_secure_password'; // Grant permission to 'my_wordpress_user' user.
quit // To exit from mysql console.
mysql_secure_installation // Secure the installation.
Update PHP Upload Limits
Edit /etc/php/7.2/apache2/php.ini
Here I’m using PHP version 7.2. If you have installed any other version then replace 7.2 with the version you have installed.
upload_max_filesize = 5M // 5M -> 5 Mega bytes
post_max_size = 5M // 5m -> 5 Minutes
Install WordPress
Navigate to /var/www/html/
wget https://wordpress.org/latest.tar.gz // Download latest WordPress.
tar -xzvf latest.tar.gz // Extract the file in the same directory.
mv wordpress/* . // Move all the files from extracted wordpress folder to current (/var/www/html/) directory.
rm latest.tar.gz // Remove wordpress tar file.
rm -r wordpress/ // Remove empty wordress directory.
chown -R www-data:www-data /var/www/html/* // Change the permission.
Add database name, password, and user in the wp-config.php file.
Don’t forget to change the salts.
All done. Visit the site.
0 Comments