CnetOS6 System Installation Configuration Nginx+php+mysql Environment

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

Prepare an 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 have added these two rules to the last line of the firewall configuration, causing the firewall to start failing,

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

The

is as follows:
################################ After adding the firewall rules as follows ################################
# Firewall configuration written by System-config-firewall
# Manual Customization The ' This ' file is not recommended.
* Filter
: INPUT ACCEPT [0:0]
: FORWARD ACCEPT [0:0]
: OUTPUT ACCEPT [0:0]
-A input-m State--state Establishe D,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-proh ibited
-A forward-j REJECT--reject-with icmp-host-prohibited
COMMIT
#################################### ###################################################
/etc/init.d/iptables Restart #最后重启防火墙使配置生效

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

3, install the third party yum Source

Yum install wget #安装下载工具

System Operation Dimension Www.111cn.net

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

Sh./atomic #安装

Yum check-update #更新yum源

System Operation Dimension Www.111cn.net

Installation article

I. Installation of Nginx

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

Yum Install nginx #安装nginx Install according to the prompt input y

Chkconfig nginx on #设置nginx开机启动

Service Nginx start #启动nginx

Second, the installation of 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, direct coverage can be)

2. Set password for root account

Mysql_secure_installation

#回车, input y according to the prompts, enter 2 times password, enter, according to the prompts all the way input y, finally appears: the for using mysql!

MySQL password settings complete, restart MySQL:

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

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

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

Iii. installation of PHP5

1. Installation PHP5

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

2, the installation of 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- Bcmath Php-mhash Libmcrypt

#这里选择以上安装包进行安装, enter Y return according to the prompts

Chkconfig php-fpm on #设置php-fpm Boot

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

Configuration Chapter

First, configure Nginx support PHP
Cp/etc/nginx/nginx.conf/etc/nginx/nginx.confbak#备份原有配置文件
vi/etc/nginx/nginx.conf #编辑
User Nginx Nginx; #修改nginx运行账号为: Nginx users of the 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 location of the server section and note the arguments for the Fastcgi_param row, change to $document_root$fastcgi_script_name, or use an absolute path
Service nginx Restart #重启nginx

Second, PHP configuration
Vi/etc/php.ini #编辑
Date.timezone = PRC #在946行 Remove the preceding semicolon and change it 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 remove them and disable them.
expose_php = off #在432行 suppresses the display of 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 that allow access to the current directory (that is, the directory where the php script files) and the/tmp/directory, you can prevent the PHP trojan across the station, if the installation program after the problem ( such as: Dream Content Management System ), you can log off this trip, or write directly to the directory of the program/data/www.111cn.net/:/tmp/
: wq! #保存退出

Third, the 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 input server IP address, you can see the relevant configuration information!

Description LNMP Configuration Successful!

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

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.