Installing Apache Mysql on Centos Ubuntu and creating WordPress website

Installing Apache Mysql on Centos Ubuntu and creating WordPress website

Installing Apache Mysql on Centos Ubuntu and creating WordPress website Once you got the Server or VPS, Login to the server through SSH using a the tool called putty. Once you have logged in. type in the below command. For CentOs : Installing Apache with Mysql support

server@root # yum install httpd php php-mysql

For Ubuntu

sudo apt-get install httpd php php-mysql

Set the Apache service to start automatically when you restart.

server@root # chkconfig httpd on
server@root # service httpd start

Start the Apache server by service httpd start or /etc/init.d/httpd start Now, we need to install mysql server

server@root # yum install mysql-server

On Ubuntu

sudo apt-get install mysql-server

Set the Mysql service to start automatically when you restart.

server@root # chkconfig mysqld on
server@root # service mysqld start

Start the Mysql server by service mysqld start or /etc/init.d/mysqld start Once the Apache Webserver and MySql server is installed and started. We need to configure it. Now, Preparing the Apache Web Server. Its simple, if you want to load WordPress or any other script through the IP Address, Just upload the files to /var/www/html and proceed to the MySql configuration process. If you want to host a website and load through a website or domain name. follow the below steps. Just edit the httpd.conf file using nano text editor.

server@root # nano /etc/httpd/conf/httpd.conf

Go to very bottom of the configuration file and add this below lines and replace your domain name instead of

  ServerAlias *
  ServerAdmin [email protected]
  ErrorLog /var/log/httpd/error_log
  CustomLog /var/log/httpd/example.log combined
  DocumentRoot /var/www/
    <Directory "/var/www/">
     Order allow,deny
     Allow from all

or you can also create a file called at the path /etc/httpd/conf.d/ and paste the above details and save it. Once done, Just restart the Apache server by service httpd restart now, you can access the website through your domain name, eg. The Apache setup is complete. We will now prepare the Mysql server. MySql server is installed with no root password set. We will now secure the mysql installation and its sooo easy. Just type : mysql_secure_installation

server@root # mysql_secure_installation

follow the setup steps after you enter the above command. Just press enter on the first prompt, enter the mysql root users password now. we will now login to the mysql server by below command. after you complete the mysql server secure setup.

server@root # mysql -u root -p

Once you logged in with MySQL root password, We need to create database for wordpress installation:


Now wee need to create a new user.

CREATE USER 'databaseuser'@'localhost' IDENTIFIED BY 'userpassword' ;

change userpassword with your own pass code. Use Strong Password Generator to get a secure password here Now, we are going to provide PRIVILEGES to the dbuser on the database we created.

GRANT ALL PRIVILEGES ON exampledb.* TO databaseuser@localhost IDENTIFIED BY 'userpassword'; 

and also flush the privileges


Now, type exit to come out of the mysql prompt. Preparing the WordPress Script to install. Downloading the WordPress Installation Files.

server@root # cd /var/www/
server@root # wget
server@root # unzip

Here, You may get an error like below

server@root # wget
Connecting to||:443... connected.
ERROR: certificate common name `*' doesn't match requested host name `'.
To connect to insecurely, use `--no-check-certificate'.

To Resolve the issue, Just add –no-check-certificate at the end of the wget command. eg: wget –no-check-certificate

server@root # wget --no-check-certificate

Now, You will see a folder called wordpress.

cd wordpress mv -Rf * /var/www/

This two lines command will move the wordpress files from /wordpress to main domain folder. make sure you change the path with yours. Now, Copy the sample wordpress config file “wp-config-sample.php” from the wordpress directory to “wp-config.php”

server@root # cd /var/www/
server@root # cp wp-config-sample.php wp-config.php

Edit the the file wp-config.php using nano text editor.

server@root # nano /var/www/

You will find this below details on the php file, make sure you update with your mysql credentials. /** The name of the database for WordPress */ define(‘DB_NAME’, ‘WordPressdb’); /**MySQL database exampledb */ define(‘DB_USER’, ‘databaseuser’); /** MySQL database password */ define(‘DB_PASSWORD’, ‘userpassword’); Save it by Pressing “CTRL + O” and Exit by Pressing “CTRL + X“. Now, access the wordpress URL, http://youripaddress/wp-admin/install.php or OPTIONAL : Set the permissions on the installation directory. First, switch in to the web directory: server@root # cd /var/www/ Give ownership of the directory sudo chown www-data:www-data * -R sudo usermod -a -G www-data username If this guide helpful, help us sharing this to your friends in need of help.


This site uses Akismet to reduce spam. Learn how your comment data is processed.