1818IP-服务器技术教程,云服务器评测推荐,服务器系统排错处理,环境搭建,攻击防护等

当前位置:首页 - 运维 - 正文

君子好学,自强不息!

Linux Nginx安装配置文件支持PHP

2022-11-12 | 运维 | admin | 591°c
A+ A-

在向大家详细介绍Linux Nginx之前,首先让大家了解下Linux Nginx,然后全面介绍Linux Nginx,希望对大家有用。利用Linux Nginx架设高性能的Web环境 Linux Nginx (“engine x”) 是一个高性能的 HTTP 和反向代理服务器,也是一个 IMAP/POP3/SMTP 代理服务器。 Linux Nginx 是由 Igor Sysoev 为俄罗斯访问量第二的 Rambler.ru 站点开发的,它已经在该站点运行超过两年半了。Igor 将源代码以类BSD许可证的形式发布。

Linux Nginx 超越 Apache 的高性能和稳定性,使得国内使用Linux Nginx作为 Web 服务器的网站也越来越多,其中包括新浪博客、新浪播客、网易新闻等门户网站频道,六间房、56.com等视频分享网站,Discuz!官方论坛、水木社区等知名论坛,豆瓣、YUPOO相册、海内SNS、迅雷在线等新兴Web 2.0网站。

实验环境Centos4.5

pcre-7.8.tar.gz正则表达式下载地址:ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/ nginx-0.7.26.tar下载地址:http://www.nginx.net/ php-5.2.6.tar.bz2下载地址:http://www.php.net/releases/ php-5.2.6-fpm-0.5.9.diff.gz php-fpm是为PHP打的一个FastCGI管理补丁,可以平滑变更php.ini配置而无需重启php-cgi下载地址:http://php-fpm.anight.org/ 注:PHP的版本要和fpm的版本一致mysql-5.0.67.tar.gz Discuz!_6.0.0_SC_UTF8.zip






1、安装pcre

#tar-zxvfpcre-7.8.tar.gz #cdpcre-7.8 #./configure #make&&makeinstall



2、安装Linux Nginx

#tar-zxvfnginx-0.7.26.tar.gz #cdnginx-0.7.26 #./configure--prefix
=/usr/local/nginx #make&&makeinstall



启动nginx#/usr/local/nginx/sbin/nginx 停止nginx#kill-QUIT`cat/usr/local/nginx/logs/nginx.pid` 重启nginxkill-HUP`cat/usr/local/nginx/logs/nginx.pid` 添加到自启动#echo"/usr/local/nginx/sbin/nginx">>
/etc/rc.local



3、安装mysql

#tar-zxvfmysql-5.0.67.tar.gz #cdmysql-5.0.67 #groupaddmysql #useradd-gmysql-s/sbin/nologin-Mmysql #./configure--prefix
=/usr/local/mysql--with-charset
=gbk
--with-extra-charset
=all
--enable-hread-safe-client
--enable-local-infile--with-low-memory #make&&makeinstall #cpsupport-files/my-medium.cnf/etc/my.cnf #chown-Rmysql.mysql/usr/local/mysql/ #/usr/local/mysql/bin/mysql_install_db--user
=mysql
#chown-Rroot.root/usr/local/mysql/ #chown-Rmysql.mysql/usr/local/mysql/var/










启动数据库服务,并添加到自启动

#/usr/local/mysql/bin/mysqld_safe--user
=mysql
& #cpsupport-files/mysql.server/etc/rc.d/init.d/mysqld #chmod755/etc/rc.d/init.d/mysqld


加入自动启动服务队列:

#chkconfig--addmysqld #chkconfig--level345mysqldon添加root密码 #/usr/local/mysql/bin/mysqladmin-urootpassword"123456" 测试一下:#/usr/local/mysql/bin/mysql-uroot-p输入密码:123456,看能不能进入到数据库



配置库文件搜索路径

#echo"/usr/local/mysql/lib/mysql">>
/etc/ld.so.conf #ldconfig #ldconfig-v 添加/usr/local/mysql/bin到环境变量PATH中 #echo"exportPATH
=$PATH:/usr/local/mysql/bin">>
/etc/profile #source/etc/profile





