Step 2: Setting up server for installation of source code

M
Muthurengan 6 years ago - Created

Since our source code is developed using PHP, we need to install Linux, Apache, MySQL, PHP (LAMP) stack on the server we created in Step 1. If you haven’t created a server yet visit Step 1: Creating a droplet in Digital Ocean.


1: Login to the Droplet

We will connect to the server with the SSH key we added to the server in Step 1.

Copy your IP address we created in Step 1. You’ll find your IP address here:


Enter the command below in your Terminal, substituting the your_server_ip with the IP address of your Droplet for and {path_to_serverkey} with the file path of the private SSH key we created earlier:

ssh root@your_server_ip -i {path_to_serverkey}

When done, it will look like this:

Hit EnterYou will be prompted to enter the passphrase we created while creating this private key. Enter the password and press Enter again.

If you are in Mac, you might be prompted to type your keychain password.

If everything went right, you will be logged in to the server and it will look like this:



2. Install Apache

Our next step is to install Apache. Type the following commands in the terminal:

sudo apt-get update
sudo apt-get install apache2

You will be prompted with a (Y/n). Type 'y' and press Enter.

You can do a spot check right away to verify that everything went as planned by visiting your server's public IP address in your web browser.

http://your_server_IP_address 

You will see the default Ubuntu 16.04 Apache web page, which is there for informational and testing purposes. It should look something like this:

You have now installed Apache web server successfully.


3. Install MySQL

Now that we have our web server up and running, it is time to install MySQL. MySQL is a database management system. Basically, it will organize and provide access to databases where our site can store information.

Type in the following commands into the Terminal:

sudo apt-get install mysql-server
You will be prompted with a (Y/n). Type 'y' and press Enter.

You will be prompted to enter a password for MySql. Enter a secure password and press Enter. Save this password. You will need this to login to your database.

You have now installed MySql database successfully.


4. Install PHP

PHP is the component of our setup that will process code to display dynamic content. It can run scripts, connect to our MySQL databases to get information, and hand the processed content over to our web server to display.

Step 1: Install PHP to server Type the following commands into the terminal:

sudo apt-get install php libapache2-mod-php php-mcrypt php-mysql
You will be prompted with a (Y/n). Type 'y' and press Enter.

This should install PHP without any problems.

Change the location of index.php

To do this, type this command to open the dir.conf file in a text editor with root privileges:

sudo nano /etc/apache2/mods-enabled/dir.conf

Inside of the file will look like this:

DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm

We want to move the index.php file above to the first position after the DirectoryIndex, like this:

DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm

When you are finished, Press Control + O to save.

And press Enter.

Then press Control + X to exit.

Enable URL beautification

sudo a2enmod rewrite
nano /etc/apache2/apache2.conf

Press the down arrow until you reach  {Directory  /var/www}

Change AllowOverride from "None" to "All".


Press Control + O to save. And press Enter. Then press Control + X to exit.

Restart the apache server by entering the following command in your terminal.

apachectl restart

You have now installed PHP successfully.


5. Install CLI and CURL

To do this, type the following command into your Terminal:

sudo apt-get install php-cli curl php-curl
You will be prompted with a (Y/n). Type 'y' and press Enter.

You have now installed CLI and CURL successfully.

6.Installing Laravel dependencies

sudo apt-get install php-mbstring php-xml
You will be prompted with a (Y/n). Type 'y' and press Enter.

7. Install Composer

Type the following command into your Terminal to install Composer globally:

curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer

You have now installed Composer successfully.


8. Install Node using NVM

Next, we install Node.js on the server so that we can run socket.io to enable real-time communication.

Type the following commands in the Terminal one by one:

sudo apt-get update
sudo apt-get install build-essential libssl-dev
You will be prompted with a (Y/n). Type 'y' and press Enter.
curl -sL https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh -o install_nvm.sh
bash install_nvm.sh
source ~/.profile
nvm install 6.3

You have now installed Node successfully.


If you have reached here successfully then you have finished setting up the server to deploy the source code. Visit Step 3: How to upload source code to the server to proceed to code deployment.

Was this article helpful?

2 out of 2 found this helpful

Articles in this section