Saturday, June 10, 2017

How To Install WordPress, Apache, MySQL and PHP on Ubuntu 16.04

In this post I will show, how to install WordPress, Apache, MySQL and PHP on Ubuntu 16.04.

Install Apache:

When you’re done installing Apache2, the below commands allow you to start it up

sudo apt-get update
sudo apt-get install apache2

sudo systemctl start apache2
sudo service apache2 start
If you you are using Nginx you may get the below ERROR:
Address already in use: AH00072: make_sock: could not bind to address [::]:80
Then GO to /etc/apache2/ports.conf

and change Listen 80 to Listen 8090 using below command

sudo vim  /etc/apache2/ports.conf
open browser and enter http://localhost:8090
The below commands allow you to restart it and enable it to startup everytime you reboot your systems.

sudo systemctl restart apache2
sudo systemctl enable apache2

Install MySQL:

sudo apt-get install mysql-server mysql-client libmysqlclient-dev

During MySQL database server installation, you’ll be prompted to create a root password.. This password enables the root users to administer MySQL server.
After installing MySQL database server, the commands below allow you to start it up, restart it and enable it so that it starts up automatically everytime you reboot your servers.

sudo systemctl start mysql
sudo service mysql start
sudo systemctl restart mysql
sudo systemctl enable mysql
After running the above commands and installing MySQL, run the commands below to configure it.

sudo mysql_secure_installation
When prompted, choose Yes or No accordingly until you’re done.

mysql -u root -p
CREATE USER DBName@localhost IDENTIFIED BY 'new_password_here';
GRANT ALL ON DBName.* to DBName@localhost;
Install PHP:

sudo apt-get install php libapache2-mod-php php-mcrypt php-mysql
sudo apt-get install php libapache2-mod-php php-mysql php-curl php-gd php-intl php-pear php-imagick php-imap php-mcrypt php-memcache php-ming php-ps php-pspell php-recode php-sqlite3 php-tidy php-xmlrpc php-xsl
Ones PHP is installed, check the installed version

php --version
to get full details regarding php, create index.php as shown

sudo vim /var/www/html/index.php
Execute the above command and paste the below code in it and save the file by pressing Esc+:wq


// Shows all information regarding PHP, Apache server, MySQL and Default enabled/Installed Modules of PHP


Use below url to execute the file
To make PHP files as default use below command to change

sudo nano /etc/apache2/mods-enabled/dir.conf
Move index.php to begining as shown below

<IfModule mod_dir.c>
    DirectoryIndex index.php index.html index.cgi index.xhtml index.htm
Now restart apache and execute the url http://localhost:8090/

sudo systemctl restart apache2
sudo service apache2 restart
To Install Additional PHP modules

sapt-cache search php- | less
For example to install additional cli module

sudo apt-get install php-cli

Install WordPress:
Download latest WordPress from
unzip the above downloaded wordpress and copy in /var/www/html/ folder with the below command.

sudo tar -xvzf /home/vara/Downloads/wordpress-4.8.tar.gz -C  var/www/html/
go to localhost:8090/wordpress if every thing is working it will redirect to http://localhost:8090/wordpress/wp-admin/setup-config.php thren press let's go! button and provide mysql details.

You may get the below error

Sorry, but I can’t write the wp-config.php file.
You can create the wp-config.php manually and paste the following text into it.

sudo chmod -R 777 /var/www/html/wordpress

Provide the required details and install wordpress.

No comments:

Post a Comment