设为首页 收藏本站
查看: 3271|回复: 0

LNMP服务器安装配置(Rhel+Nginx+PHP+MySQL)

[复制链接]
累计签到:2 天
连续签到:1 天
发表于 2016-1-11 09:07:41 | 显示全部楼层 |阅读模式
1、关闭selinux、配置防火墙,开启80、3306端口

1
2
3
4
5
6
7
8
9
10
11
12
13
[iyunv@localhost ~]# cp /etc/sysconfig/iptables /etc/sysconfig/iptablesbak
[iyunv@localhost ~]# vim /etc/sysconfig/iptables
-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
[iyunv@localhost ~]# /etc/init.d/iptables restart
[iyunv@localhost ~]# cp /etc/sysconfig/selinux /etc/sysconfig/selinuxbak
[iyunv@localhost ~]# cat /etc/sysconfig/selinux|grep -v "#"
SELINUX=disabled
SELINUXTYPE=targeted
[iyunv@localhost ~]#



2、安装nginx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[iyunv@localhost ~]# rpm -e --nodeps `rpm -qa|egrep -i "httpd|php"`  #删除系统自带的软件包
[iyunv@localhost ~]# wget   #下载、安装第三方yum源
[iyunv@localhost ~]# sh ./atomic   #安装
Do you agree to these terms? (yes/no) [Default: yes] yes
Configuring the [atomic] yum archive for this system
Installing the Atomic GPG keys: OK
OK
Enable repo by default? (yes/no) [Default: yes]:
The Atomic Rocket Turtle archive has now been installed and configured for your system
The following channels are available:
[iyunv@localhost ~]# yum check-update   #更新yum源
[iyunv@localhost ~]# yum -y install nginx
[iyunv@localhost ~]# service nginx start
Starting nginx:                                            [  OK  ]
[iyunv@localhost ~]#



3、安装MySQL
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
[iyunv@localhost ~]# yum install mysql mysql-server -y
[iyunv@localhost ~]# chkconfig mysqld on
[iyunv@localhost ~]# /etc/init.d/mysqld start
[iyunv@localhost ~]# cp /usr/share/mysql/my-medium.cnf /etc/my.cnf
cp: overwrite `/etc/my.cnf'? y
[iyunv@localhost ~]# mysql_secure_installation   #为root账户设置密码
Enter current password for root (enter for none):
OK, successfully used password, moving on...
Set root password? [Y/n] Y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
... Success!
Remove anonymous users? [Y/n] Y  
... Success!
Disallow root login remotely? [Y/n] Y
... Success!
Remove test database and access to it? [Y/n] Y
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!
Reload privilege tables now? [Y/n] Y
... Success!
Thanks for using MySQL!
[iyunv@localhost ~]# service mysqld restart



4、安装PHP5
1
2
3
4
5
6
[iyunv@localhost ~]# yum install php php-fpm -y
[iyunv@localhost ~]# yum install 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 -y  #安装PHP组件,使 PHP5 支持 MySQL
[iyunv@localhost ~]# chkconfig php-fpm on
[iyunv@localhost ~]# /etc/init.d/php-fpm start
Starting php-fpm:                                          [  OK  ]
[iyunv@localhost ~]#



5、配置nginx支持php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
[iyunv@localhost ~]# cp /etc/nginx/nginx.conf /etc/nginx/nginx.confbak
[iyunv@localhost ~]# vim /etc/nginx/nginx.conf
user              nginx nginx;    #修改nginx运行账号为:nginx组的nginx用户
worker_processes  1;
[iyunv@localhost ~]# cp /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.confbak
[iyunv@localhost ~]# vim /etc/nginx/conf.d/default.conf
    location / {
        root   /usr/share/nginx/html;
        index  index.php index.html index.htm;   #增加index.php
        # example
        #ModSecurityEnabled on;
        #ModSecurityConfig /etc/nginx/modsecurity.conf;
    }
     location ~ \.php$ {    #取location的注释,并将fastcgi_param行的参数,改为$document_root$fastcgi_script_name,或者使用绝对路径
        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;
    }   
[iyunv@localhost ~]# service nginx restart
Stopping nginx:                                            [  OK  ]
Starting nginx:                                            [  OK  ]
[iyunv@localhost ~]#



6、php配置
1
2
3
4
5
6
7
8
[iyunv@localhost ~]# cp /etc/php.ini /etc/php.inibak
[iyunv@localhost ~]# vim /etc/php.ini
878 date.timezone = PRC
314 disable_functions = passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,in     i_alter,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,escapesh     ellcmd,dll,popen,disk_free_space,checkdnsrr,checkdnsrr,getservbyname,getservbyport,disk_total_space,posix_c     termid,posix_get_last_error,posix_getcwd, posix_getegid,posix_geteuid,posix_getgid, posix_getgrgid,posix_ge     tgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid, posix_getppid,posix_getpwna     m,posix_getpwuid, posix_getrlimit, posix_getsid,posix_getuid,posix_isatty, posix_kill,posix_mkfifo,posix_se     tegid,posix_seteuid,posix_setgid, posix_setpgid,posix_setsid,posix_setuid,posix_strerror,posix_times,posix_     ttyname,posix_uname   #PHP禁用的函数,如果某些程序需要用到这个函数,可以删除,取消禁用。
  375 expose_php = Off    #禁止显示php版本的信息
  211 short_open_tag = ON   #支持php短标签
  308 open_basedir = .:/tmp/  #设置表示允许访问当前目录(即PHP脚本文件所在之目录)和/tmp/目录,可以防止php木马跨站,如果改了之后安装程序有问题(例如:nginx可能网站根目录下的文件会提示Access Denied),可以注销此行,或者直接写上程序的目录open_basedir = /usr/share/nginx/html/:/tmp/
  [iyunv@localhost ~]#



7、配置php-fpm
1
2
3
4
5
6
[iyunv@localhost ~]# cp /etc/php-fpm.d/www.conf /etc/php-fpm.d/www.confbak
[iyunv@localhost ~]# vim /etc/php-fpm.d/www.conf
user = nginx
; RPM: Keep a group allowed to write in log dir.
group = nginx
[iyunv@localhost ~]#



8、测试
1
2
3
4
5
6
7
8
9
10
11
12
13
[iyunv@localhost ~]# cd /usr/share/nginx/html/
[iyunv@localhost html]# vim index.php
<?php
phpinfo();
?>
~   
[iyunv@localhost html]# service nginx restart
Stopping nginx:                                            [  OK  ]
Starting nginx:                                            [  OK  ]
[iyunv@localhost html]# service php-fpm restart
Stopping php-fpm:                                          [  OK  ]
Starting php-fpm:                                          [  OK  ]
[iyunv@localhost html]#



在客户端浏览器输入服务器IP地址,可以看到相关的配置信息(无法查看可以将php.ini中expose_php设置为on、open_basedir注释掉,或者直接写上程序的目录)! 说明lnmp配置成功!


运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-162840-1-1.html 上篇帖子: CentOS6.5搭建LNMP 下篇帖子: xmapp + simpleforum + CentOS 6.5 部署快速论坛 服务器
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表