CentOS 6.4 Installation Configuration Lnmp server (nginx+php+mysql)

Source: Internet
Author: User
Tags configuration php fpm install php php script sql injection iptables

Prepare the article

1, configure the firewall, open 80 ports, 3306 ports
Vi/etc/sysconfig/iptables
-A input-m state--state new-m tcp-p TCP--dport 80-j ACCEPT #允许80端口通过防火墙
-A input-m state--state new-m tcp-p TCP--dport 3306-j ACCEPT #允许3306端口通过防火墙

Note: Many netizens add these two rules to the last line of the firewall configuration, causing the firewall to fail to start.

The correct one should be added to the default port 22 below this rule

The

is as follows:
################################ After the firewall rule is added ################################
# Firewall Configuration written by System-config-firewall
# Manual Customization of the This file was 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--r Eject-with icmp-host-prohibited
COMMIT
################################################################## #####################
/etc/init.d/iptables restart  #最后重启防火墙使配置生效

2. Turn off SELinux
Vi/etc/selinux/config
#SELINUX =enforcing #注释掉
#SELINUXTYPE =targeted #注释掉
Selinux=disabled #增加
: Wq #保存退出
Shutdown-r now #重启系统

3. Install a third-party yum Source

Yum Install wget #安装下载工具

wget http://www.atomicorp.com/installers/atomic #下载

Sh./atomic #安装

Yum Check-update #更新yum源

Installation article

First, install Nginx

Yum Remove httpd* php* #删除系统自带的软件包

Yum install Nginx #安装nginx Follow the prompts to enter Y for installation

Chkconfig Nginx on #设置nginx开机启动

Service Nginx Start #启动nginx

Second, install MySQL

1. Install MySQL

Yum install MySQL mysql-server #输入Y即可自动安装 until installation is complete

/etc/init.d/mysqld Start #启动MySQL

Chkconfig mysqld on #设为开机启动

CP/USR/SHARE/MYSQL/MY-MEDIUM.CNF/ETC/MY.CNF #拷贝配置文件 (Note: If the/etc directory has a my.cnf under the default, you can directly overwrite it)

2. Set the password for the root account

Mysql_secure_installation

#回车, enter Y as prompted, enter the password 2 times, enter Y as prompted, and finally appear: Thanks for using mysql!

MySQL password setup is complete, restart MySQL:

/etc/init.d/mysqld Restart #重启

/etc/init.d/mysqld Stop #停止

/etc/init.d/mysqld Start #启动

Third, installation PHP5

1, installation PHP5

Yum Install PHP php-fpm #根据提示输入Y直到安装完成

2, install PHP components, so that PHP5 support MySQL

Yum install php-mysql php-gd libjpeg* php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-mcrypt php-b Cmath Php-mhash Libmcrypt

#这里选择以上安装包进行安装, enter Y return as prompted

Chkconfig php-fpm on #设置php-fpm boot up

/ETC/INIT.D/PHP-FPM Start #启动php-fpm

Configuration Chapter

First, the configuration Nginx support PHP
cp/etc/nginx/nginx.conf/etc/nginx/nginx.confbak# backing up legacy configuration Files
Vi/etc/nginx/nginx.conf #编辑
User Nginx Nginx; #修改nginx运行账号为: Nginx User of Nginx Group
: Wq #保存退出
Cp/etc/nginx/conf.d/default.conf/etc/nginx/conf.d/default.confbak #备份原有配置文件
Vi/etc/nginx/conf.d/default.conf #编辑

Index index.php index.html index.htm; #增加index. php

# 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;
}
#取消FastCGI the comment for the server section location, and note the parameters of the Fastcgi_param row, change to $document_root$fastcgi_script_name, or use the absolute path
Service Nginx Restart #重启nginx

Second, PHP configuration
Vi/etc/php.ini #编辑
Date.timezone = PRC #在946行 Remove the preceding semicolon and change to 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,ope

Nlog,syslog,readlink,symlink,popepassthru,stream_socket_server,escapeshellcmd,dll,popen,disk_free_space, Checkdnsrr,checkdns

RR,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行 lists the functions that PHP can disable, and if some programs need to use this function, you can delete and cancel the disabled.
expose_php = Off #在432行 Suppress the PHP version information
MAGIC_QUOTES_GPC = on #在745行 open MAGIC_QUOTES_GPC to prevent SQL injection
Short_open_tag = on #在229行支持php短标签
Open_basedir =.:/ tmp/#在380行 settings to allow access to the current directory (that is, the php script file directory) and/tmp/directory, you can prevent the PHP Trojan cross-site, if you change the installation program after the problem (for example: Dream Content Management System), you can log off this line, or directly write the program directory/data/ www.osyunwei.com/:/tmp/
: wq! #保存退出

Third, configuration php-fpm
Cp/etc/php-fpm.d/www.conf/etc/php-fpm.d/www.confbak #备份原有配置文件
Vi/etc/php-fpm.d/www.conf #编辑
user = Nginx #修改用户为nginx
Group = Nginx #修改组为nginx
: Wq #保存退出

Test article

Cd/usr/share/nginx/html

VI index.php #添加以下代码
<?php
Phpinfo ();
?>

: wq! #保存退出

Chown Nginx.nginx/usr/share/nginx/html-r #设置权限

Service Nginx Restart #重启nginx

Service php-fpm Restart #重启php-fpm

In the client browser enter the server IP address, you can see the relevant configuration information!

Description LNMP Configuration succeeded!

At this point, the Cnetos 6.4 installation configuration Lnmp (Nginx+php+mysql) tutorial is complete.

CentOS 6.4 Installation Configuration Lnmp server (nginx+php+mysql)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.