linux服务器下LNMP安装与配置方法
发布时间:2023-02-20 09:57:06 所属栏目:LNMP 来源:互联网
导读:注意:关闭rpm默认安装的apache和mysql 1.准备php函数的rpm包 yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2
./configure --with-php-config=/usr/local/php/bin/php-config make make install cd ../ 7. 修改php.ini文件,让php模块生效 vi /usr/local/php/etc/php.ini extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/" 手工添加 extension = "memcache.so" extension = "pdo_mysql.so" extension = "imagick.so" 再查找output_buffering = Off 修改为output_buffering = On 再查找 ; cgi.fix_pathinfo=0 修改为cgi.fix_pathinfo=0,防止Nginx文件类型错误解析漏洞 8. 在php.ini中配置eAccelerator加速PHP mkdir -p /usr/local/eaccelerator_cache #准备eaccelerator缓存目录 vi /usr/local/php/etc/php.ini [eaccelerator] zend_extension="/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/eaccelerator.so" eaccelerator.shm_size="64" eaccelerator.cache_dir="/usr/local/eaccelerator_cache" eaccelerator.enable="1" eaccelerator.optimizer="1" eaccelerator.check_mtime="1" eaccelerator.debug="0" eaccelerator.filter="" eaccelerator.shm_max="0" eaccelerator.shm_ttl="3600" eaccelerator.shm_prune_period="3600" eaccelerator.shm_only="0" eaccelerator.compress="1" eaccelerator.compress_level="9" 9.准备php-cgi和nginx进程执行者用户 useradd nginx 10. 创建php-fpm配置文件- php-fpm.conf vi /usr/local/php/etc/php-fpm.conf <value name="display_errors">0</value> #0改成1,页面上会输出错误日志. 取消注释 unix user of processes <value name="user">nginx</value> Unix group of processes <value name="group">nginx</value> 取消注释 <value name="max_children">128</value> #最大子进程数128,如果内存小于2G,则64个最佳 <value name="rlimit_files">65535</value> # Set open file desc rlimit,同时打开的文件数,linux系统允许同时打开的文件数为1024,修改linux系统中允许同时打开的文件,ulimit -SHn 65535,而且这个参数重启后还能生效,加到 /etc/profile全局配置文件的最后,开机就会生效,ulimit -a查看open files 65535 ulimit 用户控制shell启动进程所占用的资源 -H 设定硬性资源限制,也就是管理员设定的限制 -S 设定软性资源限制,弹性限制 -n 设定可同时打开的最大文件个数 -f 设定单个文件最大大小 -a 查看目前的限制 <value name="max_requests">1024</value> #最大请求数, How much requests each process should execute before respawn.一个子进程能够回应1042个请求 11. 启动php-cgi(fastcgi)进程,监听127.0.0.1的9000端口,进程数为128(如果服务器内存小于3GB,可以只开启64个进程),用户为nginx: 复制代码代码如下: /usr/local/php/sbin/php-fpm start #启动php-cgi /usr/local/php/sbin/php-fpm reload #重新加载配置文件 /usr/local/php/sbin/php-fpm stop #关闭php-fpm,此时nginx肯定连不上php 12. 安装Nginx所需的pcre库 tar zxvf pcre-8.10.tar.gz cd pcre-8.10/ ./configure make && make install cd ../ 13. 安装Nginx 复制代码代码如下: tar zxvf nginx-0.8.46.tar.gz cd nginx-0.8.46/ ./configure --user=nginx --group=nginx --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module make && make install cd ../ 14. 修改Nginx配置文件 vi /usr/local/nginx/conf/nginx.conf user nginx nginx; worker_processes 1; #相当于cpu个数 error_log logs/nginx_error.log; #错误日志 pid /usr/local/nginx/nginx.pid; #主进程PID保存文件 #Specifies the value for maximum file descriptors that can be opened by this process. worker_rlimit_nofile 65535; #文件描述符数量 events { use epoll; #网络I/O模型,建议linux使用epoll,FreeBSD使用kqueue worker_connections 65535; #最大允许连接数 } http { include mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; #日志格式 access_log logs/access.log main; #调用格式的日志 sendfile on; tcp_nopush on; #tcp延迟 keepalive_timeout 65; #保持连接时间 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设置 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; #网络压缩设置 #limit_zone crawler $binary_remote_addr 10m; server { listen 80; #监听端口 server_name 192.168.150.253; #主机名,或IP。如果是主机名,要能够DNS解析 location / { root html; #网站主目录。/usr/local/nginx/html/ index index.html index.htm index.php; #默认网页顺序 } #limit_conn crawler 20; location ~ .*.(php|php5)?$ #~:匹配 后面正则表达式:.*任意字符 .点 php或php5结尾。碰到网页文 件名是.php或.php5结尾 { (编辑:十堰站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |