The setup steps of LNMP HTTP Web server under VPS CentOS-6 _linux

Source: Internet
Author: User
Tags fpm install php mcrypt vps scp command

I started a new VPS yesterday, as a personal blog wid Laboratory (widlabs.com) development of the experimental environment. So in this blog, will introduce CentOS 6 under the LNMP HTTP environment, from the use of SSH login VPS, until the domain name resolution to the server IP on this complete website construction process.

The new starting VPS basic configuration is as follows:

Virtualization Technology: OpenVZ operating system: CentOS-6 x86_64 Basecpu:intel (R) Xeon (r) CPU e3-1240 V2 @ 3.40GHz Memory: 2GB hard drive: 50GB HDD

First, prepare work SSH login VPS, SCP upload file

SSH Login VPS
Under Linux, to remotely administer a single server, it's a very relaxing thing, the SSH command is used to log in to the remote host, enter the shell command line mode after logging in, and then operate the remote host as if it were in the terminal operation of its own machine, the only thing to be aware of is not to write the command incorrectly, such as RM -rf./* Written RM-RF/*.

The general usage of the SSH command is:

SSH user name @ host name-P host SSH service port number

The default port number for the SSH service is 22, when the default ports are used, the-p option is optional, the first time a host is remotely connected, the host authenticity is not confirmed, asks whether to continue (yes/no), enter "Yes" to continue to connect, to login 198.98.117.120 for example:

carey@e530:~$ SSH root@198.98.117.120-p 22


SCP upload File

The SCP command enables replication of files from native to remote hosts, based on SSH services, and is generally used as follows:

To copy files from this computer to a remote host:

Copy Code code as follows:

Scp-p SSH Service port number local file path target host user name @ Host Name: Store path

To copy files from a remote host to a local:

Copy Code code as follows:

Scp-p SSH service port number target host user name @ Host Name: File path Native store path

To upload the configuration LNMP environment required files For example, Nginx source code package nginx-1.6.0.tar.gz, PHP's source code package php-5.5.10.tar.gz, a new terminal:

Copy Code code as follows:

carey@e530:~/download$ scp-p nginx-1.6.0.tar.gz Root@198.98.117.120:/home/upload
carey@e530:~/download$ scp-p php-5.5.10.tar.gz Root@198.98.117.120:/home/upload


Second, compile and install Nginx, PHP

First look at some of the packages preinstalled in the VPS CentOS system:

Yum List installed

Clean up your own Apache, PHP, MySQL services (if present), and execute the command:

Yum remove httpd mysql-server mysql PHP

Check to see if GCC is installed, execute the command gcc-v do not install yum install:

Yum Install GCC

It is necessary to install GCC, because we will compile the Nginx and PHP in the following way.
Install Nginx
Create Nginx, PHP dedicated users and user groups

[Root@widlabs ~]# Groupadd www
[Root@widlabs ~]# useradd-s/sbin/nologin-m-G www nginx

Dependencies required to install Nginx

[Root@widlabs ~]# Yum Install Pcre-devel
[Root@widlabs ~]# Yum Install Zlib-devel

Perform Nginx compilation installation

Copy Code code as follows:

[Root@widlabs ~]# cd/home/upload #进入nginx源码包所在目录
[Root@widlabs upload]# tar tar zxvf nginx-1.6.0.tar.gz
[Root@widlabs upload]# CD nginx-1.6.0
[Root@widlabs nginx-1.6.0]#./configure--prefix=/usr/local/nginx--user=nginx--group=www--with-pcre
[Root@widlabs nginx-1.6.0]# make
[Root@widlabs nginx-1.6.0]# make install

Installing PHP
dependencies required to install PHP

Copy Code code as follows:

[Root@widlabs nginx-1.6.0]# cd/home/upload #进入php源码包所在目录
#若 the wget command is available, execute:
[Root@widlabs upload]# wget ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/libmcrypt-2.5.6.tar.gz
#注: Wget is not available, you can yum install wget first, or to ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/download the libmcrypt-2.5.6.tar.gz source package, Then use the SCP command to upload to the VPS;
[Root@widlabs upload]# tar zvxf libmcrypt-2.5.6.tar.gz
[Root@widlabs upload]# CD libmcrypt-2.5.6
[Root@widlabs libmcrypt-2.5.6]#./configure--prefix=/usr/local/libmcrypt
[Root@widlabs libmcrypt-2.5.6]# make
[Root@widlabs libmcrypt-2.5.6]# make install
[Root@widlabs libmcrypt-2.5.6]# CD ...
[Root@widlabs upload]# Yum Install Libxml2-devel

