首先安装nignx
yum install -y nginx
安装php和相关包
yum install php-fpm php-cli php-mysql php-gd php-ldap php-odbc php-pdo php-pecl-memcache php-pear php-mbstring php-xml php-xmlrpc php-mbstring php-snmp php-soap php-devel
pecl install apc
编辑php和php-fpm的配置文件
vim /etc/php.ini
找到:;date.timezone =
修改为:date.timezone = Aisa/Shanghai
找到:disable_functions =
修改为: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
vim /etc/php-fpm.conf
pid = run/php-fpm.pid
vim /etc/php-fpm.d/*.conf
user = nginx #设置php-fpm运行账号为nginx
group = nginx #设置php-fpm运行组为nginx
编辑 nginx的配置文件
[root@node1 nginx]# cat nginx.conf
# For more information on configuration, see:
# * Official English Documentation: http://nginx.org/en/docs/
# * Official Russian Documentation: http://nginx.org/ru/docs/
**user nginx nginx;** 这里要做修改改成nginx的用户组和密码
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
......
[root@node1 nginx]# vim /etc/nginx/nginx.conf
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
**root /usr/share/nginx/html;** 这个就是nginx服务器放置网页界面的路径
**index index.html index.php index.htm**
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
root /usr/share/nginx/html;
index index.html index.htm index.php;
}
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;
}
server里面和 location 进行修改。
然后
[root@node1 nginx]# cd /usr/share/nginx/html
[root@node1 html]# rm -rf *
[root@node1 html]# vim index.php
<?php
phpinfo();
?>
然后启动php-fpm和nginx服务
service nginx start
service php-fpm restart
这样php和nginx 就能建立了