The use of Content Management System (CMS) has drastically changed the way content is published on the internet and allowed for the mushrooming of a lot of websites. Websites built with WordPress (a CMS) account for the majority of websites online that run using CMS. Because the history of WordPress is rooted on blogging, it makes content publishing relatively easy and straightforward.
By installing WordPress with LAMP (Linux, Apache, MySQL, and PHP) on your Ubuntu computer, you can work on your WordPress-based website before you launch it on the internet. This tutorial will teach you how to do so. Please note that some of the commands in this article have been grouped together to shorten the article. Thus, you will have to wait for some seconds for each line of command to finish processing.
1. Update and upgrade your Ubuntu system.
$ sudo apt update $ sudo apt upgrade
2. Install Apache and confirm that it is installed on your system.
$ sudo apt install apache2 $ systemctl status apache2
To further verify that the Apache installation is complete, go to your browser and enter the keyword localhost.
3. Install MySQL, and start and enable the MySQL service.
$ sudo apt-get install mysql-client mysql-server $ sudo systemctl start mysql.service $ sudo systemctl enable mysql.service
4. Secure the MySQL database server.
$ sudo mysql_secure_installation
You will be asked a series of questions, some of which have introductory sentences. Here are the answers:
Would you like to setup VALIDATE PASSWORD plugin? y
Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 2
New password: (Enter password)
Re-enter new password: (Repeat password)
Do you wish to continue with the password provided? : y
Remove anonymous users? : y
Disallow root login remotely? : y
Remove test database and access to it? : y
Reload privilege tables now? : y
5. Restart the MysqlSQL server service.
$ sudo systemctl restart mysql.service
6. Install PHP and the needed PHP extensions.
$ sudo apt install php libapache2-mod-php php-mysql $ sudo apt install php-curl php-gd php-xml php-mbstring php-xmlrpc php-zip php-soap php-intl
7. Make index.php and not index.html your default page.
$ sudo gedit /etc/apache2/mods-enabled/dir.conf
This will open a text editor with text that looks like the lines of code below:
<IfModule mod_dir.c> DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm </IfModule> # vim: syntax=apache ts=4 sw=4 sts=4 sr noet
Swap the positions of index.html and index.php and save the file.
8. Restart the Apache server.
$ sudo systemctl restart apache2
9. Check the directory /var/www/html.
The webpage that you see when you type in localhost in your browser has the file name index.html and is located in the directory /var/www/html.
10. Grant user permissions to /var/www/html and restart Apache.
$ sudo chown -R user /var/www/html $ sudo service apache2 restart
11. Confirm that PHP is installed on your Ubuntu computer.
Create a sample.php file in /var/www/html. Type the lines of code below as the content of sample.php:
<?php phpinfo(); ?>
Visit localhost/sample.php in your browser to check the result.
12. Create a database and a database user for WordPress, and grant user permissions to access the database.
$ sudo mysql -u root -p mysql> CREATE DATABASE wordpress_db; mysql> CREATE USER 'wordpress_user'@'localhost' IDENTIFIED BY 'password'; mysql> GRANT ALL ON wordpress_db.* TO 'wordpress_user'@'localhost' IDENTIFIED BY 'password';
Remember the database name, database username and password that you entered. You will be needing them later on.
13. Exit the database.
mysql> FLUSH PRIVILEGES; mysql> Exit;
14. Download and uncompress the latest WordPress file (The result is a folder called wordpress).
$ wget https://wordpress.org/latest.tar.gz $ tar -xvf latest.tar.gz
15. Copy the wordpress folder to the directory /var/www/html/.
$ cp -R wordpress /var/www/html/
16. Change ownership of and file permissions for the directory wordpress.
$ sudo chown www-data:www-data /var/www/html/wordpress/ $ sudo chmod -R 755 /var/www/html/wordpress/
17. Create an uploads directory and change its file permissions.
$ sudo mkdir /var/www/html/wordpress/wp-content/uploads $ sudo chown -R www-data:www-data /var/www/html/wordpress/wp-content/uploads/
18. Type localhost/wordpress in your browser and then go to the bottom of the resulting page and click on Let’s go!
19. Fill out the form with the information you filled in Step 12 (leave the Database Host and Table Prefix as they are). Click on Submit.
20. Next, you will be reading a page with a button that tells you to Run the installation. Click on that button.
21. The next page is a Welcome page.
It will ask you for some information related to your WordPress website (not your WordPress database). Fill in the boxes next to Site Title, Username, Password, and Email. Search Engine Visibility is only relevant if you’re working on your website online and you don’t want search engines to index your unfinished website. If you’re working on your local computer, you can leave this as is. Click on Install WordPress.
22. You will be greeted by a Success! page. Click on Log In.
23. You will be brought to the Log-in Page.
Input your WordPress username and password. Click on Log In.