快速搭建LNMP

[centos 6.4 server]
系統安裝請參考:http://blog.zhuyin.org/748.html
1.防火牆設置:php

iptables -F
service iptables save
service iptables restart
vim /etc/sysconfig/iptables
#######################
.....
:OUTPUT ACCEPT [4:512]
-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-prohibited
COMMIT
...
#########################
service iptables restart

 

2.關閉SELINUX 並設置指定IPhtml

vim /etc/selinux/config

#####
#SELINUX=enforcing
#SELINUXTYPE=targeted
SELINUX=disabled
#####
vim /etc/sysconfig/network-scripts/ifcfg-eth0

###########
DEVICE=eth0
HWADDR=00:0C:29:55:98:1E
TYPE=Ethernet
ONBOOT=yes
BOOTPROTO=none
NETMASK=255.255.0.0
IPADDR=172.26.11.100
GATEWAY=172.26.0.1
###########
vim /etc/resolv.conf

###########
search localdomain
nameserver 8.8.8.8
nameserver 202.96.128.68
nameserver 202.106.0.20
########### service network restart

 

3.更新yum源mysql

yum check-update

#刪除系統自帶的apache/php 等·····(有可能系統有自動裝上這些了…)
yum remove httpd* php*

 

4.安裝nginx
因爲centos沒有默認的nginx軟件包,須要啓用REHL的附件包linux

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

#設置nginx開機啓動
chkconfig nginx on

#啓動nginx
service nginx start

 

ok,直接訪問:http://172.26.11.100/ 便可看nginx是否正常運行了。nginx

5.安裝MySQLweb

yum -y install mysql-server

/etc/init.d/mysqld start

#設爲開機啓動
chkconfig mysqld on
#配置文件
cp /usr/share/mysql/my-medium.cnf /etc/my.cnf
#爲root帳戶設置密碼 回車,根據提示輸入Y,輸入2次密碼,回車,根據提示一路輸入Y,最後出現:Thanks for using MySQL!
mysql_secure_installation

#MySql密碼設置完成,從新啓動 MySQL
/etc/init.d/mysqld stop
/etc/init.d/mysqld start

SQLyog連接linux虛擬機上的mysql數據庫
對用戶進行遠程訪問受權
命令:mysql> GRANT ALL PRIVILEGES ON *.* TO '用戶名'@'%' IDENTIFIED BY '密碼' WITH GRANT OPTION;
Query OK, 0 rows affected (0.02 sec)


mysql>  FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

 二進制安裝mysqlsql

6.安裝php5shell

yum install zlib libxml libjpeg freetype libpng gd curl libiconv zlib-devel libxml2-devel libjpeg-devel  freetype-devel libpng-devel gd-devel curl-devel -y
#檢查安裝包
rpm -qa ......
安裝 libiconv libmcrypt mhash mcrypt

yum -y install php php-fpm 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 #設置php-fpm開機啓動 chkconfig php-fpm on #啓動php-fpm /etc/init.d/php-fpm start

 yum安裝php5.6數據庫

rpm -Uvh http://ftp.iij.ad.jp/pub/linux/fedora/epel/6/i386/epel-release-6-8.noarch.rpm;
rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm;
yum list --enablerepo=remi --enablerepo=remi-php56 | grep php;
yum install --enablerepo=remi --enablerepo=remi-php56 php php-mysql php-opcache php-pecl-apcu php-devel php-mbstring php-mcrypt php-mysqlnd php-phpunit-PHPUnit php-pecl-xdebug php-pecl-xhprof php-pdo php-pear php-fpm php-cli php-xml php-bcmath php-process php-gd php-common;
php -v;

  

7.配置nginx支持phpapache

cp /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.confbak #備份原有配置文件
vim /etc/nginx/conf.d/default.conf

######################
....
index index.php index.html index.htm;
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
    #root html;#注意這一行請註釋掉!!!
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
}
######################

 

這裏能夠用netstat -ntpl 查看php-fpm的監聽端口127.0.0.1:9000是否是真的存在
注意fastcgi_param行的參數,改成$document_root$fastcgi_script_name,或者使用絕對路徑
location ~ \.php$ { 裏面的 root html;請註釋掉,否則就覆蓋外面的root了!!!!

#重啓nginx
service nginx restart

#配置php.ini
vim /etc/php.ini ##下面的設置內容僅供參考!!!

#########################
...
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
#禁用某些危險函數!
expose_php = Off #禁止顯示php版本的信息
magic_quotes_gpc = On #打開magic_quotes_gpc來防止SQL注入  這個仍是關閉吧。。。。不一樣的版本有點問題
short_open_tag = ON #支持php短標籤
open_basedir = .:/tmp/ #設置容許訪問當前目錄(即PHP腳本文件所在之目錄)和/tmp/目錄,能夠防止php木馬跨站,若是改了以後安裝程序有問題(例如:織夢內容管理系統),能夠註銷此行,或者直接寫上程序的目錄/data/web/test/:/tmp/
############################
#配置php-fpm
cp /etc/php-fpm.d/www.conf /etc/php-fpm.d/www.confbak
vim /etc/php-fpm.d/www.conf

#################################
user = nginx
group = nginx
#################################
cat /etc/passwd 能夠查看有沒有nginx的用戶組和用戶

重啓nginx和php
/etc/init.d/nginx restart
/etc/init.d/php-fpm restart

寫個phpinfo訪問結果以下:
<?php
phpinfo();
?>

 

 

方法二 快速安裝nginx +php +mysql

[root@greymouster ~]# vi /etc/yum.repos.d/nginx.repo [nginx] name=nginx repo baseurl=http://nginx.org/packages/centos/6/$basearch/ gpgcheck=0 enabled=1 [root@greymouster ~]# yum list nginx [root@greymouster ~]# yum install nginx
[root@greymouster ~]# /etc/init.d/nginx start

[root@greymouster ~]# yum install php php-fpm
[root@greymouster ~]# /etc/init.d/php-fpm start

[root@greymouster ~]# vi /etc/nginx/conf.d/default.conf

   location ~ \.php$ {
       root /usr/share/nginx/html;
       fastcgi_pass 127.0.0.1:9000;
       fastcgi_index index.php;
       fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
       include fastcgi_params;
   }

   [root@greymouster ~]# /etc/init.d/nginx restart

   [root@greymouster ~]# cat >>/usr/share/nginx/html/info.php<<EOF

   > <?php
   > phpinfo();
   > EOF

   [root@greymouster ~]# yum install mysql mysql-server

   [root@greymouster ~]# mysql_install_db

   [root@greymouster ~]# mysqld_safe &

   [root@greymouster ~]# mysql -uroot

   [root@greymouster ~]# yum install php-mysql

   [root@greymouster ~]# /etc/init.d/php-fpm restart

若是忘記mysql密碼

    

第一步,先停掉msyql服務,固然我沒有中止服務後面也是能夠的。

 

第二步,修改Mysql的登陸配置,在ect/my.cnf裏

 

添加skip-grant-tables 用來跳過權限檢查,這裏要注意,必定要寫在[mysqld]的下面

datadir = /usr/local/mysql/data
socket=/var/lib/mysql/mysql.sock

我就是由於寫到下面的[mysqld_safe]裏去了,致使第一次修改沒有生效

 

修改完後就是這個樣子:

 

第三步,重啓Mysql服務

相關文章
相關標籤/搜索