Nginx's support is high concurrency, strong load balancing, low resource consumption makes it the first choice for Linux Web server, especially for small memory VPS, this is more obvious, make it win Apache.
The installation of LNMP is described below.
1. Preparatory work
Modify Login Password: <<linux Modify user Password >>
Modify time zone and time: << Modify Linux system time zone and time >>
Close redundant TTY channels
The code is as follows |
Copy Code |
Vi/etc/init/start-ttys.conf Find tty[1-6] change into tty[1-2] Find Active_consoles=/dev/tty[1-6] Change into active_consoles=/dev/tty[1-2] |
After reboot, you can
Modify Host Name: << Modify Linux host name (hostname) >>
Add Yum source and update: <<centos add common yum source >> configuration
iptables firewall, open the necessary ports:
The code is as follows |
Copy Code |
Vi/etc/sysconfig/iptables # generated by Iptables-save v1.4.7 on Sat Sep 29 10:26:10 2012
*nat
:P rerouting ACCEPT [40,182:3,767,364]
:P ostrouting ACCEPT [11,964:943,507]
: OUTPUT ACCEPT [11,964:943,507]
-A postrouting-s 192.168.0.0/24-o eth0-j Masquerade
COMMIT
# Completed on Sat Sep 29 10:26:10 2012
# generated by Iptables-save v1.4.7 on Sat Sep 29 10:26:10 2012
*filter
: INPUT DROP [4:600]
: FORWARD DROP [0:0]
: OUTPUT DROP [0:0]
-A input-p gre-j ACCEPT
-A input-i lo-j ACCEPT
-A input-p tcp-m tcp--dport 20-j ACCEPT
-A input-p tcp-m tcp--dport 21-j ACCEPT
-A input-p tcp-m state--state new-m TCP--dport 22-j ACCEPT
-A input-p tcp-m tcp--dport 443-j ACCEPT
-A input-p tcp-m tcp--dport 80-j ACCEPT
-A input-p tcp-m tcp--dport 1723-j ACCEPT
-A input-p tcp-m tcp--dport 3306-j ACCEPT
-A input-p tcp-m tcp--dport 30000:35000-j ACCEPT
-A input-p tcp-m tcp--dport 65535-j ACCEPT
-A input-p icmp-m ICMP--icmp-type any-j ACCEPT
-A input-m state--state related,established-j ACCEPT
-A forward-s 192.168.0.0/24-o eth0-j ACCEPT
-A forward-d 192.168.0.0/24-i eth0-j ACCEPT
-A output-m state--state new,related,established-j ACCEPT |
2. Install Nginx
List all versions of Nginx
The code is as follows |
Copy Code |
Yum List Nginx |
You can see that the latest version is 1.5.2
The code is as follows |
Copy Code |
Yum Install Nginx |
Start Nginx
The code is as follows |
Copy Code |
Service Nginx Start |
Set to boot
The code is as follows |
Copy Code |
Chkconfig--level 3 Nginx on |
Visit the VPS domain or IP if the display Welcome to nginx! Page to indicate that the installation was successful.
Nginx's web site root is different from Apache, for/usr/share/nginx/html
Configuration file is located in/etc/nginx
3. Install MySQL
This is the same as the MySQL installation under the LAMP environment. Refer to <<centos installation mysql>>
The latest version is 5.5.31
4. Install PHP
According to user testing, PHP 5.4 than PHP 5.3 performance increased by more than 50%, so here is recommended to use PHP 5.4 and updated version.
List the latest version of PHP because the webtatic source is usually up to date, so we only look in webtatic.
Yum List--disablerepo=*--enablerepo=webtatic php*
You can see that the latest version is PHP 5.5, but since Zend Guard Loader currently only supports PHP 5.4, we install the PHP 5.4 version.
Install PHP 5.4 and related components (additions and deletions according to your own needs)
Here, the PHP54W-FPM is used to associate with the Nginx module, so it is necessary, which is different from the LAMP environment
The code is as follows |
Copy Code |
Yum install php54w php54w-fpm php54w-bcmath php54w-cli php54w-common php54w-gd php54w-imap php54w-intl php54w-ldap php54w -mbstring php54w-mcrypt php54w-mysql php54w-odbc php54w-pdo php54w-pear Php54w-pspell php54w-soap php54w-xml Php54w-xmlrpc |
If the httpd service is started, deactivate the service.
The code is as follows |
Copy Code |
Service httpd Stop Chkconfig httpd off |
Start the PHP-FPM service
The code is as follows |
Copy Code |
Service PHP-FPM Start |
Configure Nginx to use PHP-FPM
The code is as follows |
Copy Code |
Vi/etc/nginx/conf.d/default.conf |
Find the following content
The code is as follows |
Copy Code |
Location/{ root/usr/share/nginx/html; Index index.html index.htm; } |
can modify root to other directories
Add the index.php type to the index entry
The code is as follows |
Copy Code |
Location/{ root/usr/share/nginx/html; Index index.html index.htm index.php; }
|
Remove the comments from the following content
The code is as follows |
Copy Code |
#location ~ php$ { # root HTML; # Fastcgi_pass 127.0.0.1:9000; # Fastcgi_index index.php; # Fastcgi_param Script_filename/scripts$fastcgi_script_name; # include Fastcgi_params; #} |
Modify the Fastcgi_param entry to replace the/scripts with the root content in location, which is the site root directory
The code is as follows |
Copy Code |
Location ~. php$ { root HTML; Fastcgi_pass 127.0.0.1:9000; Fastcgi_index index.php; Fastcgi_param Script_filename/usr/share/nginx/html$fastcgi_script_name; Include Fastcgi_params; }
|
Save exit
Edit PHP.ini
The code is as follows |
Copy Code |
Vi/etc/php.ini
|
The maximum allowable upload value is changed to 8M.
The code is as follows |
Copy Code |
Post_max_size = 8M Upload_max_filesize = 8M
|
Setting up Boot
The code is as follows |
Copy Code |
Chkconfig--level 3 php-fpm on
|
Restart Nginx and PHP-FPM services
The code is as follows |
Copy Code |
Service Nginx Restart Service PHP-FPM Restart
|
Create a new phpinfo.php file in/usr/share/nginx/html
The code is as follows |
Copy Code |
vi/usr/share/nginx/html/phpinfo.php
<?php Phpinfo (); ?>
|
If displayed correctly, the installation is successful.
5. Install Vsftp
Configuring the FTP Service
1. Install Vsftp
The code is as follows |
Copy Code |
Yum Install vsftpd |
Edit configuration file
The code is as follows |
Copy Code |
Vi/etc/vsftpd/vsftpd.conf |
We use the form of a virtual user here, configured as follows.
The code is as follows |
Copy Code |
Anonymous_enable=no Local_enable=yes Write_enable=yes local_umask=022 Dirmessage_enable=yes Xferlog_enable=yes Xferlog_file=/var/log/vsftpd.log Connect_from_port_20=yes Ftpd_banner=welcome to my FTP Server ^_^. Chroot_local_user=yes Ls_recurse_enable=yes Listen=yes
Pam_service_name=vsftpd Userlist_enable=no Tcp_wrappers=yes
One_process_model=no
#以下是手动添加的 pasv_min_port=30000 pasv_max_port=35000
Allow_writable_root=yes Guest_enable=yes Guest_username=root Virtual_use_local_privs=yes User_config_dir=/etc/vsftpd/user_conf |
2. Generate vsftpd Virtual user database files:
To create a virtual user list file:
The code is as follows |
Copy Code |
Vi/etc/vsftpd/ftpuser.txt |
The contents are as follows:
The code is as follows |
Copy Code |
Ftp1 1234 Ftp2 5678 |
The format is simple: "A line of user name, one line password!" ”。
3. Generate virtual user data files:
The code is as follows |
Copy Code |
Db_load-t-T Hash-f/etc/vsftpd/ftpuser.txt/etc/vsftpd/users.db chmod 600/etc/vsftpd/users.db
|
4. Configure PAM Authentication file:
The code is as follows |
Copy Code |
Vi/etc/pam.d/vsftpd |
Annotate or delete the original content and add the following to the file.
32-bit system:
The code is as follows |
Copy Code |
#db =/etc/vsftpd/users, the users here are the database names that were created in the previous step, removing the suffix. Auth required/lib/security/pam_userdb.so db=/etc/vsftpd/users Account Required/lib/security/pam_userdb.so Db=/etc/vsftpd/users |
64-bit system:
The code is as follows |
Copy Code |
#db =/etc/vsftpd/users, the users here are the database names that were created in the previous step, removing the suffix. Auth required/lib64/security/pam_userdb.so db=/etc/vsftpd/users Account Required/lib64/security/pam_userdb.so Db=/etc/vsftpd/users |
5. Create a virtual user-independent configuration file
Each virtual user must have a profile that is the same as the user name, which holds the personalization configuration for the user, which can be any property in the vsftpd.conf.
Create a virtual user profile directory, which is user_config_dir= configured in vsftpd.conf.
Mkdir/etc/vsftpd/user_conf
Create a user profile, named after the user name.
The code is as follows |
Copy Code |
Vi/etc/vsftpd/user_conf/ftp1
Local_root=/var/www/html idle_session_timeout=600 data_connection_timeout=120 max_clients=10 Max_per_ip=5 local_max_rate=50000
|
6. Start Service
The code is as follows |
Copy Code |
Service VSFTPD Start
|
Setting up Boot
The code is as follows |
Copy Code |
Chkconfig--level 3 vsftpd on
|
7. Allow through firewall
The code is as follows |
Copy Code |
Iptables-a input-p tcp-m TCP--dport 20-j ACCEPT Iptables-a input-p tcp-m TCP--dport 21-j ACCEPT Iptables-a input-p tcp-m TCP--dport 30000:35000-j ACCEPT
|
At this point, the FTP service configuration is complete, try it with the client connection.