阿里云香港

CentOS6.5 64位   

默认内核版本 2.6.32-431.el6.x86_64  (尽量不更新系统,保持内核版本号统一)
 
关闭SELINUX  (已默认关闭)
 
#vi /etc/selinux/config

将SELINUX=enforcing 修改为 SELINUX=disabled
 
关闭防火墙

暂时关闭
#service iptables stop

永久关闭
#chkconfig iptables off

查看防火墙状态
#service iptables status

(需要重启才生效)
#reboot

一、安装MySQL
 
安装
#yum install mysql-server

设置开机启动
#chkconfig mysqld on

启动mysql
#service mysqld start

拷贝配置文件
#cp /usr/share/mysql/my-huge.cnf /etc/my.cnf
 
初始化
mysql_secure_installation
 
回车,根据提示输入Y
 
输入2次密码,回车
 
根据提示一路输入Y
 
最后出现:Thanks for using MySQL!

开放远程登录权限
#mysql -uroot -p
输入密码
>use mysql;
>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;
>exit

重启mysql
#service mysqld restart

二、安装php   
 
#yum install php-fpm php-mysql php-gd libjpeg* php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-bcmath php-mhash

启动php-fpm
#service php-fpm start
自动启动php-fpm
#chkconfig php-fpm on

配置PHP
#vi /etc/php.ini
 
修改如下内容 (可根据情况修改)    
 
memory_limit = 256M
 
upload_max_filesize = 8M
 
-----------------------------------
session.save_path = "/var/lib/php/session"
 
将其改为
 
session.save_path = "/data/sessions"
 
修改
session.auto_start = 1
 
保存,
 
然后
#mkdir /data
#mkdir /data/sessions
#chown -R daemon:daemon /data/sessions
#chmod -R 777 /data/sessions
#mkdir /data/logs
#chown -R daemon:daemon /data/logs
#chmod -R 777 /data/logs

三、安装 NginX  

添加repo源
#vi /etc/yum.repos.d/nginx.repo
添加如下内容:
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1

查看nginx版本  (1.10.1-1.el6.ngx)
#yum list|grep nginx

安装
#yum install nginx
 
启动  
#service nginx start
 
自动启动
#chkconfig nginx on
 
#mkdir /data/www
#mkdir /data/logs/nginx
#chown -R nginx:nginx /data/logs/nginx
 
配置
#vi /etc/nginx/nginx.conf
 
error_log /data/logs/nginx/error.log;
 
events {
    worker_connections 1024;
    use epoll;  //增加此行 如果你使用Linux 2.6+,你应该使用epoll。
}

http {
    access_log  /data/logs/nginx/access.log  main;
    
    client_max_body_size 8m;    //限制上传文件最大值,根据实际需要设置 此处设置与php.ini中的设置有关联

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;

    #support gzip
    gzip on;
    gzip_http_version 1.0;
    gzip_disable "MSIE [1-6].";
    gzip_types text/plain application/x-javascript text/css text/javascript application/x-httpd-php image/jpeg image/gif image/png;

    #include /etc/nginx/conf.d/*.conf;

    server {  
        listen       80;  
        server_name  www.phplee.com phplee.com;  
        root /data/www/phplee.com/www;  
        index  index.html index.htm index.php;  
        error_page  404              /404.html;  
        location = /404.html {  
                return 404 'Sorry, File not Found!';  
        }  
        error_page  500 502 503 504  /50x.html;  
        location = /50x.html {  
                root   /usr/share/nginx/html; # windows dir  
        }  
        location / {  
                try_files $uri @rewrite;  
        }  
        location @rewrite {  
                set $static 0;  
                if  ($uri ~ \.(css|js|jpg|jpeg|png|gif|ico|woff|eot|svg|css\.map|min\.map)$) {  
                        set $static 1;  
                }  
                if ($static = 0) {  
                        rewrite ^/(.*)$ /index.php?s=/$1;  
                }  
        }  
        location ~ /Uploads/.*\.php$ {  
                deny all;  
        }  
        location ~ \.php/ {  
                if ($request_uri ~ ^(.+\.php)(/.+?)($|\?)) { }  
                fastcgi_pass 127.0.0.1:9000;  
                include fastcgi_params;  
                fastcgi_param SCRIPT_NAME     $1;  
                fastcgi_param PATH_INFO       $2;  
                fastcgi_param SCRIPT_FILENAME $document_root$1;  
        }  
        location ~ \.php$ {  
                fastcgi_pass 127.0.0.1:9000;  
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;  
                include fastcgi_params;  
        }  
        location ~ /\.ht {  
                deny  all;  
        }  
   }  

}

四、安装redis

更新源  
#cd /data
#wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm .
#rpm -ivh epel-release-6-8.noarch.rpm

安装
#yum install redis php-redis

配置

#vi /etc/redis.conf
maxmemory 100mb //添加一行 最大内存
appendonly yes  //修改 启用持久化

启动及开机启动

#service redis start
#chkconfig redis on

进入测试

#redis-cli
127.0.0.1:6379>set foo bar
OK
127.0.0.1:6379>get foo
"bar"
127.0.0.1:6379>quit

PS:

ThinkPHP中这样引用就可以了

S(array('type'=>'redis','host'=>'127.0.0.1','port'=>'6379','prefix'=>'think','expire'=>600));


iptables设置

开机启动
#chkconfig iptables on

查看状态
#service iptables status

开放80端口
#iptables -A INPUT -p tcp --dport 80 -j ACCEPT
#iptables -A INPUT -p tcp --dport 3306 -j ACCEPT
#iptables -A INPUT -p tcp --dport 9000 -j ACCEPT
#iptables -A INPUT -p tcp --dport 6379 -j ACCEPT
#iptables -A INPUT -p tcp --dport 1723 -j ACCEPT

保存更改
#service iptables save

重启防火墙以便生效
#service iptables restart

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