Linux for developer

Linux, like the idea was born in 1991. Linus Torvalds decided to write the core for the operating system with an open source license, which attracted many enthusiasts in this project, and later, large corporations, such as Google, Microsoft, Oracle, RedHat.

Today, the use of Linux and the software, that is installed with it, is very simple. It is enough to insert a disk with the distributive, click few buttons and wait.

But if you use a Linux for server, you must know how to install and configure the necessary components and software from the console.

In this article you will learn how to configure Linux as a Web server. All further explanations and examples will be based on the Debian distributive like Ubuntu.

Almost all companies that provide hosting services are selling a virtual server space where you can install the necessary components. This type of server is required if the project is not a standard, unless it is CMS, but something much more complex.

To use a standard web server, the following components needed: apache / nginx, php / php-fmp, mysql and other related software.

Installing Apache2+PHP+mysql

To install Apache2 + PHP + mysql, you must have root access (root), or a user who has installation rights. To install programs use a command line utility "aptitude", it is a package manager that allows you to set quickly the desired program. All programs can be downloaded from remote servers called repositories. If you properly set up aptitude, it downloads the required package and installs it. Therefore, before installing all the software it is necessary to update the repository with the command "apt-get update".

To install Apache2 you must perform the following command in the console "apt-get install apache2". This command sets the Apache2 web server and adds the necessary files from the default settings, adds the folder "/var/www/html" as the default page. Now you need to change the current settings to the ones you need.

Let's say the project has already been added to the server in the directory "/var/www/phpmyadmin". Also added to the new address in the DNS for the new project, for example, myadmin.mindteam.com.ua. To see your project on the “myadmin.mindteam.com.ua” adress - you need to configure virtual host for Apache2. This is done in the folder "/etc/apache2/sites-available /". Here you need to add a file "phpmyadmin.conf" and write following:

1. <VirtualHost *: 80>

2.       ServerName myadmin.mindteam.com.ua

3.       DocumentRoot / var / www / myadmin

4.       DirectoryIndex index.php

5.  

6.       ErrorLog $ {APACHE_LOG_DIR} /myadmin_error.log

7.       CustomLog $ {APACHE_LOG_DIR} /myadmin_access.log combined

8. </ VirtualHost>

 

You must then publish a setup project using the following command "a2ensite phpmyadmin.conf" and restart the server "service apache2 restart". The project will be available at the specified address afterwards.

Installing PHP

To install php must run "apt-get install php5 libapache2-mod-php5 php5-mcrypt" and "apt-get install php-cli", now you can run a project in php and use it to console commands.

Installing mysql

To install mysql, you must run "apt-get install mysql-server libapache2-mod-auth-mysql php5-mysql", when you install mysql will need to enter the password for the mysql administrator.

As can be seen from the written ebove, the  installation of apache2 + php + mysql is performed in  a very simple way. After installing and configuring the components of these programs -  the server is ready to use.

Nginx web server

Nginx web server appeared not so long time ago. In 2011, Igor Sysoev started a company Nginx, which is engaged in the development and support of this product. The main purpose of it is that with help of Nginx web servers for running big loads can be configured.

Together with Nginx is used process manager "php-fpm". This software does not work as a standard php. Php-fpm was created by Andrei Nigmatulin, who works on the project as a separate Badoo patch for use in this social networks. This approach will significantly simplify and speed up the work with php.

Installation and setup nginx+php-fpm

To install nginx you must run "apt-get install nginx", to install php-fpm - "apt-get install php5-fpm".

After you install nginx you need to add a virtual host, its principle is the same as for apache2, but with different syntax. To do this, go to the folder "/etc/nginx/sites-available /", to add the file "phpmyadmin.conf" with the following text:

  1. server {
  2.    listen 80;
  3.  
  4.    root / var / www / phpmyadmin;
  5.  
  6.    error_log /var/log/nginx/phpmyadmin.error.log;
  7.    access_log /var/log/nginx/phpmyadmin.access.log;
  8.  
  9.    server_name phpmiadmin.mindteam.com.ua;
  10.  
  11.   "rewrite ^/index\.php/?(.*)$ /$1 permanent;"
  12.  
  13.    location / {
  14.        index index.php;
  15.        try_files $ urirewriteapp;
  16.    }
  17.  
  18.    locationrewriteapp {
  19.        rewrite ^ (. *) $ /index.php/$1 last;
  20.    }
  21.  
  22.    location ~ ^ / (index) \. php (/ | $) {
  23.        fastcgi_pass unix: /var/run/php5-fpm.sock;
  24.        fastcgi_split_path_info ^ (. + \. php) (/.*) $;
  25.        include fastcgi_params;
  26.        fastcgi_param SCRIPT_FILENAME $ document_root $ fastcgi_script_name;
  27.        fastcgi_param HTTPS off;
  28.    }
  29. }

After restart the nginx using the "service nginx start". Now server is ready for use.

P.S. This article only describes the basic features of Apache and Nginx, in fact, these web servers have a lot of opportunities, which are available on the websites of the products.

Best regards,

Mind Team

Published at:11.08.2015