In this post we will go through the steps for installing WordPress on Ubuntu locally. I have tested for WordPress 4.9 and Ubuntu 16.
Step-1: Install Apache Web Server
Type following commands in terminal:
$ sudo apt-get install apache2 apache2-utils $ sudo systemctl enable apache2 $ sudo systemctl start apache2
Test the webserver by opening the browser and enter the address:
You should see following in your browser:
Step 2: Install MySQL Database Server
Install MySQL database server by running the command:
$ sudo apt-get install mysql-client mysql-server
During the installation, you will be prompted to set the root user password for mysql as seen in the image below. Type in your password in field highlighted , then hit the OK button twice to proceed further.
Now issue the following command to harden database server security:
$ sudo mysql_secure_installation
You will be asked to install the ‘validate_password’ plugin, so type in Y/Yes and press Enter, and also choose the default password strength level.
Also if you do not want to change the root password, then type N/No when prompted to do so. Answer Y/Yes for the rest of the subsequent questions.
Step 3: Install PHP and Modules
Install PHP and a few other modules for it to work with the web and database servers using the command below:
$ sudo apt-get install php7.0 php7.0-mysql libapache2-mod-php7.0 php7.0-cli php7.0-cgi php7.0-gd
To test if php is working in collaboration with the web server, create a
info.php file inside /var/www/html.
$ sudo gedit /var/www/html/info.php
and paste following code into the file, save and exit.
<?php phpinfo(); ?>
Now open your web browser and type in the this address
http://server_address/info.php. You should be able to view the php info page below as a confirmation.
Step 4: Install WordPress
Download the latest WordPress package and extract it by issuing the commands below on the terminal:
$ wget -c http://wordpress.org/latest.tar.gz $ tar -xzvf latest.tar.gz
Then move the WordPress files from the extracted folder to the Apache default root directory, /var/www/html/:
$ sudo rsync -av wordpress/* /var/www/html/
Next, set the correct permissions on the website directory:
$ sudo chown -R www-data:www-data /var/www/html/ $ sudo chmod -R 755 /var/www/html/
Step 5: Create WordPress Database
Execute the command below and provide the root (created in step-2) user password, then hit Enter to move to the mysql shell:
$ mysql -u root -p
At the mysql shell, type the following commands, pressing Enter after each line of a mysql command. Remember to use your own, valid values for database_name, databaseuser, and also use a strong and secure password as databaseuser_password:
mysql> CREATE DATABASE own_database_name; mysql> GRANT ALL PRIVILEGES ON own_database_name.* TO 'own_databaseuser'@'localhost' IDENTIFIED BY 'own_databaseuser_password'; mysql> FLUSH PRIVILEGES; mysql> EXIT;
Now restart the web server and mysql service using the commands below:
$ sudo systemctl restart apache2.service $ sudo systemctl restart mysql.service
Open your web browser, then enter your server address:
http://localhost/wp-admin/setup-config.php to get the welcome page below. Click on “Let’s go!” to proceed further and fill all requested on screen information using above own values.
Login and enjoy WordPress on your system.
Note: If clicking your ‘Home’ link in your WordPress site takes you to Apache default page then copy
index.php from your /home/<your user name>/wordpress/ directory and paste it in /var/www/html/ (you may want to take backup before over-writing files here).