Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to install Nginx environment on CentOS5 server

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "how to install the Nginx environment on the CentOS5 server". In the daily operation, I believe many people have doubts about how to install the Nginx environment on the CentOS5 server. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "how to install the Nginx environment on the CentOS5 server". Next, please follow the editor to study!

I. system agreement

Software source code package location / usr/local/src

Source package compilation installation location (prefix) / usr/local/software_name

Location of scripts and maintenance programs / usr/local/sbin

MySQL database location / var/lib/mysql (can be set as appropriate)

Web site root directory / home/www/wwwroot (can be set as appropriate)

Virtual host log root / home/www/logs (can be set as appropriate)

Run the account www:www

II. Deployment and adjustment of system environment

1. Check whether the system is normal

# more / var/log/messages (check for system-level error messages)

# dmesg (check hardware devices for error messages)

# ifconfig (check whether the Nic settings are correct)

# ping www.163.com (check whether the network is working)

# cat / proc/cpuinfo (check whether the CPU frequency is normal)

# top (press 1 to check whether the number of CPU cores and memory size are normal)

2. Turn off unwanted services

# ntsysv

The following lists only the services that need to be started, and it is recommended to shut down all services that are not listed:

Atd

Crond

Irqbalance

Microcode_ctl

Network

Sendmail

Sshd

Syslog

Close SElinux: modify the SELINUX= in the / etc/selinux/config file to disabled

3. Replace the yum domestic source

# cd / etc/yum.repos.d

# mv CentOS-Base.repo CentOS-Base.repo.save

# wget http://centos.ustc.edu.cn/CentOS-Base.repo.5

# mv CentOS-Base.repo.5 CentOS-Base.repo

# yum clean all

4. Server time check and setting

# data (check whether the time is correct and whether it is China time CST)

# cp-f / usr/share/zoneinfo/Asia/Shanghai / etc/localtime (execute if the time zone is not correct, the time is skipped normally)

# yum-y install ntp (install ntp timing tool)

# chkconfig ntpd on (enable the timing service to start up)

Use yum to update the system and install the necessary software packages

# yum update-y

# yum-y install make openssl openssl-devel pcre pcre-devel libpng libpng-devel libjpeg-6b libjpeg-devel-6b freetype freetype-devel gd gd-devel zlib zlib-devel gcc gcc-c++ libXpm libXpm-devel ncurses ncurses-devel libmcrypt libmcrypt-devel libxml2 libxml2-devel imake autoconf automake screen sysstat compat-libstdc++-33 curl curl-devel

6. Restart the system

# init 6

Compile and install L.A.M.P environment

1. Download the software (the latest version as of October 2009)

# cd / usr/local/src

# wget http://sysoev.ru/nginx/nginx-0.7.63.tar.gz

# wget http://download.scientificlinux.net/nginx

# wget http://download.scientificlinux.net/php-fpm.conf

# wget http://download.scientificlinux.net/nginx.conf

# wget http://download.scientificlinux.net/fcgi.conf

# wget http://download.scientificlinux.net/php-5.2.10.tar.gz

# wget http://download.scientificlinux.net/php-5.2.10-fpm-0.5.13.diff.gz

# wget http://download.scientificlinux.net/ZendOptimizer-3.3.3-linux-glibc23-i386.tar.gz (32-bit system)

# wget http://download.scientificlinux.net/ZendOptimizer-3.3.3-linux-glibc23-x86_64.tar.gz (64-bit system)

# wget http://download.scientificlinux.net/mysql-5.1.39-linux-i686-glibc23.tar.gz (32-bit system)

# wget http://download.scientificlinux.net/mysql-5.1.39-linux-x86_64-glibc23.tar.gz (64-bit system)

2. Install MySQL

The code is as follows:

Cd / usr/local/src

Tar zxvf mysql-5.1.39-linux-i686-glibc23.tar.gz

Mv mysql-5.1.39-linux-i686-glibc23 / usr/local/

Ln-s / usr/local/mysql-5.1.39-linux-i686-glibc23/ / usr/local/mysql

Groupadd mysql

Useradd-g mysql mysql

Chown-R mysql:mysql / usr/local/mysql

Chown-R mysql:mysql / usr/local/mysql-5.1.39-linux-i686-glibc23/

Cd / usr/local/mysql

. / scripts/mysql_install_db-- user=mysql

Cp. / support-files/mysql.server / etc/rc.d/init.d/mysqld

Chmod 755 / etc/rc.d/init.d/mysqld

Chkconfig-add mysqld

Chkconfig-level 3 mysqld on

Cp. / support-files/my-huge.cnf / etc/my.cnf

Mv / usr/local/mysql/data / var/lib/mysql

Chown-R mysql:mysql / var/lib/mysql

Edit / etc/my.cnf

