LinuxApacheNginxMysqlPHP完美配置教程.doc_第1页
LinuxApacheNginxMysqlPHP完美配置教程.doc_第2页
LinuxApacheNginxMysqlPHP完美配置教程.doc_第3页
LinuxApacheNginxMysqlPHP完美配置教程.doc_第4页
LinuxApacheNginxMysqlPHP完美配置教程.doc_第5页
已阅读5页,还剩17页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

Linux+apache+nginx+mysql+php完美配置教程一、准备工作1、安装编译工具gcc、gcc-c+注意解决依赖关系,推荐使用yum安装,若不能联网可使用安装光盘做为yum源1)编辑yum配置文件:# mount /dev/cdrom /mnt/cdrom# vi /etc/yum.repos.d/CentOS-Media.repo c5-media name=CentOS-$releasever - Mediabaseurl=file:/mnt/cdrom * 修改为光盘挂载点 file:/media/cdrom/ file:/media/cdrecorder/gpgcheck=1enabled=1 * 改为1意为启用gpgkey=file:/etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-52)剪切/etc/yum.repos.d/CentOS-Base.repo# mv /etc/yum.repos.d/CentOS-Base.repo /backup3)依次安装gcc、gcc-c+# yum -y install gcc# yum -y install gcc-c+2、关闭系统RPM安装包的Apache、MySQL的服务关闭启动的服务httpd、mysqld# service httpd stop# service mysqld stop确定rpm包安装的httpd和mysqld不能开机自启动chkconfig -level 2345 httpd(mysqld) off3、关闭SELinux,允许防火墙80端口访问1)关闭SELinux# vi /etc/selinux/configSELINUX=disabled * 若安装时没有禁用SELinux ,将enforcing改为disabled修改后需重新启动Linux方可生效!2)关闭防火墙Netfilter/iptables因尚未做防火墙讲解,直接简单的关闭所有防火墙设置:# iptables -F * 如果没有禁用防火墙,默认80端口禁止访问 -Z-X4、关闭不必要自启动服务# ntsysv以下列出服务可保持自启动,未列出的服务都可以关闭:atd crond # atd、crond计划任务irqbalancemicrocode_ctl # 系统irq端口调用,系统服务network #网络设置sendmail #邮件sshd #远程管理syslog #系统日志5、拷贝源码包,解包解压缩 建议将LAMP环境安装源码包统一存放在一个目录下,如/lamp 可编写个批量处理脚本,一次性把所有.tar.gz的安装包解包解压缩 # vi tar.sh cd /lamp/bin/ls *.tar.gz ls.list/bin/ls *.tgz ls.list for TAR in cat ls.list do/bin/tar -zxf $TAR done/bin/rm ls.list6、查看确认磁盘空间未满df -h * 若/分区已满,可以移动安装包到其他分区或删除其他无用文件二、编译安装l 每个源码包配置编译安装完成后,确认安装目录下是否生成安装文件以下版本都是比较稳定的版本,虽然不是最新的软件LinuxApacheNginxMysqlPHP版本Centos0.8.4.141.准备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 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers2.准备lnmp其他的源代码包wget/soft/linux/nginx_php/nginx/nginx-0.8.46.tar.gzwget/soft/linux/nginx_php/imagick/php-5.2.14.tar.gzwget/soft/linux/nginx_php/imagick/httpd-2.2.9.tar.gzwget/soft/linux/nginx_php/phpfpm/php-5.2.6-fpm-0.5.14.diff.gzwget/soft/linux/nginx_php/mysql/mysql-5.5.3-m3.tar.gzwget/soft/linux/nginx_php/libiconv/libiconv-1.13.1.tar.gzwget/soft/linux/nginx_php/mcrypt/libmcrypt-2.5.8.tar.gzwget/soft/linux/nginx_php/mcrypt/mcrypt-2.6.8.tar.gzwget/soft/linux/nginx_php/memcache/memcache-2.2.5.tgzwget/soft/linux/nginx_php/mhash/mhash-.tar.gzwget/soft/linux/nginx_php/pcre/pcre-8.10.tar.gzwget/soft/linux/nginx_php/eaccelerator/eaccelerator-.tar.bz2wget/soft/linux/nginx_php/pdo/PDO_MYSQL-1.0.2.tgzwget/soft/linux/nginx_php/imagick/ImageMagick.tar.gzwget/soft/linux/nginx_php/imagick/phpMyAdmin-3.0.0-rc1-all-languages.tar.gz3.安装php-5.2.14源代码包所需要的函数支持包tar zxvf libiconv-1.13.1.tar.gzcd libiconv-1.13.1/./configure -prefix=/usr/local/libiconvmakemake installcd ./tar zxvf libmcrypt-2.5.8.tar.gzcd libmcrypt-2.5.8/./configure & make & make install#安装libltdl,也在libmcrypt源码目录中,非新软件cd libltdl/./configure -enable-ltdl-installmakemake installcd ././tar zxvf mhash-.tar.gzcd mhash-/./configure & make & make installcd ./建立软链接文件ln -s /usr/local/lib/libmcrypt.la /usr/lib/libmcrypt.laln -s /usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.soln -s /usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib/libmcrypt.so.4.4.8ln -s /usr/local/lib/libmhash.a /usr/lib/libmhash.aln -s /usr/local/lib/libmhash.la /usr/lib/libmhash.laln -s /usr/local/lib/libmhash.so /usr/lib/libmhash.soln -s /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib/libmhash.so.2.0.1ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-configtar zxvf mcrypt-2.6.8.tar.gzcd mcrypt-2.6.8/./configure & make & make installcd ./若提示configure:error: * libmcrypt was not found的问题configure: error: * libmcrypt was not found为了的到mcrypt.so库文件,先后安装编译了mhash和libmcrypt,但是到最后编译mcrypt时报错:configure: error: * libmcrypt was not found 最后发现是因为环境变量的问题,gcc编译的时候根据自身定义的变量寻找相关函数库等文件,libmcrypt也是刚安装的,在变量中没有定义出来,所以手动添加:rootlocalhost modules# export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH再次编译即可4. 编译安装MySQL 5.5.3-m3(时间会比较长)groupadd mysqluseradd -g mysql mysqltar zxvf mysql-5.5.3-m3.tar.gzcd mysql-5.5.3-m3./configure -prefix=/usr/local/mysql -without-debug -enable-thread-safe-client -with-pthread -enable-assembler -enable-profiling -with-mysqld-ldflags=-all-static -with-client-ldflags=-all-static -with-extra-charsets=all -with-plugins=all -with-mysqld-user=mysql -without-embedded-server -with-server-suffix=-community -with-unix-socket-path=/tmp/mysql.sockmake #编译make install#安装cp -f /usr/local/mysql/share/mysql/f /etc/f#准备mysql配置文件vi /etc/fclientdefault-character-set=utf8#修改客户端和连接字符集mysqldcharacter-set-server=utf8#修改服务器和数据库字符集collation-server = utf8_general_ci#修改服务器校验字符集登陆mysql后可以s查看字符集setfacl -m u:mysql:rwx -R /usr/local/mysqlsetfacl -m d:u:mysql:rwx -R /usr/local/mysql#设置权限/usr/local/mysql/bin/mysql_install_db -user=mysql#安装mysql和test数据库/usr/local/mysql/bin/mysqld_safe -user=mysql &#启动mysql服务/usr/local/mysql/bin/mysqladmin -uroot password 123456#修改mysql登录密码为123456/usr/local/mysql/bin/mysql -uroot -p123456 #用mysql登录,登录成功则说明mysql安装成功5. 编译安装PHP(FastCGI模式。使用fastCGI管理php,加快php解析速度)tar zxvf php-5.2.14.tar.gzgzip -cd php-5.2.14-fpm-0.5.14.diff.gz | patch -d php-5.2.14 -p1#解压并打补丁,让php支持fpm来方便管理php-cgi进程(使用php-fpm管理fastCGI)# gzip -c 保留源文件 -d 解压cd php-5.2.14/./configure -prefix=/usr/local/php -with-config-file-path=/usr/local/php/etc -with-mysql=/usr/local/mysql -with-mysqli=/usr/local/mysql/bin/mysql_config -with-iconv-dir=/usr/local/libiconv -with-freetype-dir -with-jpeg-dir -with-png-dir -with-zlib -with-libxml-dir=/usr -enable-xml -disable-rpath -enable-discard-path -enable-safe-mode -enable-bcmath -enable-shmop -enable-sysvsem -enable-inline-optimization -with-curl -with-curlwrappers -enable-mbregex -enable-fastcgi -enable-fpm -enable-force-cgi-redirect -enable-mbstring -with-mcrypt -with-gd -enable-gd-native-ttf -with-openssl -with-mhash -enable-pcntl -enable-sockets -with-ldap -with-ldap-sasl -with-xmlrpc -enable-zip -enable-soapmake ZEND_EXTRA_LIBS=-liconv#编译过程设定变量(编译过程需要)make installcp php.ini-dist /usr/local/php/etc/php.inicd ./6.准备编译安装PHP5扩展模块tar zxvf memcache-2.2.5.tgzcd memcache-2.2.5/usr/local/php/bin/phpize./configure -with-php-config=/usr/local/php/bin/php-config & make & make installcd ./tar jxvf eaccelerator-.tar.bz2cd eaccelerator-/usr/local/php/bin/phpize./configure -enable-eaccelerator=shared -with-php-config=/usr/local/php/bin/php-configmakemake installcd ./tar zxvf PDO_MYSQL-1.0.2.tgzcd PDO_MYSQL-1.0.2/usr/local/php/bin/phpize./configure -with-php-config=/usr/local/php/bin/php-config -with-pdo-mysql=/usr/local/mysqlmakemake installcd ./tar zxvf ImageMagick.tar.gzcd ImageMagick-6.5.1-2/./configure & make & make installcd ./tar zxvf imagick-2.3.0.tgzcd imagick-2.3.0/usr/local/php/bin/phpize./configure -with-php-config=/usr/local/php/bin/php-config & make & make installcd ./7. 安装apache(同时让php生效,设置完成后,apache就能解析php了)cd httpd-2.2.9./configure -prefix=/usr/local/apache2/ -sysconfdir=/usr/local/apache2/etc/ -with-included-apr -enable-so -enable-deflate=shared -enable-expires=shared -enable-rewrite=sharedmakemake installcd ./libphp5.so文件是apache解析php模块cp /lnmp/libphp5.so /usr/local/apache2/modules/libphp5.so创建软链接ln -sf /usr/local/lib/libiconv.so.2 /usr/lib/libiconv.so.2让php生效,编辑httpd.conf,加入一下两句话(任意位置)vi /usr/local/apache2/etc/httpd.conf AddType application/x-httpd-php .php .phtml .phps (注意T的大小写) LoadModule php5_module modules/libphp5.so* .phtml为将.phps做为PHP源文件进行语法高亮显示 重启Apache服务:/usr/local/apache2/bin/apachectl restart* Apache无法启动,提示cannot restore segment prot after reloc: Permission denied错误,为SELinux问题,可关闭SELinux或者执行命令chcon -t texrel_shlib_t /usr/local/apache2/modules/libphp5.so 测试:vi /usr/local/apache2/htdocs/test.php 通过浏览器输入地址访问:http:/Apache服务器地址/test.php * 有时第一次浏览器测试会失败,关闭浏览器重启再尝试即可,非编译错误8. 修改php.ini文件,让php模块生效cp /lnmp/php-5.2.14/php.ini-dist /usr/local/php/etc/php.inivi /usr/local/php/etc/php.iniextension_dir = /usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/手工添加extension = memcache.soextension = pdo_mysql.soextension = imagick.so再查找output_buffering = Off修改为output_buffering = On再查找 ; cgi.fix_pathinfo=0修改为cgi.fix_pathinfo=0,防止Nginx文件类型错误解析漏洞8. 在php.ini中配置eAccelerator加速PHPmkdir -p /usr/local/eaccelerator_cache#准备eaccelerator缓存目录vi /usr/local/php/etc/php.inieacceleratorzend_extension=/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/eaccelerator.soeaccelerator.shm_size=64eaccelerator.cache_dir=/usr/local/eaccelerator_cacheeaccelerator.enable=1eaccelerator.optimizer=1eaccelerator.check_mtime=1eaccelerator.debug=0eaccelerator.filter=eaccelerator.shm_max=0eaccelerator.shm_ttl=3600eaccelerator.shm_prune_period=3600eaccelerator.shm_only=0press=1press_level=99.准备php-cgi和nginx进程执行者用户(用户nginx可以不设置密码)useradd nginx10. 创建php-fpm配置文件- php-fpm.confvi /usr/local/php/etc/php-fpm.conf将以下内容复制到此文件(全部覆盖) All relative paths in this config are relative to phps install prefix Pid file /usr/local/php/logs/php-fpm.pid Error log file /usr/local/php/logs/php-fpm.log Log level notice When this amount of php processes exited with SIGSEGV or SIGBUS . 10 . in a less than this interval of time, a graceful restart will be initiated. Useful to work around accidental curruptions in accelerators shared memory. 1m Time limit on waiting childs reaction on signals from master 5s Set to no to debug fpm yes Name of pool. Used in logs and stats. default Address to accept fastcgi requests on. Valid syntax is ip.ad.re.ss:port or just port or /path/to/unix/socket :9000 Set listen(2) backlog -1 Set permissions for unix socket, if one used. In Linux read/write permissions must be set in order to allow connections from web server. Many BSD-derrived systems allow connections regardless of permissions. 0666 Additional php.ini defines, specific to this pool of workers. /usr/sbin/sendmail -t -i 0 Unix user of processes nginx Unix group of processes nginx Process manager settings Sets style of controling worker process count. Valid values are static and apache-like static Sets the limit on the number of simultaneous requests that will be served. Equivalent to Apache MaxClients directive. Equivalent to PHP_FCGI_CHILDREN environment in original php.fcgi Used with any pm_style. 128 Settings group for apache-like pm style Sets the number of server processes created on startup. Used only when apache-like pm_style is selected 20 Sets the desired minimum number of idle server processes. Used only when apache-like pm_style is selected 5 Sets the desired maximum number of idle server processes. Used only when apache-like pm_style is selected 35 The timeout (in seconds) for serving a single request after which the worker process will be terminated Should be used when max_execution_time ini option does not stop script execution for some reason 0s means off 0s The timeout (in seconds) for serving of single request after which a php backtrace will be dumped to slow.log file 0s means off 0s The log file for slow requests logs/slow.log Set open file desc rlimit 65535 Set max core size rlimit 0 Chroot to this directory at the start, absolute path Chdir to this directory at the start, absolute path Redirect workers stdout and stderr into main error log. If not set, they will be redirected to /dev/null, according to FastCGI specs yes How much requests each process should execute before respawn. Useful to work around memory leaks in 3rd party libraries. For endless request processing please specify 0 Equivalent to PHP_FCGI_MAX_REQUESTS 1024 Comma separated list of ipv4 addresses of FastCGI clients that allowed to connect. Equivalent to FCGI_WEB_SERVER_ADDRS environment in original php.fcgi (5.2.2+) Makes sense only with AF_INET listening socket. Pass environment variables like LD_LIBRARY_PATH All $VARIABLEs are taken from current environment $HOSTNAME /usr/local/bin:/usr/bin:/bin /tmp /tmp /tmp $OSTYPE $MACHTYPE 2 11. 启动php-cgi(fastcgi)进程,监听的9000端口,进程数为128(如果服务器内存小于3GB,可以只开启64个进程),用户为nginx:/usr/local/php/sbin/php-fpm start#启动php-cgi,若显示Starting php_fpm done,表示启动成功!/usr/local/php/sbin/php-fpm reload#重新加载配置文件/usr/local/php/sbin/php-fpm stop#关闭php-fpm,此时nginx肯定连不上php12. 安装Nginx所需的pcre库tar zxvf pcre-8.10.tar.gzcd pcre-8.10/./configure & make & make installcd ./13. 安装Nginxtar zxvf nginx-0.8.46.tar.gzcd nginx-0.8.46/./configure -user=nginx -group=nginx -prefix=/usr/local/nginx -with-http_stub_status_module -with-http_ssl_modulemake & make installcd ./14. 修改Nginx配置文件vi /usr/local/nginx/conf/nginx.conf将以下内容复制到此文件(全部覆盖)user nginx nginx;worker_processes 2;#相当于cpu个数error_log logs/nginx_error.log ;#错误日志 crit 日志格式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; #charset gb2312; server_names_hash_bucket_size 128; client_header_buffer_size 32k; large_client_header_buffers 4 32k; client_max_body_size 8m; sendfile on; tcp_nopush on;#tcp延迟 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设置 gzip on;#开启gzip压缩,大大加速网页传输速度,节省了带宽,以下都是gzip的设置 gzip_proxied any; gzip_min_length 1k; gzip_buffers 4 16k; gzip_comp_level 2; gzip_types text/html te

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论