Configuring VPS server with Ubuntu 12.04


 

The first thing we need is to install and configure the Web server. I choose Apache, he worked for many years on my home computer,I like it. Install will not only Apache but also PHP, MySQL, phpMyAdmin:

 

If we are not under root-user, enter in the console root, not to write before each command sudo if under root, then immediately to paragraph 1:
sudo su
From ruta we went and stayed our folder, so write cd (version cd/root is not supposed to work):
CD
Update the list of repositories:
apt-get update
Install Apache2, php, mysql, phpmyadmin and a text editor Nano (further examples will be using it, if it is not necessary to remove the last word of the command):
apt-get install apache2 apache2-mpm-prefork apache2-utils apache2suexec php5 php5-mysql libapache2-mod-php5 curl libcurl3libcurl3-dev php5-curl php5-mcrypt php-pear php5-gd sendmail mysql-server mysql-client libmysqlclient15-dev phpmyadmin nano
By the way, delete it all can be just one command:
apt-get purge apache2 apache2-mpm-prefork apache2-utils apache2suexec php5 php5-mysql libapache2-mod-php5 curl libcurl3libcurl3-dev php5-curl php5-mcrypt php-pear php5-gd sendmail mysql-server mysql-client libmysqlclient15-dev phpmyadmin nano
Since established in addition to Web server and php, mysql, phpmyadmin, restart Apache:
Service apache2 restart

 

Now configure phpMyAdmin. Live it we will have on the IP 127.0.1.1 (can be set to any other).

 

If you missed the first block, then there we have installed phpMyAdmin bundled with other programs. To install phpMyAdmin, enterin the console as rootuser:
apt-get update
then
apt-get install phpmyadmin
and for further work set the text editor Nano
apt-get install nano
Open a console editor Nano and create a new file:
Nano/etc/apache2/sites-available/phpmyadmin
Insert the following text:
< VirtualHost 127.0.1.1:80 >
Servername localhost
DocumentRoot/usr/share/phpmyadmin
Serveradmin webmaster@localhost.loc
Errorlog/var/log/apache2/error.log
CustomLog/var/log/apache2/access.log combined
</VirtualHost>

 

