LNMP是Linux+Nginx+MySQL+PHP的简称,是一套完整的PHP网站服务器架构环境。所用Linux发行版为Ubuntu14. 04,所有需要的软件均使用Ubuntu自带apt源下载安装。Ubuntu默认登录不是root用户;所以要加sudo命令才能执行某些 命令;root用户不用加sudo就可以执行命令;如:普通用户:sudo?apt-getupdateroot用户:apt-get update安装php1】第一步安装php包root@zhangyu1:~#?apt-get?install-yphp5-fp m?php5-mysql?php5-curl?php5-gd?php5-intl?php-pear?php5-imagick?ph p5-imap?php5-mcrypt?php5-memcache?php5-ming?php5-ps?php5-pspell?p hp5-recode?php5-snmp?php5-sqlite?php5-tidy?php5-xmlrpc?php5-xsl?p hp-apc?php5-cgi?php5-cliphp5-ldapphp5-odbcphp5-mhashphp5-idn php5-jsonphp5-dev至此所有基本组件已安装完毕,蓝色字体为后添加;可以根据需要继续安装其它可选组件等。2】查看ph p版本信息root@zhangyu1:~#?php5-fpm?-vPHP?5.5.9-1ubuntu4.14?(cli)?(bui lt:?Oct?28?2015?01:34:46)?3】php5相关目录文件/usr/sbin/php5-fpm????php5- fpm启动文件/etc/php5???配置文件目录/etc/init.d/php5-fpm??启动文件/var/log/php5- fpm.log??日志文件4】php5-fpm命令记录#重启php5mailto:root@zhangyu1root@zhangy u1:~#?service?php5-fpm?restartphp5-fpm?stop/waitingphp5-fpm?start /running,?process?21483#停止php5mailto:root@zhangyu1root@zhangyu1:~ #?service?php5-fpm?stopphp5-fpm?stop/waiting#启动php5mailto:root@zh angyu1root@zhangyu1:~#?service?php5-fpm?startphp5-fpm?start/runni ng,?process?21508#平滑重启php5mailto:root@zhangyu1root@zhangyu1:~#?se rvice?php5-fpm?reload#检查配置文件mailto:root@zhangyu1root@zhangyu1:~#? /usr/sbin/php5-fpm?-tNOTICE:?configuration?file?/etc/php5/fpm/php -fpm.conf?test?is?successful#查看php启动情况root@zhangyu1:~#?ps?-ef?|gr ep?phproot?????22422?????1??0?18:02??????????00:00:00?php-fpm:?ma ster?process?(/etc/php5/fpm/php-fpm.conf)www-data?22425?22422??0? 18:02??????????00:00:00?php-fpm:?pool?wwwwww-data?22426?22422??0? 18:02??????????00:00:00?php-fpm:?pool?wwwroot?????22653?22580??0? 19:42?pts/1????00:00:00?grep?--color=auto?php#################### ####################################配置php.ini备份配置文件php.ini和www.co nfroot@zhangyu1:~#?cp?/etc/php5/fpm/php.ini?/etc/php5/fpm/php.ini -bak#把php配置文件链接到系统默认位置root@zhangyu1:~#?ln-s/etc/php5/fpm/php.in i/etc/php.ini?#编辑php.ini文件root@zhangyu1:~#?vim/etc/php.ini?#在9 46行把前面的分号去掉,改为date.timezone=PRC;默认时区date.timezone=PRC#在386行; 禁用不安全的PHP函数,有些php函数是不够安全的,我们必须要加强安全配置,如果做虚拟主机,建议禁止php函数列表如下,如果某些程 序需要用到这个函数,可以删除,取消禁用。(蓝色部分为系统自带)disable_functions?=?pcntl_alarm,pc ntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstoppe d,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstops ig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_ strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,p cntl_exec,pcntl_getpriority,pcntl_setpriority,passthru,exec,syste m,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status ,ini_alter,ini_alter,ini_restore,dl,openlog,syslog,readlink,symli nk,popepassthru,stream_socket_server,escapeshellcmd,dll,popen,dis k_free_space,checkdnsrr,getservbyname,getservbyport,disk_total_sp ace,posix_ctermid,posix_get_last_error,posix_getcwd,?posix_getegi d,posix_geteuid,posix_getgid,?posix_getgrgid,posix_getgrnam,posix _getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpi d,?posix_getppid,posix_getpwnam,posix_getpwuid,?posix_getrlimit,? posix_getsid,posix_getuid,posix_isatty,?posix_kill,posix_mkfifo,p osix_setegid,posix_seteuid,posix_setgid,posix_setpgid,posix_setsi d,posix_setuid,posix_strerror,posix_times,posix_ttyname,posix_una me,proc_close,getmxrr,show_source,highlight_file,dl,socket_listen ,socket_create,socket_bind,socket_accept,socket_connect,stream_so cket_accept,stream_socket_client,ftp_connect,ftp_login,ftp_pasv,f tp_get,sys_getloadavg,#在432行禁止显示php版本的信息expose_php=Off#在745行打 开magic_quotes_gpc来防止SQL注入(这句没找到)magic_quotes_gpc=On?#下面这行没弄;怕出问 题;open_basedir=.:/tmp/#在380行,设置表示允许访问当前目录(即PHP脚本文件所在之目录)和/tmp/ 目录,可以防止php木马跨站,如果改了之后安装程序有问题,可注销此行,或者直接写上程序目录路径/var/www/html/www. osyunwei.com/:/tmp/#查找extension_dir?=?"./"修改为extension_dir?=?"/us r/lib/php5/20121212/"#并在此行后增加以下几行,然后保存:#extension?=?"memcache.so" ??//如果安装memcache,再添加此字段,如果没有则不用extension?=?"pdo_mysql.so"#extensi on?=?"imagick.so"??//如果安装ImageMagick,再添加此字段,如果没有则不用再查找output_buff ering?=?Off修改为output_buffering?=?On或者找到“output_buffering”的注释项,修改为 :output_bufferingDefault?Value:?OnDevelopment?Value:?4096Producti on?Value:?4096###################################配置php-fpm#备份原有配置 文件root@zhangyu1:~#?cp?/etc/php5/fpm/pool.d/www.conf?/etc/php5/fpm /pool.d/www.conf-bak#编辑www.conf文件root@zhangyu1:~#?vim/etc/php5/f pm/pool.d/www.conf;用分号注释下面这句;;listen?=?/var/run/php5-fpm.sock;添加下 面这句;要和nginx配置文件一样listen?=?127.0.0.1:9000;静态方式下开启的php-fpm进程数量pm.ma x_children?=64;动态方式下的起始php-fpm进程数量pm.start_servers?=?20;动态方式下的最小 php-fpm进程数量。保证空闲进程数最小值,如果空闲进程小于此值,则创建新的子进程pm.min_spare_servers?=? 5;动态方式下的最大php-fpm进程数量。保证空闲进程数最大值,如果空闲进程大于此值,此进行清理;对于专用服务器,pm可以设置为 static。pm.max_spare_servers?=35;设置每个子进程重生之前服务的请求数.?对于可能存在内存泄漏的第三 方模块来说是非常有用的.?如果设置为’0′?则一直接受请求.?等同于?PHP_FCGI_MAX_REQUESTS?环境变量.?默认 值:?0.pm.max_requests?=500#修改为配置文件要先检查有没有错误;在最下面有成功的字样;然后重启#检查配置文 件mailto:root@zhangyu1root@zhangyu1:~#?/usr/sbin/php5-fpm?-tNOTICE :?configuration?file?/etc/php5/fpm/php-fpm.conf?test?is?successfu l#重启php5mailto:root@zhangyu1root@zhangyu1:~#?service?php5-fpm?res tartphp5-fpm?stop/waitingphp5-fpm?start/running,?process?21483###################################测试篇#进入nginx默认网站根目录root@zhangyu1:~#?cd/usr/share/nginx/html/编辑index.php文件root@zhangyu1:~#?vimindex.php#设置目录所有者chown-R?www-data.www-data?/usr/share/nginx/html/#设置目录权限chmod-R700/usr/share/nginx/html/在客户端浏览器输入服务器IP地址,可以看到相关的配置信息! |
|