Build Nginx + MariaDB server environment in VPS/Linux

Source: Internet
Author: User
Tags apc geoip drupal

If you want to build Nginx + MariaDB in windows, refer to another blog article titled Nginx + MariaDB + PHP in windows using WnMp.

First, Log On As root:

Basic Server Configuration

Set Hostname

 
 
  1. echo “plato” > /etc/hostname 
  2. hostname -F /etc/hostname 

Edit/etc/hosts IPv6)

Added:

12.34.56.78 plato.example.com plato

2600: 3c01: a123: b456: c789: d012 plato.example.com plato

Set Time Zone

 
 
  1. dpkg-reconfigure tzdata 

Update Server Software

 
 
  1. nano /etc/apt/sources.list 

Add the following two lines:

 
 
  1. deb http://packages.dotdeb.org squeeze all 
  2. deb-src http://packages.dotdeb.org squeeze all 
  3.  
  4. wget http://www.dotdeb.org/dotdeb.gpg 
  5. cat dotdeb.gpg | apt-key add - 
  6.  
  7. apt-get update 
  8. apt-get upgrade –show-upgraded 

Configure security attributes

Add a system administrator

 
 
  1. adduser example_user 
  2. usermod -a -G sudo example_user 
  3. logout 
  4. ssh example_user@123.456.78.90 

Now, you can use the new user and sudo to execute the Administrator command.

Reverse-activate root SSH Logon

 
 
  1. sudo nano /etc/ssh/sshd_config 

Update this line: PermitRootLogin no

Sudo service ssh restart

Set firewall:

 
 
  1. sudo iptables -L 
  2. sudo nano /etc/iptables.firewall.rules 

Copy:

 
 
  1. *filter 
  2.  
  3. # Allow all loopback (lo0) traffic and drop all traffic to 127/8 that doesn’t use lo0 
  4. -A INPUT -i lo -j ACCEPT 
  5. -A INPUT -d 127.0.0.0/8 -j REJECT 
  6.  
  7. # Accept all established inbound connections 
  8. -A INPUT -m state –state ESTABLISHED,RELATED -j ACCEPT 
  9.  
  10. # Allow all outbound traffic – you can modify this to only allow certain traffic 
  11. -A OUTPUT -j ACCEPT 
  12.  
  13. # Allow HTTP and HTTPS connections from anywhere (the normal ports for websites and SSL). 
  14. -A INPUT -p tcp –dport 80 -j ACCEPT 
  15. -A INPUT -p tcp –dport 443 -j ACCEPT 
  16.  
  17. # Allow SSH connections 
  18. # The -dport number should be the same port number you set in sshd_config 
  19. -A INPUT -p tcp -m state –state NEW –dport 22 -j ACCEPT 
  20.  
  21. # Allow ping 
  22. -A INPUT -p icmp -j ACCEPT 
  23.  
  24. # Log iptables denied calls 
  25. -A INPUT -m limit –limit 5/min -j LOG –log-prefix “iptables denied: ” –log-level 7 
  26.  
  27. # Drop all other inbound – default deny unless explicitly allowed policy 
  28. -A INPUT -j DROP 
  29. -A FORWARD -j DROP 
  30.  
  31. COMMIT 
  32.  
  33. sudo iptables-restore 

Automatically load the firewall after each restart:

 
 
  1. sudo nano /etc/network/if-pre-up.d/firewall 
  2. #!/bin/sh 
  3. /sbin/iptables-restore 
  4. sudo chmod +x /etc/network/if-pre-up.d/firewall 

Install Fail2Ban to automatically detect and prevent attacks:

 
 
  1. sudo aptitude install fail2ban 

Install PHP-FPM

 
 
  1. sudo aptitude install php5 php5-cli php5-dev php5-gd php-pear php5-fpm php5-geoip libgeoip1 libgeoip-dev geoip-database 

Update some configurations:

 
 
  1. sudo nano /etc/php5/fpm/php.ini 
  2. memory_limit: 512M 
  3. cgi.fix_pathinfo=0 

Install Nginx

 
 
  1. sudo aptitude install nginx 

Configure a VM

 
 
  1. sudo mkdir -p /srv/www/insready.com/{public_html,logs} 
  2. sudo chown -R www-data:www-data /srv/www 
  3. sudo chmod -R 775 /srv/www 
  4. cd /etc/nginx/sites-available/ 
  5. sudo wget https://gist.github.com/raw/4248423/c7b2ea550ef9273f7f5d0823f81f054296fc… 

