Installing WordPress on localhost or local development environment is pretty easy. With a decent up to date guide and stable internet connection it only takes 5 to 10 minutes really. It is fast to setup and can be really helpful at times.
You are thinking of starting a website with WordPress on the back end and wanna learn how to use WordPress or do all sorts of experiments then it is the perfect solution. Some people also work on their website while still being offline in the local environment first and then, later on, publish the site whenever it is ready.
But if you want to experiment with the code on your website or make any changes without messing with the live version then also you can move it easily to your local development environment. You get to mess it up without affecting anything, after all, it is just a local version.
There are different ways of installing WordPress like using WAMP(Windows Apache Mysql Php) stack, MAMP(Mac Apache Mysql Php) stack, LAMP(Linux Apache Mysql Php) stack etc.
And in this tutorial, I’m going to show you how to install WordPress on Ubuntu using the LAMP stack. But this tutorial should work for any other Linux distro too. Okay then open your terminal and get ready.
Enter the commands in your terminal or copy paste them.
$ wget wordpress.org/latest.zip
unzip the downloaded file.
$ unzip latest.zip
Copy the extracted WordPress folder to apache2 default root directory.
$ sudo cp -r wordpress /var/www/html/
Set the file permissions correct
Now change the file permissions and provide ownership to the apache2 user.
$ sudo chmod -R 755 /var/www/html/wordpress/ $ sudo chown -R www-data:www-data /var/www/html/wordpress/
Install and configure apache2 on your Ubuntu
Apache2 is a very popular, robust free and open source web server. You can install it via terminal with a single line of command. According to the man page of apache2 “apache2 – Apache Hypertext Transfer Protocol Server”
$ sudo apt-get install apache2
Enable the mod_rewrite module for the permalinks to work.
$ sudo a2enmod rewrite $ sudo service apache2 restart
After that go ahead and edit the apache2 config file to allow rewrite for the apache2 default apache2 root directory, where you recently copied the WordPress folder.
$ sudo nano /etc/apache2/apache2.conf
Scroll down until you find the following block of code and change the value of “Allow Override” to All form None:
<Directory /var/www/> Options Indexes FollowSymLinks AllowOverride None(#change this to All) Require all granted </Directory>
Install and configure MySQL database
Most probably you won’t be prompted to set the password for the MySQL root user but if prompted then go ahead and set a strong MySQL root user password. Mysql root password won’t matter much anyway because you can only access the root user via sudo and when you access the root MySQL user via sudo you can access it without any password.
$ sudo apt-get install MySQL-server MySQL-client $ sudo mysql_secure_installation
Press ‘n’ for the first prompt asking you to setup VALIDATE PASSWORD plugin because it can be a pain at times. If you install this plugin you won’t be able to set simple passwords for your MySQL users. I like to keep the passwords simple in the local environment but if you still want to install the plugin then go ahead and press ‘y’ it won’t do any harm.
It will prompt you to set a new password, enter a strong password and re-enter it again when prompted. This is the root password you are setting by the way. But it really won’t matter, You know why.
Press ‘y’ for the next prompt again ‘y’ for the next prompt too press ‘y’ and for the last time again press ‘y’.
After that login to MySQL and create a new database, user and then assign privileges of the newly created database to the newly created MySQL user.
$ sudo mysql -u root
You don’t need to enter the username and password and database name as me you can change them to whatever you want but if you are not familiar with MySQL commands then I suggest you set the username, password and database name same as me to avoid some complexity. Once you are familiar with the whole process then you can go ahead and change whatever variables you wish to change.
mysql> create database test; mysql> create user testuser@localhost identified by 'password'; mysql> grant all privileges on test.* to testuser@localhost; myslq> flush privileges; mysql> exit;
Install PHP and required PHP modules
Install PHP and some of its required modules. This command will install the latest available version of PHP and its modules.
$ sudo apt-get install php $ sudo apt-get install php php-mysql libapache2-mod-php php-cli php-cgi php-gd
Now that the LAMP stack is installed and properly configured we can begin the WordPress installation process.
Install WordPress on localhost
Open Firefox to begin the installation process.
- Enter “localhost/WordPress” in the address bar of the browser and press enter.
- Choose your preferred language and click on continue.
- Read whatever is shown in the next screen if you want to and press “let’s go!” button.
- Enter “Database Name” as test “Username” as testuser “Password” as password and then leave other fields as it is and press submit. If you set the different username, password or Database name in MySQL previously then enter that information instead.
- Click on “Run the installation” and enter the “Site Title”, “Username”, “Password”, “Your Email” as you wish and then finally click on “Install WordPress’ button.
- It will take a while to install the WordPress wait for it to complete and after installation is complete press the “Login” button and log in by entering the credentials you set earlier.
WordPress is now installed in your Ubuntu. you will need to visit localhost/WordPress to visit your locally hosted website in the future. Similarly, visit localhost/wordpress/wp-admin to go to the admin area or backend of the site.
So this is it for this article if you having any difficulties in installing WordPress on your Ubuntu then please feel free to comment down below I will be more than happy to help. I hope this was helpful. Have a good day.