服務器ip設置。編輯網卡配置文件,命令:
1 vi /etc/sysconfig/network-scripts/ifcfg-eth0
注:ifcfg-eth0參數TYPE=Ethernet #網卡類型DEVICE=eth0 #網卡接口名稱ONBOOT=yes #系統啟動時是否自動加載BOOTPROTO=static #啟用地址協議 --static:靜態協議 --bootp協議 --dhcp協議下面內容非DHCP協議設置,DHCP協議請刪除或者注釋掉#IPADDR=192.168.1.11 #網卡IP地址NETMASK=255.255.255.0 #網卡網絡地址GATEWAY=192.168.1.1 #網卡網關地址DNS1=10.203.104.41 #網卡DNS地址HWADDR=00:0C:29:13:5D:74 #網卡設備MAC地址
BROADCAST=192.168.1.255 #網卡廣播地址
重啟網絡連接,命令:
1 service network restart
配置防火墻,開啟80端口、3306端口
1 vi /etc/sysconfig/iptables
特別提示:很多網友把這兩條規則添加到防火墻配置的最后一行,導致防火墻啟動失敗,正確的應該是添加到默認的22端口這條規則的下面
添加好之后防火墻規則如下所示:
########################################################## Firewall configuration written by system-config-firewall# Manual customization of this file is not recommended.*filter:INPUT ACCEPT [0:0]:FORWARD ACCEPT [0:0]:OUTPUT ACCEPT [0:0]-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT-A INPUT -p icmp -j ACCEPT-A INPUT -i lo -j ACCEPT-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT-A INPUT -j REJECT --reject-with icmp-host-prohibited-A FORWARD -j REJECT --reject-with icmp-host-prohibitedCOMMIT#########################################################
1 /etc/init.d/iptables restart #最后重啟防火墻使配置生效
關閉SElinux
1 vi /etc/selinux/config
#SELINUX=enforcing #注釋掉
#SELINUXTYPE=targeted #注釋掉
SELINUX=disabled #增加
:wq 保存,關閉
1 shutdown -r now #重啟系統
配置CentOS 6.2 第三方yum源(CentOS默認的標準源里沒有nginx軟件包)
1 wget http://www.atomicorp.com/installers/atomic #下載atomic yum源2 sh ./atomic #安裝3 yum check-update #更新yum軟件包安裝LNMPNginx
安裝Nginx之前,必須先安裝安裝epel,如何在centos中安裝epel,請參考:在centos中安裝epel
1 yum install -y nginx #安裝nginx2 service nginx start #啟動Nginx3 chkconfig --add nginx #設為開機啟動4 chkconfig nginx on #設為開機啟動5 /etc/init.d/nginx restart #重啟MySQL
1 yum install -y mysql mysql-server #安裝Mysql和相關組件2 chkconfig mysqld on #設為開機啟動3 /etc/init.d/mysqld start #啟動MySQL4 cp /usr/share/mysql/my-medium.cnf /etc/my.cnf #拷貝配置文件(注意:如果/etc目錄下面默認有一個my.cnf,直接覆蓋即可)5 service mysqld restart #重啟服務
可以選擇為Mysql重置默認密碼,默認密碼為空,重置密碼命令:
1 mysql_secure_installation
回車,根據提示輸入Y
輸入2次密碼,回車
根據提示一路輸入Y
最后出現:Thanks for using MySQL!
密碼重置后記得重啟Mysql服務
1 service mysqld restartphp
1 yum install -y php #安裝PHP2 yum install -y php-mysql php-gd libjpeg* php-imap php-ldap php-odbc php-Pear php-xml php-xmlrpc php-mbstring php-mcrypt php-bcmath php-mhash libmcrypt libm crypt-devel php-fpm #安裝PHP組件3 service mysqld restart #重啟MySql4 service nginx restart #重啟nginx5 /etc/rc.d/init.d/php-fpm start #啟動php-fpm6 chkconfig php-fpm on #設置開機啟動LNMP配置配置nginx支持php
1 cp /etc/nginx/nginx.conf /etc/nginx/nginx.confbak #備份原有配置文件2 vi /etc/nginx/nginx.conf #編輯
user nginx nginx;#修改nginx運行賬號為:nginx組的nginx用戶
1 cp /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.confbak #備份原有配置文件2 vi /etc/nginx/conf.d/default.conf #編輯index index.php index.html index.htm; #增加index.php
1 # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 2 # 3 location ~ /.php$ { 4 root html; 5 fastcgi_pass 127.0.0.1:9000; 6 fastcgi_index index.php; 7 fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name; 8 include fastcgi_params; 9 }10 # deny access to .htaccess files, if Apache's document root11 # concurs with nginx's one12 #13 location ~ //.ht {14 deny all;15 }16 }
#取消FastCGI server部分location的注釋,并要注意fastcgi_param行的參數,改為$document_root$fastcgi_script_name,或者使用絕對路徑
配置php1 vi /etc/php.ini #編輯
如果查找不到,可以用nano 進行搜索更替
1 nano /etc/php.ini
date.timezone = PRC #在946行 把前面的分號去掉,改為date.timezone = PRC
disable_functions = passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,escapeshellcmd,dll,popen,disk_free_space,checkdnsrr,checkdnsrr,getservbyname,getservbyport,disk_total_space,posix_ctermid,posix_get_last_error,posix_getcwd, posix_getegid,posix_geteuid,posix_getgid, posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid, posix_getppid,posix_getpwnam,posix_getpwuid, posix_getrlimit, posix_getsid,posix_getuid,posix_isatty, posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid, posix_setpgid,posix_setsid,posix_setuid,posix_strerror,posix_times,posix_ttyname,posix_uname
#在386行 列出PHP可以禁用的函數,如果某些程序需要用到這個函數,可以刪除,取消禁用。expose_php = Off #在432行 禁止顯示php版本的信息magic_quotes_gpc = On #在745行 打開magic_quotes_gpc來防止SQL注入open_basedir = .:/tmp/ #在380行,設置表示允許訪問當前目錄(即PHP腳本文件所在之目錄)和/tmp/目錄,可以防止php木馬跨站,如果改了之后安裝程序有問題,可注銷此行,或者直接寫上程序目錄路徑/var/www/html/www.osyunwei.com/:/tmp/
配置php-fpm1 p /etc/php-fpm.d/www.conf /etc/php-fpm.d/www.confbak #備份原有配置文件2 vi /etc/php-fpm.d/www.conf #編輯
user = nginx #修改用戶為nginx
group = nginx #修改組為nginx重啟所有服務1 service nginx restart #重啟Nginx2 service mysqld restart #重啟Mysql3 service php-fpm restart #重啟PHP
最后在瀏覽器中打開就可以看到如下效果:
安裝完成!
|
新聞熱點
疑難解答