环境:Centos6.5 64位
编译nginx-1.6.2.tar.gz前面已经做过来参考http://my.oschina.net/kcw/blog/318309
这里就编译mysql和php
mysql编译太慢,我这块是官方网站的二进制格式 去mysql官网下载
mysql-5.6.19-linux-glibc2.5-x86_64.tar.gz
安装mysql
[root@tomcat2 ~]# mkdir /mydata/data -pv 建立数据目录 ,最好在lvm卷上 mkdir: 已创建目录 "/mydata" mkdir: 已创建目录 "/mydata/data" [root@tomcat2 ~]# groupadd -r mysql [root@tomcat2 ~]# useradd -r -g mysql -s /sbin/nologin -M -d /mydata/data/ mysql [root@tomcat2 ~]# tar xf mysql-5.6.19-linux-glibc2.5-x86_64.tar.gz [root@tomcat2 ~]# chown -R mysql:mysql /mydata/data/ [root@tomcat2 ~]# mv mysql-5.6.19-linux-glibc2.5-x86_64 /usr/local/ [root@tomcat2 ~]# cd /usr/local/ [root@tomcat2 local]# ln -sv mysql-5.6.19-linux-glibc2.5-x86_64 mysql "mysql" -> "mysql-5.6.19-linux-glibc2.5-x86_64" [root@tomcat2 local]# cd mysql [root@tomcat2 mysql]# chown -R mysql:mysql ./* [root@tomcat2 mysql]# scripts/mysql_install_db --user=mysql --datadir=/mydata/data/ [root@tomcat2 mysql]# cp my.cnf /etc/my.cnf cp:是否覆盖"/etc/my.cnf"? y root@tomcat2 mysql]# vim /etc/my.cnf datadir=/mydata/data innodb_file_per_table=ON log-bin=mysql-bin socket=/tmp/mysql.sock [root@tomcat2 mysql]# cp support-files/mysql.server /etc/init.d/mysqld [root@tomcat2 mysql]# chmod +x /etc/init.d/mysqld [root@tomcat2 mysql]# chkconfig --add mysqld [root@tomcat2 mysql]# /etc/init.d/mysqld start Starting MySQL..... [确定] [root@tomcat2 mysql]# netstat -antlp |grep mysqld tcp 0 0 :::3306 :::* LISTEN 2079/mysqld
输出mysql库文件和头文件和二进制命令
[root@tomcat2 mysql]# vim /etc/ld.so.conf.d/mysql.conf /usr/local/mysql/lib [root@tomcat2 mysql]# ldconfig -v [root@tomcat2 mysql]# ln -sv /usr/local/mysql/include/ /usr/include/mysql "/usr/include/mysql" -> "/usr/local/mysql/include/" root@tomcat2 mysql]# vim /etc/profile.d/mysql.sh export PATH=$PATH:/usr/local/mysql/bin [root@tomcat2 mysql]# . /etc/profile.d/mysql.sh
测试
[root@tomcat2 mysql]# mysql Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1 Server version: 5.6.19-log MySQL Community Server (GPL) Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | test | +--------------------+ 4 rows in set (0.09 sec)
安装php 下载地址 http://cn2.php.net/get/php-5.6.0.tar.bz2/from/a/mirror
如果想让编译的php支持mcrypt、mhash扩展和libevent 安装一下几个包 libmcrypt libmcrypt-devel mhash mhash-devel mcrypt
这里自带光盘没带使用aliyun yum
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
[root@tomcat2 yum.repos.d]# yum install libmcrypt libmcrypt-devel mhash mhash-devel mcrypt
[root@tomcat2 php-5.6.0]# ./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-openssl --enable-fpm --enable-sockets --enable-sysvshm --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib-dir --with-libxml-dir=/usr --enable-xml --with-mhash --with-mcrypt --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2 --with-curl 报错 configure: error: xml2-config not found. Please check your libxml2 installation. 安装 [root@tomcat2 php-5.6.0]# yum install libxml2-devel 又报错 configure: error: Please reinstall the BZip2 distribution 安装 [root@tomcat2 php-5.6.0]# yum install bzip2-devel 又错 onfigure: error: Please reinstall the libcurl distribution - easy.h should be in <curl-dir>/include/curl/ [root@tomcat2 php-5.6.0]# yum install libcurl-devel ok! make && make install
提供php配置文件和php-fpm配置文件
[root@tomcat2 php-5.6.0]# cp php.ini-production /etc/php.ini [root@tomcat2 etc]# cp php-fpm.conf.default php-fpm.conf [root@tomcat2 etc]# ls pear.conf php-fpm.conf php-fpm.conf.default [root@tomcat2 etc]# pwd vim /usr/local/php/etc/php-fpm.conf 配置fpm的相关选项为你所需要的值,并启用pid文件(如下最后一行): pm.max_children = 150 pm.start_servers = 8 pm.min_spare_servers = 5 pm.max_spare_servers = 10 pid = /usr/local/php/var/run/php-fpm.pid
为php-fpm提供Sysv init脚本,并将其添加至服务列表
[root@tomcat2 php-5.6.0]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm [root@tomcat2 php-5.6.0]# chmod +x /etc/init.d/php-fpm [root@tomcat2 php-5.6.0]# chkconfig --add php-fpm [root@tomcat2 php-5.6.0]# chkconfig php-fpm on [root@tomcat2 php-5.6.0]# /etc/init.d/php-fpm start Starting php-fpm done [root@tomcat2 php-5.6.0]# netstat -antlp |grep php-fpm tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 53659/php-fpm ps -aux
整合nginx和php
在nginx开启如下选项
location ~ \.php$ { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; include fastcgi_params; }
编辑/etc/nginx/fastcgi_params,将其内容更改为如下内容: fastcgi_param GATEWAY_INTERFACE CGI/1.1; fastcgi_param SERVER_SOFTWARE nginx; fastcgi_param QUERY_STRING $query_string; fastcgi_param REQUEST_METHOD $request_method; fastcgi_param CONTENT_TYPE $content_type; fastcgi_param CONTENT_LENGTH $content_length; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param SCRIPT_NAME $fastcgi_script_name; fastcgi_param REQUEST_URI $request_uri; fastcgi_param DOCUMENT_URI $document_uri; fastcgi_param DOCUMENT_ROOT $document_root; fastcgi_param SERVER_PROTOCOL $server_protocol; fastcgi_param REMOTE_ADDR $remote_addr; fastcgi_param REMOTE_PORT $remote_port; fastcgi_param SERVER_ADDR $server_addr; fastcgi_param SERVER_PORT $server_port; fastcgi_param SERVER_NAME $server_name;
测试并启动
[root@tomcat2 nginx]# nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful [root@tomcat2 nginx]# /etc/init.d/nginx restart nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful 停止 nginx: [失败] 正在启动 nginx: [确定] [root@tomcat2 nginx]# /etc/init.d/nginx restart nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful 停止 nginx: [确定] 正在启动 nginx: [确定]
写个测试页看看
[root@tomcat2 nginx]# cd /usr/html/ [root@tomcat2 html]# ls 50x.html index.html [root@tomcat2 html]# vim index.html [root@tomcat2 html]# vim index.php <?php phpinfo(); ?>
测试
OK
测试链接数据库是否正常
<?php $conn=mysql_connect('localhost','root','redhat'); 注意你的数据库账号密码 if($conn) echo "DB conn OK..."; else echo "DB conn Failure..."; phpinfo(); ?>
停掉数据库
OK如果想安装xcache为php加速的话去看这篇文章http://my.oschina.net/kcw/blog/300671
完