Centos 6.5上安裝最新LNMP

平臺:Centos 6.5 x86_64 最小系統安裝php

1,更新系統html

yum install -y epel-release
yum update -ymysql

修改系統時區
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
ntpdate 1.cn.pool.ntp.orgnginx

2,安裝基本庫c++

yum -y install gcc gcc-c++ autoconf automake zlib zlib-devel openssl openssl-devel pcre pcre-develweb

3,安裝最新穩定版nginx 1.10.1sql

rpm -ivh http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpmapache

yum install -y nginxcentos

4,安裝mysql5.6.28cookie

rpm -Uvh http://dev.mysql.com/get/mysql-community-release-el6-5.noarch.rpm

CentOS/RHEL 7.x
rpm -ivh http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm

yum install -y mysql-community-server

service mysqld start

mysql_secure_installation

5,安裝最新的php

CentOS/RHEL 7.x:

rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

 

CentOS/RHEL 6.x:

rpm -Uvh https://mirror.webtatic.com/yum/el6/latest.rpm

php 5.5.30

yum install -y php55w php55w-common php55w-cli php55w-mysql php55w-gd php55w-fpm php55w-intl php55w-mcrypt php55w-mbstring php55w-pdo php55w-pear php55w-soap php55w-tidy php55w-xml php55w-xmlrpc php55w-bcmath php55w-xml php55w-opcache php55w-devel

 

php5.6.16

yum install -y php56w php56w-common php56w-cli php56w-mysql php56w-gd php56w-fpm php56w-intl php56w-mcrypt php56w-mbstring php56w-pdo php56w-pear php56w-soap php56w-tidy php56w-xml php56w-xmlrpc php56w-bcmath php56w-xml php56w-opcache php56w-devel

 

php7.0

yum install -y php70w php70w-common php70w-cli php70w-mysql php70w-gd php70w-fpm php70w-intl php70w-mcrypt php70w-mbstring php70w-pdo php70w-pear php70w-soap php70w-tidy php70w-xml php70w-xmlrpc php70w-bcmath php70w-xml php70w-opcache php70w-devel

 

6,安裝php加速模塊

wget http://xcache.lighttpd.net/pub/Releases/3.2.0/xcache-3.2.0.tar.gz 

tar -zxvf xcache-3.2.0.tar.gz  

cd xcache-3.2.0

phpize --clean

phpize

./configure --enable-xcache

make && make install

cat xcache.ini >> /etc/php.ini

cd

 

7,配置php

sed -i 's/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/g' /etc/php.ini

sed -i 's/post_max_size = 8M/post_max_size = 32M/g' /etc/php.ini

sed -i 's/upload_max_filesize = 2M/upload_max_filesize = 20M/g' /etc/php.ini

sed -i 's/;date.timezone =/date.timezone = PRC/g' /etc/php.ini

sed -i 's/max_execution_time = 30/max_execution_time = 180/g' /etc/php.ini

sed -i 's/disable_functions =.*/disable_functions = passthru,exec,system,chroot,scandir,chgrp,proc_open,proc_get_status,popen,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server/g' /etc/php.ini

ulimit -HSn 65535

chgrp nginx /var/lib/php/session

chgrp nginx /var/lib/php/wsdlcache

sed -i 's/user = apache/user = nginx/g' /etc/php-fpm.d/www.conf

sed -i 's/group = apache/group = nginx/g' /etc/php-fpm.d/www.conf

sed -i 's/;request_terminate_timeout = 0/request_terminate_timeout = 120/g' /etc/php-fpm.d/www.conf

sed -i 's/pm.max_children = 50/pm.max_children = 100/g' /etc/php-fpm.d/www.conf

sed -i 's/pm.start_servers = 5/pm.start_servers = 10/g' /etc/php-fpm.d/www.conf

sed -i 's/pm.min_spare_servers = 5/pm.min_spare_servers = 10/g' /etc/php-fpm.d/www.conf

sed -i 's/pm.max_spare_servers = 35/pm.max_spare_servers = 70/g' /etc/php-fpm.d/www.conf

sed -i 's/;pm.max_requests = 500/pm.max_requests = 10240/g' /etc/php-fpm.d/www.conf

sed -i 's/;rlimit_files = 1024/rlimit_files = 51200/g' /etc/php-fpm.d/www.conf

chkconfig --level 2345 php-fpm on

service php-fpm start

 

8,修改nginx配置

mkdir -p /var/www/html

chown -R nginx:nginx /var/www/html

 

vi /etc/nginx/conf.d/default.conf

    #location / {

        root   /var/www/html;

        index  index.php index.html index.htm;

    #}

 

location ~ \.php$ {

    #    root           html;

        fastcgi_pass   127.0.0.1:9000;

        fastcgi_index  index.php;

        fastcig_read_timeout 120;

        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

        include        fastcgi_params;

    }

 

service nginx start

 

9.測試

echo '<?php phpinfo(); ?>' > /var/www/html/index.php

 

http://yourserverip

 

網絡優化

cat >> /etc/security/limits.conf<<-EOF
* soft nofile 51200
* hard nofile 51200
EOF
 

cat >> /etc/sysctl.conf<<-EOF
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_fin_timeout = 10
net.ipv4.tcp_keepalive_time = 30
                                 
net.ipv4.ip_local_port_range = 1024 65000
net.ipv4.tcp_max_syn_backlog = 8192
net.ipv4.tcp_max_tw_buckets = 8000
                                 
net.core.somaxconn = 262144
                                 
net.ipv4.tcp_keepalive_probes = 5
net.ipv4.tcp_keepalive_intvl = 20
                                 
net.core.wmem_default = 8388608
net.core.rmem_default = 8388608
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
                                 
net.ipv4.tcp_rmem = 4096 87380 16777216
net.ipv4.tcp_wmem = 4096 65536 16777216
                                 
net.core.netdev_max_backlog = 32768
                                 
net.ipv4.tcp_timestamps = 0
net.ipv4.tcp_synack_retries = 2
net.ipv4.tcp_syn_retries = 2
net.ipv4.tcp_retries2 = 5
                                 
net.ipv4.tcp_mem = 41943040 73400320 94371840
net.ipv4.tcp_max_orphans = 3276800
fs.file-max = 1300000

kernel.printk_ratelimit = 30
kernel.printk_ratelimit_burst = 200
EOF

sysctl -p使生效

相關文章
相關標籤/搜索