Nginx PHP Configuration

Source: Internet
Author: User
Tags configuration php
CentOS 6.2 Yum Installation configuration Lnmp server (nginx+php+mysql)
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 (allow 80 ports via firewall)
-A input-m state--state new-m tcp-p TCP--dport 3306-j ACCEPT (Allow 3306 ports via firewall)
Special 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 22 port under this rule
After adding the firewall rules as follows:
#########################################################
# Firewall configuration written by System-config-firewall
# Manual Customization of this file are 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-prohibited
COMMIT
#########################################################
System operation and maintenance www.osyunwei.com warm reminder: qihang01 original content? Copyright, reproduced Please indicate the source and the original link
/etc/init.d/iptables Restart #最后重启防火墙使配置生效
2. Turn off SELinux
Vi/etc/selinux/config
#SELINUX =enforcing #注释掉
#SELINUXTYPE =targeted #注释掉
Selinux=disabled #增加
: Wq Save, close
Shutdown-r now #重启系统
3. Configure CentOS 6.2 Third-party yum Source (no Nginx package in CentOS default standard source)
Yum Install wget #安装下载工具wget
wget http://www.atomicorp.com/installers/atomic #下载atomic Yum Source
Sh./atomic #安装
Yum Check-update #更新yum软件包
#############################################################################
Installation article:
First, install Nginx
Yum install Nginx #安装nginx, follow the prompts, enter the Y installation can be installed successfully
Service Nginx Start #启动
Chkconfig Nginx on #设为开机启动
/etc/init.d/nginx Restart #重启
rm-rf/usr/share/nginx/html/* #删除ngin默认测试页
Two install MySQL
1. install MySQL
Yum install MySQL mysql-server #询问是否要安装, enter y for automatic installation 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)
Shutdown-r now #重启系统
2. Set the password for the root account
Mysql_secure_installation
Enter, follow the prompts for Y
Enter Password 2 times, enter
Enter Y as prompted
Last appearance: Thanks for using mysql!
System operation and maintenance www.osyunwei.com warm reminder: qihang01 original content? Copyright, reproduced Please indicate the source and the original link
MySQL password setup is complete, restart MySQL:
/etc/init.d/mysqld Stop #停止
/etc/init.d/mysqld Start #启动
Service mysqld Restart #重启
Third, install PHP
1. Install PHP
Yum Install PHP #根据提示输入Y直到安装完成
2, install PHP components, so that PHP support MySQL, PHP support fastcgi Mode
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 libmcrypt-devel php-fpm #根据提示输入Y回车
/etc/init.d/mysqld Restart #重启MySql
/etc/init.d/nginx Restart #重启nginx
/ETC/RC.D/INIT.D/PHP-FPM Start #启动php-fpm
Chkconfig PHP-FPM on #设置开机启动
#############################################################################
Configuration Chapter
First, the configuration Nginx support PHP
Cp/etc/nginx/nginx.conf/etc/nginx/nginx.confbak #备份原有配置文件
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
System operation and maintenance www.osyunwei.com warm reminder: qihang01 original content? Copyright, reproduced Please indicate the source and the original link
# 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
Second, configure PHP
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,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行 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
Open_basedir =.:/ tmp/#在380行, set 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, you can log off this line, or directly write the program directory path/var/www/html/ www.osyunwei.com/:/tmp/
: wq! #保存退出
Third, configuration php-fpm
System operation and maintenance www.osyunwei.com warm reminder: qihang01 original content? Copyright, reproduced Please indicate the source and the original link
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
/etc/init.d/mysqld Restart #重启MySql
/etc/init.d/nginx Restart #重启nginx
/ETC/RC.D/INIT.D/PHP-FPM Restart #重启php-fpm
#############################################################################
Test article
cd/usr/share/nginx/html/#进入nginx默认网站根目录
VI index.php #新建index. php file
Phpinfo ();
?>
: wq! #保存
Chown nginx.nginx/usr/share/nginx/html/-R #设置目录所有者
chmod700/usr/share/nginx/html/-R #设置目录权限
In the client browser enter the server IP address, you can see the relevant configuration information!
#############################################################################

The above describes the Nginx PHP configuration, including the installation of mysql,fastcgi mode, chmod aspects of the content, I hope that the PHP tutorial interested in a friend helpful.

  • 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.