You need to modify the above domain name configuration sudo nano insready.com

Sudo nano/etc/php5/fpm/pool. d/www. conf

Change listen = 127.0.0.1: 9000:

 
 
  1. listen = /tmp/php-fpm.sock 
  2. sudo ln -s /etc/nginx/sites-available/insready.com /etc/nginx/sites-enabled 

Configure Nginx Microcache (and put the Microcache in the memory to experience the lightning speed !)

 
 
  1. Sudo nano/etc/nginx/conf. d/microcache. conf
  2. Fastcgi_cache_path/dev/shm/microcache levels = keys_zone = microcache: 5 M max_size = 1G inactive = 2 h; # Set the nicnx Microcache in the memory, which is faster!
  3. Map $ http_cookie $ cache_uid {
  4. Default nil; # hommage to Lisp :)
  5. ~ SESS [[: alnum:] + = (? <Session_id> [[: alnum:] +) $ session_id;
  6. }
  7.  
  8. Map $ request_method $ no_cache {
  9. Default 1;
  10. HEAD 0;
  11. GET 0;
  12. }

Now enable Nginx to run automatically every time it is started.

 
 
  1. sudo update-rc.d nginx defaults 

Start Nginx

 
 
  1. sudo /etc/init.d/nginx start 

Install MariaDB

To put it bluntly, MariaDB is a new open-source database that was created after Oracle bought MySQL. MariaDB is used in the same way as MySQL.

 
 
  1. sudo nano /etc/apt/sources.list.d/MariaDB.list 
  2.  
  3. # MariaDB 5.5 repository list – created 2012-12-08 07:39 UTC 
  4. # http://downloads.mariadb.org/mariadb/repositories/ 
  5. deb http://ftp.yz.yamagata-u.ac.jp/pub/dbms/mariadb/repo/5.5/debian squeeze main 
  6. deb-src http://ftp.yz.yamagata-u.ac.jp/pub/dbms/mariadb/repo/5.5/debian squeeze main 
  7.  
  8. sudo apt-key adv –recv-keys –keyserver keyserver.ubuntu.com 0xcbcb082a1bb943db 
  9.  
  10. sudo aptitude update 
  11. sudo aptitude install libmariadbclient-dev libmariadbclient18 libmariadbd-dev
  12.  libmysqlclient18 mariadb-client mariadb-client-5.5 mariadb-client-core-5.5
  13.  mariadb-common mariadb-server mariadb-server-5.5 mariadb-server-core-5.5 mariadb-test mariadb-test-5.5 mysql-common 

Install the latest version of Drupal

 
 
  1. cd /srv/www/insready.com 
  2. sudo wget http://ftp.drupal.org/files/projects/drupal-7.18.tar.gz 
  3. sudo tar -xvzf drupal-7.18.tar.gz 
  4. cd drupal-7.18 
  5. sudo cp -a . ../public_html/ 
  6. sudo chown www-data:www-data public_html -R 

Install Memcache and APC

 
 
  1. sudo aptitude install memcached libmemcached-tools memstat make 
  2. sudo pecl install memcache 
  3. sudo pecl install apc 

Create the following file to configure Memcache

 
 
  1. sudo nano /etc/php5/conf.d/memcache.ini 
  2. extension= memcache.so 
  3. memcache.hash_strategy=”consistent” 

Create the following files and configure apc

 
 
  1. sudo nano /etc/php5/conf.d/apc.ini 
  2. extension=apc.so 
  3. apc.shm_size = 256M 
  4. apc.apc.stat = 0 

Install uploadprogress

 
 
  1. sudo pecl install uploadprogress 

Create the following file and configure uploadprogress

 
 
  1. sudo nano /etc/php5/conf.d/uploadprogress.ini 
  2. extension=uploadprogress.so 

Restart:

 
 
  1. sudo service nginx restart 
  2. sudo service mysql restart 
  3. sudo service php5-fpm restart 
  4. sudo service memcached restart 

Done!

Edit recommendations]

  1. MariaDB 5.3 will support the alter table progress prompt
  2. The founder of MySQL builds MariaDB fully compatible with MySQL 5.1.
  3. MariaDB 2 anniversary
  4. How to optimize your MongoDB in five steps
  5. Install MariaDB in Windows

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.