Want live help from a dedicated Tech Agent?

Step 3: Setting up server for installation of source code

A
Ashwin 7 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.

Open the mysql conf file to rewrite port number with the following command.

sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf

Change the bind-address from the default value of 127.0.0.1 to 0.0.0.0

bind-address    =   0.0.0.0
sudo service mysql restart

4. Install PHP 7.0

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 php7.0 libapache2-mod-php php-mcrypt php-mysql php-gd php-bcmath
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.

You have now installed PHP successfully.


5. Enable short_open_tags

Open the php.ini file with the following command:

sudo nano /etc/php/7.0/apache2/php.ini

Scroll down and search for a line with text "short_open_tags = off" and change the status from "off" to "on".


short_open_tags = on

Scroll down and search for a line with text "upload_max_filesize = 2M" and change "2M" to "20M".

sudo service apache2 restart

Save this file by pressing Control + O.

Press Enter.

Close this close by pressing Control + X.


6. Enabling pretty URLs

Next, we need to enable pretty URLs by the following commands:

sudo a2enmod rewrite
sudo service apache2 restart
cd /etc/apache2
sudo chmod -R 777 .
sudo service apache2 restart
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.

sudo service apache2 restart

7. Install CLI and CURL

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

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

You have now installed CLI and CURL successfully.


8. 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.

You have to give full permission to html directory. Otherwise you will not be able to upload the source code to the server.

cd /var/www/html
sudo chmod -R 777 .

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

Was this article helpful?

15 out of 15 found this helpful

Articles in this section