To compile the PHP installation

Copy Code code as follows:

[Root@widlabs upload]# tar zxvf php-5.5.10.tar.gz
[Root@widlabs upload]# CD php-5.5.10
[Root@widlabs php-5.5.10]#./configure--prefix=/usr/local/php--with-config-file-path=/usr/local/php--with-mysql- -with-mysqli--with-pdo-mysql--enable-opcache--enable-mbstring--enable-mbregex--with-mcrypt=/usr/local/ Libmcrypt--with-mhash--enable-cgi--enable-fpm #可根据自身需要增加相应编译选项
[Root@widlabs php-5.5.10]# make
[Root@widlabs php-5.5.10]# make install
[Root@widlabs php-5.5.10]# CP Php.ini-development/usr/local/php/php.ini
[Root@widlabs php-5.5.10]# Cd/usr/local/php/etc
[Root@widlabs etc]# CP Php-fpm.conf.default php-fpm.conf

Third, the installation of MySQL

MySQL can be installed directly by Yum Way:

[Root@widlabs ~]# yum install MySQL mysql-server mysql-devel

Iv. Configure Nginx, PHP
Configuration of Nginx

Copy Code code as follows:

[Root@widlabs ~]# cd/usr/local/nginx/conf
[Root@widlabs conf]# CP nginx.conf Nginx.conf.bak
[Root@widlabs conf]# VI nginx.conf

server {
Listen 80;
server_name widlabs.com www.widlabs.com; #网站域名

#charset Koi8-r;

#access_log Logs/host.access.log Main;

Location/{
root HTML;
Index index.html index.htm index.php; #添加 index.php
}

#error_page 404/404.html;

# REDIRECT Server error pages to the static page/50x.html
#
Error_page 502 503 504/50x.html;
Location =/50x.html {
root HTML;
}

# Proxy The PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# Proxy_pass http://127.0.0.1;
#}

# Pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
# Remove the comments from these lines and make the changes small
Location ~ \.php$ {
root HTML;
Fastcgi_pass 127.0.0.1:9000;
Fastcgi_index index.php;
#fastcgi_param Script_filename/scripts$fastcgi_script_name; To
Fastcgi_param script_filename $document _root$fastcgi_script_name;
Include Fastcgi_params;
}

# Deny access to. htaccess files, if Apache ' s document Root
# concurs with Nginx ' s one
#
#location ~/\.ht {
# Deny All;
#}
}

Configuration of PHP

Copy Code code as follows:

[Root@widlabs ~]# Vi/usr/local/php/php.ini
[Date]
; Defines the default timezone used by the date functions
; Http://php.net/date.timezone
Date.timezone = PRC

V. Test configuration is correct

Copy Code code as follows:

[Root@widlabs ~]# cd/usr/local/nginx/html #/usr/local/nginx/html is the default working directory for Web sites
[Root@widlabs html]# Echo ' <?php echo phpinfo ()?> ' > test.php #新建 test.php execute test as PHP
[Root@widlabs html]# service mysqld start #启动MySQL服务
[Root@widlabs html]#/usr/local/php/sbin/php-fpm #启动PHP fastcgi Manager
[Root@widlabs html]#/usr/local/nginx/sbin/nginx #启动Nginx

Use the browser to access the host IP and test.php to determine if Nginx is working properly.


Six, Nginx website service boot from start

Copy Code code as follows:

[Root@widlabs ~]# vi/etc/rc.local

#!/bin/sh
#
# This script would be executed *after* all the other init scripts.
# You can put your own initialization stuff with If you don ' t
# want to does the full Sys V style init stuff.

Touch/var/lock/subsys/local
#添加
/sbin/service mysqld Start
/usr/local/php/sbin/php-fpm
/usr/local/nginx/sbin/nginx

Reboot the VPS to determine if the boot is correct:

[Root@widlabs ~]# reboot now

Vii. resolving domain name to server IP

Login provider provided by the Management panel, select Domain name resolution, type Select a record, record value to point to the host IP.


Here, the entire LNMP HTTP base environment is built.


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.