4、安装PHP

这里产生的是可执行文件,和apache的不一样,和apache结合的时候产生的是动态库

#tar-jxvfphp-5.2.6.tar.bz2 #gzip-cdphp-5.2.6-fpm-0.5.9.diff.gz|patch-dphp-5.2.6-p1 #cdphp-5.2.6 #./configure--prefix
=/usr/local/php--with-mysql
=/usr/local/mysql--enable-fastcgi--enable-fpm --with-config-file-path
=/usr/local/php/etc--enable-force-cgi-redirect #make&&makeinstall #cpphp.ini-recommended/usr/local/php/etc/php.ini #vi/usr/local/php/php-fpm.conf







(1)<value
name
="listen_address"
>
127.0.0.1:9000</value>
修改为<value
name
="listen_address"
>
IP:9000</value>

//本机就用默认的127.0.0.1 (2)下面这两行去掉注释并修改 <value
name
="sendmail_path"
>
/usr/sbin/sendmail-t-i</value>
<value
name
="display_errors"
>
1</value>
(3)<value
name
="user"
>
nobody</value>
//去注释 (4)<value
name
="group"
>
nobody</value>
//去注释 (5)<value
name
="allowed_clients"
>
127.0.0.1</value>
//允许连接的PC,本机就用127.0.0.1






启动php-fpm# /usr/local/php/sbin/php-fpm start添加到自启动# echo “/usr/local/php/sbin/php-fpm start”>>/etc/rc.local

5、修改Linux Nginx的配置文件,支持PHP

#vi/usr/local/nginx/conf/nginx.conf usernobody; worker_processes8; pid/usr/local/nginx/logs/nginx.pid; worker_rlimit_nofile1024; events {useepoll; worker_connections1024;} http{ includemime.types; default_typeapplication/octet-stream; server_names_hash_bucket_size128; client_header_buffer_size32k; large_client_header_buffers432k; client_max_body_size8m;














sendfileon; tcp_nopushon; keepalive_timeout60; tcp_nodelayon; fastcgi_connect_timeout300; fastcgi_send_timeout300; fastcgi_read_timeout300; fastcgi_buffer_size64k; fastcgi_buffers464k; fastcgi_busy_buffers_size128k; fastcgi_temp_file_write_size128k; gzipon; gzip_min_length1k; gzip_buffers416k; gzip_http_version1.0; gzip_comp_level2; gzip_typestext/plainapplication/x-javascripttext/cssapplication/xml; gzip_varyon; server{ listen80; server_namewww.bbb.com; root/var/www/blog; indexindex.htmlindex.htmindex.php; location~.*\.(php|php5)?${ roothtml; fastcgi_pass127.0.0.1:9000; fastcgi_indexindex.php; fastcgi_paramSCRIPT_FILENAME/var/www/blog$fastcgi_script_name; includefastcgi_params;} location~.*\.(gif|jpg|jpeg|png|bmp|swf)$ {expires30d;} location~.*\.(js|css)?$ {expires1h;} log_formataccess'$remote_addr-$remote_user[$time_local]"$request"' '$status$body_bytes_sent"$http_referer"' '"$http_user_agent"$http_x_forwarded_for'; access_log/var/logs/access.logaccess;}}





































注:server部分为PHP虚拟主机127.0.0.1:9000为fastcgi的PC,我这里用的本机/var/www/blog$fastcgi_script_name; 为PHP网页保存的目录测试配置文件: # /usr/local/nginx/sbin/nginx -t

6、优化Linux内核参数

#vi/etc/sysctl.conf 在末尾增加以下内容: net.ipv4.tcp_fin_timeout
=30
net.ipv4.tcp_keepalive_time
=300
net.ipv4.tcp_syncookies
=1
net.ipv4.tcp_tw_reuse
=1
net.ipv4.tcp_tw_recycle
=1
net.ipv4.ip_local_port_range
=5000
65000







使配置立即生效:# /sbin/sysctl -p。

本文来源:1818IP

本文地址:https://www.1818ip.com/post/8743.html

免责声明:本文由用户上传,如有侵权请联系删除!

发表评论

必填

选填

选填

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。