How to Setup Your VPS Server for Centos, Apache, PHP 7.1 & MySQL


Setting up an unmanaged VPS server requires you to access your server in SSH and you have to type commands in order to install programs for your server. Unmanaged VPS usually don’t have a Cpanel when you purchase it either from Godaddy or Digital Ocean.

On this tutorial, we’re going to help you install your first VPS with Apache, the latest PHP 7.1, MySQL in a Centos OS. These are the basic component on building a website for your VPS. In the end we will also teach you how to setup free HTTPS for your website and optimize it using Google Pagespeed.

Before anything else, make sure your server installed the Centos OS to your server.

Connecting to VPS Server

Windows 10 also has a SSH features in the command prompt, you can use it by enabling the Developer Mode. Just search on Cortana “For Developer Settings”, then enable Developer mode. It requires a restart to use the SSH. Alternatively, you can use Putty to open SSH.

For this tutorial, we’re going to use the Windows’ SSH CMD to connect to our server. Now, connect to your server using CMD by the following command SSH your_username@your_vps_ipaddress_or_domain:

SSH codefaq@codefaq.org

It will ask you for a password. Just type your password and press ENTER.

From here, we have to use the root account of your vps – so that we don’t need to add sudo at start everytime we make commands. Type the following:

su -

It will ask you to enter your password again, just enter the password and we’re ready.

Downloading the latest updates for your Server

We need to updates all of the components for your server before we proceed. Type the following command to update your server:

yum update

Installing Apache

Now, let’s install the Apache in our VPS.

yum install httpd

Wait until the installation is complete, and we can now start the apache server.

systemctl start httpd

Installing MySQL

We can now install our MySQL database, this one requires you to download the official repository of MySQL. You can check the latest rpm at https://dev.mysql.com/downloads/repo/yum/

rpm -iUvh https://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm
yum -y install mysql-server

Wait until the installation is complete, and we can start the mysql server.

systemctl start mysqld

We have to get the default password of your MySQL, in order to get that we have to check the mysql log.

grep 'temporary password' /var/log/mysqld.log

Now you know the temporary password, we can now proceed on installing our mysql.

mysql_secure_installation

It will ask you for the temporary password, just enter it and enter your new password. The installation is self explanatory, so just choose the best fit for your preferences.

Installing PHP 7.1 from Webtatic

The latest PHP 7.1 is not officially available in default Centos repository. So we have to use this trusted 7.1 repository from Webtatic. First, we have to download the repository from webtatic.

rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
yum install php71w

After the installation is complete, we can now proceed on installing the rest of important php plugins.

yum install php71w-gd php71w-ldap php71w-mysqlnd php71w-odbc php71w-pear php71w-xml php71w-xmlrpc php71w-mbstring php71w-snmp php71w-soap curl curl-devel

We can now restart our apache server after the installation.

apachectl restart

Adding a Domain Name / Website to your VPS

Since we already have Apache, MySQL and PHP. We can now add your domain name to your VPS. Just follow the command below.

mkdir -p /var/www/yourwebsite.com/public_html
chown -R apache:apache /var/www/yourwebsite.com/public_html
chmod -R 755 /var/www/
vim /var/www/yourwebsite.com/public_html/index.html
mkdir /etc/httpd/sites-available
mkdir /etc/httpd/sites-enabled

After that, we have to include the sites-enabled directory to our apache configuration.

vim /etc/httpd/conf/httpd.conf

It will open the vim, it looks like a notepad in SSH. On the bottom add the following code.

IncludeOptional sites-enabled/*.conf

Now, save the file by pressing ESC from your keyboard, then typing this command:

:wq!

We can now add the site to sites-available directory. We need to create a conf file, do the command below.

vim /etc/httpd/sites-available/yourwebsite.com.conf

It will open again the vim program, now – write the following codes:

<VirtualHost *:80>
 ServerAdmin webmaster@yourwebsite.com
 ServerName www.yourwebsite.com
 ServerAlias yourwebsite.com
 DocumentRoot /var/www/yourwebsite.com/public_html
 ErrorLog /var/www/yourwebsite.com/error.log
 CustomLog /var/www/yourwebsite.com/requests.log combined
 </VirtualHost>

 

<Directory /var/www/yourwebsite.com/public_html>
 Options FollowSymLinks
 AllowOverride All
 </Directory>

Save the file by pressing ESC again and entering the:

:wq!

We need to link your website to the sites-enabled directory.

ln -s /etc/httpd/sites-available/yourwebsite.com.conf /etc/httpd/sites-enabled/yourwebsite.com.conf

Lastly, let’s create a index.html file to your website root directory to test your website.

vim /var/www/yourwebsite.com/public_html/index.html

It will open the vim program again and now enter any text. Example:

Welcome to my website! Awoo!

Save the file by pressing ESC again and entering the:

:wq!

Then we can now restart our apache server.

service httpd restart

Since your domain is now recognizable in your VPS. What you have to do now is edit the DNS Management of your domain, you can find this under your domain settings. By editing the Type A and adding the following values.

Host: @
Points to: Your_IP_Address_of_your_VPS
TTL: custom
Seconds: 600

The changes will took about 3 minutes or longer depending on the DNS traffic. Once its done, you can now visit your website in a browser. (eg. http://yourwebsite.com)

How to add free HTTPS for your website

There is a free certificate authority that we can use to have a free https in our website. That is Let’s Encrypt and it is available in epel repository in Centos and it can be use anytime.

Make sure, your website is now accessible in your browser before proceeding to this step. Now, Type the following command.

yum install epel-release
yum install mod_ssl python-certbot-apache
curl yourwebsite.com
certbot --apache -d yourwebsite.com -d www.yourwebsite.com
certbot renew
apachectl restart

Done! You have now a working VPS with Apache, PHP 7.1, MySQL and a free HTTPS. If you want to know how to install wordpress to your VPS, you can check our seperate article here.

Comments 0

Your email address will not be published. Required fields are marked *

How to Setup Your VPS Server for Centos, Apache, PHP 7.1 & MySQL

log in

Captcha!

reset password

Back to
log in
Choose A Format
Gif
GIF format