大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
注:为了使用方便,需要将php加到系统环境变量中,如果在没有添加到环境变量之前,执行“php -v”命令查看当前php版本信息时时,则会提示命令不存在的错误,添加命令:
创新互联公司专注于庆元网站建设服务及定制,我们拥有丰富的企业做网站经验。 热诚为您提供庆元营销型网站建设,庆元网站制作、庆元网页设计、庆元网站官网定制、成都微信小程序服务,打造庆元网络公司原创品牌,更为您提供庆元网站排名全网营销落地服务。$echo -e \'nexport PATH=/usr/local/php/bin:/usr/local/php/sbin:$PATHn\' >> /etc/profile && source /etc/profile $php -v PHP 7.1.10 (cli) (built: Nov 10 2017 18:02:06) ( NTS ) Copyright (c) 1997-2017 The PHP Group Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies PHP配置
拷贝php7.1.10源码目录下相应配置文件到php安装的etc目录下:
$cd /usr/local/php/etc/ $cp php.ini-production php.ini $cp php-fpm.conf.default php-fpm.conf $cp php-fpm.d/www.conf.default php-fpm.d/www.conf $ls pear.conf php-fpm.conf php-fpm.conf.default php-fpm.d php.ini
php.ini配置
# 不显示错误,默认 display_errors = Off # 在关闭display_errors后开启PHP错误日志(路径在php-fpm.conf中配置),默认 log_errors = On # 字符集,默认 default_charset = "UTF-8" # 文件上传大小,默认值太小,如果是后台应用,一般涉及上传文件,可设置大点 upload_max_filesize = 64M # Maximum size of POST data that PHP will accept. 表单值,默认是8M,如果表单含有多图上传,大小可能不够。超过该大小后台收不到 表单数据 post_max_size = 64M # 设置PHP的扩展库路径,,默认被注释了。 extension_dir = "/usr/local/php7/lib/php/extensions/" # 如果不设置extension_dir,也可以直接写绝对位置: # extension=/usr/local/php/lib/php/extensions/no-debug-non-zts-20151012/redis.so # 设置PHP的时区 date.timezone = PRC # 开启opcache,默认是0,官方介绍这可以大幅提升性能,建议开启 [opcache] ; Determines if Zend OPCache is enabled opcache.enable=1
php-fpm.conf配置
; 去掉里分号,方便以后重启。建议修改 ; Default Value: none ; 下面的值最终目录是/usr/local/php/var/run/php-fpm.pid ; 开启后可以平滑重启php-fpm pid = run/php-fpm.pid ; 设置错误日志的路径,可以默认值 ; Note: the default prefix is /usr/local/php/var ; Default Value: log/php-fpm.log, 即/usr/local/php/var/log/php-fpm.log error_log = log/php-fpm.log ; Log等级,可以默认值 ; Possible Values: alert, error, warning, notice, debug ; Default Value: notice log_level = notice ; 后台运行,默认yes,可以默认值 ; Default Value: yes ;daemonize = yes ; 引入www.conf文件中的配置,可以默认值,如果没有可手动加入 include=/usr/local/php/etc/php-fpm.d/*.conf
www.conf配置(在etc/php-fpm.d/目录下,它是php-fpm进程服务的扩展配置文件,有些会将此文件内容直接放到php-fpm.conf后面,建议分出来,这样更好维护)
; 设置用户和用户组,默认都是nobody。可以默认值。决定你的php是以什么用户运行,这里配置为www,注意需要添加www用户并添加 ; 到相应用户组 user = www group = www ; 设置PHP监听 ; 下面是默认值,可以默认值。此值与nginx.conf相应配置对应 listen = 127.0.0.1:9000 ; 也可以配置为sock方式。根据nginx.conf中的配置fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock; ; listen = /var/run/php-fpm/php-fpm.sock ######开启慢日志。可以默认值 slowlog = var/log/$pool.log.slow request_slowlog_timeout = 10
添加www用户并设置组(如果已经有www用户可略过)
$useradd www #假如你的运行目录也正巧放在目录下/home/www/src $chown -R www:www /home/www/src
检查phpp-fpm.conf配置文件是否正确
$/usr/local/php/sbin/php-fpm -t [01-Dec-2017 17:06:24] NOTICE: configuration file /usr/local/php/etc/php-fpm.conf test is successful
启动php-fpm
#启动 $/usr/local/php/sbin/php-fpm #其他相关操作命名 $killall php-fpm #关闭 $ps aux |grep php-fpm #查看启动情况 NGINX配置
nginx.conf配置
http { server_tokens off; include mime.types; default_type application/octet-stream; charset utf-8; #解决虚拟主机名字过长 server_names_hash_bucket_size 128; client_header_buffer_size 32k; large_client_header_buffers 4 32k; client_max_body_size 64m; sendfile on; tcp_nopush on; keepalive_timeout 60; tcp_nodelay on; fastcgi_connect_timeout 300; fastcgi_send_timeout 300; fastcgi_read_timeout 300; #fastcgi_buffer_size 64k; #fastcgi_buffers 4 64k; #fastcgi_busy_buffers_size 128k; #fastcgi_temp_file_write_size 128k; fastcgi_buffer_size 128k; fastcgi_buffers 8 128k; fastcgi_busy_buffers_size 256k; fastcgi_temp_file_write_size 256k; #开启gzip gzip on; gzip_min_length 1k; gzip_buffers 4 16k; #gzip_http_version 1.0; gzip_comp_level 2; gzip_types text/plain application/x-javascript text/css application/xml; gzip_vary on; gzip_disable msie6; #设置nginx日志格式 log_format access \'Time: $time_iso8601 \' \'Remote Addr: $remote_addr \' \'Request: $request \' \'Status: $status \' \'Body Sent[B]:$body_bytes_sent \' \'Http Referer: $http_referer \' \'Http User Agent: $http_user_agent \' \'Http x Forwarded For: $http_x_forwarded_for\'; access_log off; #文件底部添加,避免多个web服务配置在一个nginx.conf文件下,以便更好的维护 include /usr/local/nginx/conf/vhosts/*.conf; }
添加你需要的web服务配置到vhosts下,如g.ktvme.com.conf,命名自己看得懂即可
server { listen 8080; server_name g.ktvme.com; charset utf-8; root /home/www/src/g.ktvme.com/public; index index.php; location / { if (!-e $request_filename) { rewrite ^(.*)$ /index.php$1 last; break; } } location ~ .php$ { fastcgi_pass 127.0.0.1:9000;#对应php-fpm.d/www.conf listen配置 fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /home/www/src/g.ktvme.com/public/$fastcgi_script_name; include fastcgi_params; } location ~ .+.php($|/) { #配置PHP支持PATH_INFO进行URL重写 set $script $uri; set $path_info "/"; if ($uri ~ "^(.+.php)(/.+)"){ set $script $1; set $path_info $2; } fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php?IF_REWRITE=1; include fastcgi_params; fastcgi_param SCRIPT_FILENAME /home/www/src/g.ktvme.com/public/$script; fastcgi_param PATH_INFO $path_info; fastcgi_param SCRIPT_NAME $script; } }
启动nginx
#查看nginx 配置是否ok $nginx -t nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful #启动 $nginx #或/usr/local/nginx/sbin/nginx #重启 $nginx -s reload #停止 $nginx -s stop
到此就完成php和ngnix的配置,理论应该可以正常访问到你的web服务
memeched服务安装1、包地址:http://memcached.org/downloads
2、memcached需依赖于libevent,所以没有安装的需先安装libevent:
下载地址:http://www.monkey.org/~provos/libevent/
进入libevent包目录
$./configure --prefix=/usr/local/libevent # (/usr/local/libevent 是安装路径) $make && make install
3、memcached安装
进入memcached目录
$./configure --prefix=/usr/local/memcached --with-libevent=/usr/local/libevent/ $make && make install
4、启动Memcache的服务器端:
$/usr/local/memcache/bin/memcached -d -m 10 -u root -l 192.168.0.200 -p 11211-c 256 -P /tmp/memcached.pid
启动参数:
-d 选项是启动一个守护进程,
-m 是分配给Memcache使用的内存数量,单位是MB,默认64MB
-M return error on memory exhausted (rather than removing items)
-u 是运行Memcache的用户,如果当前为root 的话,需要使用此参数指定用户。
-l 是监听的服务器IP地址,默认为所有网卡。
-p 是设置Memcache的TCP监听的端口,最好是1024以上的端口
-c 选项是运行的并发连接数,默认是1024
-P 是设置保存Memcache的pid文件
-f
-I Override the size of each slab page. Adjusts max item size(1.4.2版本新增)
运行ps aux|grep memcached
若有memcached相关进程则说明成功!
杀死memcahed
$kill `cat /tmp/memcached.pid`
5、设置开机启动
写服务脚本
$vi /etc/init.d/memcached #写入以下脚本 #!/bin/sh # # memcached: MemCached Daemon # # chkconfig: - 90 25 # description: MemCached Daemon # # Source function library. . /etc/rc.d/init.d/functions . /etc/sysconfig/network #[ ${NETWORKING} = "no" ] && exit 0 #[ -r /etc/sysconfig/dund ] || exit 0 #. /etc/sysconfig/dund #[ -z "$DUNDARGS" ] && exit 0 MEMCACHED="/usr/local/memcache/bin/memcached" SERVER_IP="127.0.0.1" SERVER_PORT="11211" [ -f $MEMCACHED ] || exit 1 start() { echo -n $"Starting memcached: " daemon $MEMCACHED -u daemon -d -m 2048 -l $SERVER_IP -p $SERVER_PORT -P /tmp/memcached.pid echo } stop() { echo -n $"Shutting down memcached: " killproc memcached echo } # See how we were called. case "$1" in start) start ;; stop) stop ;; restart) stop sleep 3 start ;; *) echo $"Usage: $0 {start|stop|restart}" exit 1 esac exit 0
设置启动服务
$chmod 755 /etc/init.d/memcached #增加执行权限 $chkconfig memcached on #设置开机启动 $chkconfig --list memcached #查看是否设置成功
服务管理命令
$service memcached start # 启动memcached $service memcached stop # 关闭memcached $service memcached restart # 重启memcached