And exit the editor. To do this, press Ctrl + X, y to save the file, and then press Enter to confirm the address of the file to be saved.
Allow (turn) this virtual host:
a2ensite phpmyadmin
ban (disable) the host command
a2dissite phpmyadmin
Restart Apache:
Service apache2 restart
Because our phpMyAdmin is only available from the server, access from the Internet is denied the first line of the file created in step 2, then add a beautiful address: http://phpmyadmin/. To do this, open the/etc/hosts file:
Nano/etc/hosts
and at the beginning or end of the file add the line:
127.0.1.1 phpmyadmin
For file navigation buttonsbuttons and arrows Page Up (PgUp) and Page Down (PgDn), Home and End. To exit the editor, press Ctrl + X, y to save the file, and then press Enter to confirm the address of the file to be saved.
Now, phpMyAdmin is available at http://phpmyadmin/.
Completely forgot: Northern Ubuntu no screen. So now install desktopnuû version of Ubuntu and configure VNC. If you have and sothe Ubuntu desktop, scroll further.
To begin, install Ubuntu Desktop, remember, all actions should be done under the root user:
apt-get install ubuntu-desktop
Depending on the ingenuity of your VPS, connection speed and how stars are in the sky, this process may take from several minutes to several hours, in theory, in practice, I managed to setup time only make coffee.
The installation process will be asked about the language and keyboard layout, as well as on how to switch layouts. The samequestion might arise (or several) to change those or other system packages, agree (press y).
Install graphical environment GNOME:
apt-get install gdm if the server is not powerful, when the question, choose lightgdm (when you run will be the only console). Ifpowerful, you can choose the gdm (at startup will console and a full desktop), but why ship Server redundant?
Launch the GUI:
/etc/init.d/gdm start
Now you need to configure VNC server and VNCclient:
Let’s start with the server. Install:
apt-get install vnc4server
Run:
vncserver: 1geometry 1366 x 768-depth 16pixelformat rgb565
You can substitute any screen resolution, in the example above, is convenient to me, here is an example for 1024 × 768:
vncserver: 1geometry 1024 x 768-depth 16pixelformat rgb565
After the first launch the program you will prompt you to enter a password to access the VNC server. To change the password using the vncpasswd
To stop a VNC server, use the command vncserverkill: 1
It is advisable to run a VNC server not from ruta, and from any other user.
Add GNOME to run together with the launch of the VNC server:
Nano ~/.vnc/xstartup
and add at the end of the file:
GNOME-session &
For file navigation buttonsbuttons and arrows Page Up (PgUp) and Page Down (PgDn), Home and End. To exit the editor, press Ctrl + X, y to save the file, and then press Enter to confirm the address of the file to be saved.
Now on your home computer, install the program and run the UltraVNC. Enter the IP of your VPS and port 5901 185 format. *. *. *:5901, if the VNC server is found, you are prompted for a password, enter the password and get Visual access to your server.
To access the address http://phpmyadmin/in the console enter firefox and press Enter. Enter http://phpmyadmin/in the address barand if everything is configured correctly, we see the following picture:
Let us now change the security settings. You can do everything and zprivedënnogo below. For example, leave the root user, butchange the port. However, this may not affect security.
First, we create a user with the nickname harder to replace Ruth:
useradd user0
where user0 as Nick the new user. Set password, answer questions (can be skipped by pressing the Enter key a few times.
Give our user administrator privileges. To begin, add it to the Group sudo:
useradd user0 sudo
And to eliminate possible problems will collect in the console
visudo is
and at the end of the opened file add
user0 ALL = (ALL) ALL
where user0 as Nick the new user.
Change the port for SSH and ban user root to connect to the SSH server, to do this, open the file/etc/ssh/sshd_configcommand/etc/ssh/sshd_config nano.
We find in it a line Port 22, will replace 22 on anything from 2 up to 4 digital characters, for example at 3133.
In the same file, find the line PermitRootLogin yes, replace yes on no.
Allow user with Nick user0 connect via SSH. To do this, add the following line AllowUsers user0. If you do not add this line, you can stay without SSH access after the next step.
For file navigation buttonsbuttons and arrows Page Up (PgUp) and Page Down (PgDn), Home and End. To exit the editor, press Ctrl + X, y to save the file, and then press Enter to confirm the address of the file to be saved.
In the same way you can do this via WinSCP, through it more convenient to work with long files.
Restart SSH:
Service ssh restart
or maybe so:
/etc/init.d/sshd restart
Now all commands are executed only through unauthorised user, in this case user0. That would be from this user to execute commands as root from either before work writing sudo su and cd (Ruta” exit mode) or before each write command sudo
We will use VPS for hosting the site and still haven’t set no host for the site. Virtual host configuration we have, when configuringphpMyAdmin. Now determine where your server files will be stored in the/var/www/folder or user site.ru/home/user0/site.ru whereuser0site.ru user name is the name of the domain. The example below uses the second method.
Open a console editor Nano and create a new file:
Nano/etc/apache2/sites-available/site.ru
Insert the following text:
Instead of the user name box, type user0 site.ru substitute your domain if multiple domains, then fill the ServerAlias (replace site2.ru),so instead of webmaster@localhost.loc you can enter your e-mail. Be sure to check that the first line was not an IP address (for example, 127.0.0.1:80), and asterisk (*: 80), otherwise the site will not be accessible from the Internet. Exit the editor. To do this, pressCtrl + X, y to save the file, and then press Enter to confirm the address of the file to be saved. For file navigation buttonsbuttons andarrows Page Up (PgUp) and Page Down (PgDn), Home and End.
Slightly corrected the hosts file. Add to it the local IP 127.0.0.1, the address of our new site alias (second, third, etc. domain), you can optionally specify another address, which will be available only from the server, for example. To do this, open the/etc/hosts file:
Nano/etc/hosts
and at the beginning or end of the file add the line:
127.0.0.1 site.ru site2.ru site
Now create a folder/home/user0/site.ru:
mkdir/home/user0/site.ru
Allow (turn) this virtual host:
a2ensite site.ru
ban (disable) the host command
a2dissite site.ru
Update the Apache configuration:
Service apache2 reload
either restart
Service apache2 restart
You can now upload files to the site directory. For this purpose we use WinSCP. The program is very simple, so any tips on workingwith it giving will not.
FTP. This is a separate issue. The whole epoch in those three letters. So I didn’t bother her to include in the first section. I FTP neverneeded, everything was uploaded via WinSCP. However, sometimes this morally obsolete Protocol still needed. For example, toupdate and install WordPress plugins.
From ruta in the console write:
apt-get install proftpd
During installation you are prompted From inetd or Standalone choose the Standalone.
In fact it’s all🙂 You can contact the server by IP with an indication of the FTP protocol. For example, if the server requestedftp://127.0.0.1 login and password, then everything is OK. The FTP server is started automatically after the installation and usesUbuntu users, IE any user except the root, can now connect to the server via FTP and all these users will fall into the same folder/srv/ftp. I was not satisfied, so I fixed/etc/proftpd/proftpd.conf file:
Nano/etc/proftpd/proftpd.conf
I found this file line:
# DefaultRoot ~
and raskommentil it (removed the # at the beginning of the line). Now a few words about this line. If it is commented out, then when you connect any user uses a different default path (that’s/srv/ftp). If this line does not have a hash (#) at the beginning and as thetilde (~) character is specified, then the user when connecting to the server gets into your home folder. You can also specify a shared folder for all users, for example,/var/www. To do this, this string should take the following form: # DefaultRoot/var/www
For file navigation buttonsbuttons and arrows Page Up (PgUp) and Page Down (PgDn), Home and End. To exit the editor, press Ctrl + X, y to save the file, and then press Enter to confirm the address of the file to be saved.
If you intend to connect multiple people non-administrators for the server to FTP, it is desirable to create each user without access toSSH. Let’s create a ftpuser the user with access to FTP, but no SSH access:
adduser ftpuser-shell/bin/false
set password and personal data. If necessary, the user can remove the userdel command ftpuser ftpuser and its folder rm-r/home/ftpuser
We shall make more detailed customization of our FTPserver. Again okryvaem:/etc/proftpd/proftpd.conf
Nano/etc/proftpd/proftpd.conf
Let me remind you that for file navigation buttonsbuttons and arrows Page Up (PgUp) and Page Down (PgDn), Home and End. Toexit the editor, press Ctrl + X, y to save the file, and then press Enter to confirm the address of the file to be saved.
Let’s see some options in this file:
Servername-option, which specifies the name of the server.
DefaultRoot-option to specify in which folder immediately after connecting will be user.
Port is the option that specifies the port to connect to a server, the default is 21.
MaxInstances option specifies the maximum number of connections to the server (but not users).
Umask-option, which specifies the rights mask for the downloadable files via FTP. 022 mask means that all folders are loaded withrights 755 and all files with the permissions of 644.
AllowOverwrite-option, which enables or disables the overwrite files via FTP.
Restart FTP server for the changes to take effect:
service restart proftpd
On this basic setup FTP server over. Of course, the possibilities of the program anymore. Information about it appears in one of the next posts.
That’s it for today. Perhaps something else forgot, necessarily augment, I‘ll adjust either the following VPS.
Follov′te me on Twitter, write comments, yet!