Add in [mysqld] paragraph

Datadir = / var/lib/mysql

Skip-innodb

Wait-timeout = 10

Max_connections = 512

Max_connect_errors = 10000000

Modify in [mysqld] paragraph

Max_allowed_packet = 16m

Thread_cache_size = number of CPU * 2

Annotate log-bin

Service mysqld start

Bin/mysqladmin-u root password 'password_for_root'

Where the password_for_root in quotation marks is the root password to be set

3. Install Nginx

The code is as follows:

Cd / usr/local/src/

Tar zxvf nginx-0.7.63.tar.gz

Cd nginx-0.7.63

. / configure-- prefix=/usr/local/nginx-- conf-path=/usr/local/nginx/conf/nginx.conf-- with-http_realip_module-- with-http_addition_module-- with-http_gzip_static_module-- with-http_random_index_module-- with-http_stub_status_module-- with-http_sub_module-- with-http_dav_module

Make

Make install

Cp / usr/local/src/nginx / etc/init.d/nginx

Chmod 755 / etc/init.d/nginx

Chkconfig-add nginx

Chkconfig nginx on

4. Install PHP and Zend

The code is as follows:

Cd / usr/local/src

Tar zxvf php-5.2.10.tar.gz

Gzip-cd php-5.2.10-fpm-0.5.13.diff.gz | patch-d php-5.2.10- p1

Cd php-5.2.10

/ configure-- prefix=/usr/local/php5-- with-config-file-path=/usr/local/etc/cgi-- enable-mbstring-- enable-ftp-- with-gd-- with-jpeg-dir=/usr-- with-png-dir=/usr-- enable-magic-quotes-- with-mysql=/usr/local/mysql-- with-pear-- enable-sockets-- with-ttf-- with-freetype-dir=/usr-- enable-gd-native-ttf-- with-zlib-- Enable-sysvsem-enable-sysvshm-with-libxml-dir=/usr-enable-force-cgi-redirect-enable-fastcgi-with-xmlrpc-enable-zip-enable-fpm

Make

Make install

Mkdir-p / usr/local/etc/cgi/

Cp php.ini-dist / usr/local/etc/cgi/php.ini

Mv-f / usr/local/src/php-fpm.conf / usr/local/php5/etc/php-fpm.conf

Groupadd www

Useradd-g www www

Echo 'ulimit-SHn 65535' > > / etc/rc.local

Echo'/ usr/local/php5/sbin/php-fpm start' > > / etc/rc.local

Cd / usr/local/src

Tar zxvf ZendOptimizer-3.3.3-linux-glibc23-i386.tar.gz

Cd ZendOptimizer-3.3.3-linux-glibc23-i386

. / install

(note that the first path to be filled in is the Zend installation path, and the second is the path where php.ini is located, namely / usr/local/etc/cgi)

(do not choose to restart apache)

5. Start Nginx and php

The code is as follows:

Mv-f / usr/local/src/fcgi.conf / usr/local/nginx/conf/

Cp-f / usr/local/src/nginx.conf / usr/local/nginx/conf/nginx.conf

Mkdir-p / home/www/wwwroot

Ulimit-SHn 65535

/ usr/local/php5/sbin/php-fpm start

Service nginx start

Put an index.php in / home/www/wwwroot with the following content

Open the browser to access the phpinfo page

6. Set up the system firewall

Edit / usr/local/sbin/fw.sh

Copy the following into it

The code is as follows:

#! / bin/bash

# Stop iptables service first

Service iptables stop

# Load FTP Kernel modules

/ sbin/modprobe ip_conntrack_ftp

/ sbin/modprobe ip_nat_ftp

# Inital chains default policy

/ sbin/iptables-F-t filter

/ sbin/iptables-P INPUT DROP

/ sbin/iptables-P OUTPUT ACCEPT

# Enable Native Network Transfer

/ sbin/iptables-An INPUT-I lo-j ACCEPT

# Accept Established Connections

/ sbin/iptables-An INPUT-m state-- state ESTABLISHED,RELATED-j ACCEPT

# ICMP Control

/ sbin/iptables-An INPUT-p icmp-m limit--limit 1max s-- limit-burst 10-j ACCEPT

# WWW Service

/ sbin/iptables-An INPUT-p tcp-- dport 80-j ACCEPT

# FTP Service

/ sbin/iptables-An INPUT-p tcp-- dport 21-j ACCEPT

# SSH Service

/ sbin/iptables-An INPUT-p tcp-- dport 22-j ACCEPT

Exit editing and execute the following command

The code is as follows:

# chmod 755 / usr/local/sbin/fw.sh

# echo'/ usr/local/sbin/fw.sh' > > / etc/rc.local

# / usr/local/sbin/fw.sh

At this point, the study on "how to install the Nginx environment on the CentOS5 server" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report