分类: IT业界
2012-08-18 18:40:10
一、编译安装nginx-1.1.9.tar.gz
安装nginx
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;
而后重新载入nginx的配置文件:
# service nginx reload
netstat -tnlp #查看80端口此时是否有进程在用,若有下面需要关闭此占用80端口的进程
service httpd stop #若80端口此时正在使用,则关闭httpd服务,以为httpd与nginx服务同
时占用80端口会出冲突
service nginx start #开启nginx服务
5.查看nginx 配置文件,定义nginx虚拟主机:
# /etc/ngxin/nginx.conf #nginx服务配置文件位置
这里可以添加nginx里面的虚拟主机:
server {
listen 8080; #这个你可以自己定义
server_name IP:8080; #ip的话 也可以写个域名在这
root /www/myweb; #这个是你的站点存放路径
index index.php index.html;
location ~\.php$ {
root /www/myweb; #网页文件的目录
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi_params;
}
测试一下 这个目录
#mkdir -pv /www/myweb
#cd /www/myweb
# vim index.html
hello welcome to zhangzhengxing #编辑器里面写的东西
#service nginx restart
二、编译安装mysql
1.下载mysql源码包
# mysql-5.5.20-linux2.6-i686.tar.gz 编译mysql之前我们需要去mysql官网查找最新版本的mysql源码包,可以根据自己的实际需要选择对应的源码包!
2.添加mysql系统用户和组
# groupadd -r mysql #添加mysql组
# useradd -g mysql -r -s /sbin/nologin -M mysql #添加mysql用户
# id mysql 查看mysqlid信息
3.解压mysql源码包
# tar xvf mysql-5.5.20-linux2.6-i686.tar.gz -C /usr/local 解压在/usr/local中
# cd /usr/local/
#ln -sv mysql-5.5.20-linux2.6-i686 mysql创建软连接
# chown -R mysql:mysql /mydata/data #改变存储mysql数据的目录属主属组为mysql
# cd /mysql --> chown -R mysql:mysql . #将mysql属组属主改为mysql
#rpm -q mysql-server #初始化mysql之前确认系统上没有安装mysql-server 的rpm包,否则会冲突
# scripts/mysql_install_db --user=mysql --datadir=/mydata/data #用脚本初始化mysql
#chown -R root . # 将mysql 中的属主重新改为root,为了使mysql执行时添加安全保证。
4.为mysql提供主配置文件
# cd /usr/local/mysql
# cp support-files/my-large.cnf /etc/my.cnf
# 为mysql提供主配置文件:
并修改此文件中thread_concurrency的值为你的CPU个数乘以2,比如这里使用如下行:
thread_concurrency = 2
另外还需要添加如下行指定mysql数据文件的存放位置:
datadir = /mydata/data
5.为mysql提供sysv服务脚本
# cd /usr/local/mysql
# cp support-files/mysql.server /etc/rc.d/init.d/mysqld
# 为mysql提供sysv服务脚本:
添加至服务列表:
# chkconfig --add mysqld
# chkconfig --level 2345 mysqld on #添加了这个这几个运行级别都可以启动
而后就可以启动服务测试使用了。
# ls /mydata/data 里面有mysql的日志文件
6.优化mysql服务
#为了使用mysql的安装符合系统使用规范,并将其开发组件导出给系统使用,这里还需要进行如下步骤:
# ln -sv /usr/local/mysql/include /usr/include/mysql
#为mysql创建头文件链接
# vim /etc/ld.so.conf.d/mysql.conf
/usr/local/mysql/lib
# ldconfig -v 重新加载一下 ,-v显示过程
7.为mysql提供帮助文件
编辑/etc/man.config,添加如下行即可:
MANPATH /usr/local/mysql/man #找到MANPATH 就可以添加了
8.修改mysql环境变量
修改PATH环境变量,让系统可以直接使用mysql的相关命令。具体实现过程这里不再给出。
# vim /etc/profile 添加下面一句:
export PATH=$PATH:/usr/local/apache/bin:/usr/local/mysql/bin
# source /etc/profile 重读配置文件
#service mysqld start
三、编译安装php
1、解决依赖关系:
请配置好yum源(可以是本地系统光盘)后执行如下命令:
# yum -y groupinstall "X Software Development"
# yum -y groupinstall "Development Tools" #安装好开发组包工具
# yum -y groupinstall "Development Libraries"# 安装编译时依赖的库文件
如果想让编译的php支持mcrypt、mcrypt、mhash扩展和libevent,此处还需要下载如下几个rpm包并安装:
mcrypt-2.6.8-1.el5.i386.rpm
libmcrypt-2.5.7-5.el5.i386.rpm
libmcrypt-devel-2.5.7-5.el5.i386.rpm
mhash-0.9.2-6.el5.i386.rpm
mhash-devel-0.9.2-6.el5.i386.rpm
libevent-2.0.17-2.i386.rpm
libevent-devel-2.0.17-2.i386.rpm
最好使用升级的方式安装上面的rpm包,命令格式如下:
# rpm -Uvh *.rpm --nodeps #--nodeps 忽略依赖关系并升级安装
#rpm -Uvh mcrypt-2.6.8-1.el5.i386.rpm libmcrypt-2.5.7-5.el5.i386.rpm libmcrypt-devel-2.5.7-5.el5.i386.rpm mhash-0.9.2-6.el5.i386.rpm mhash-devel-0.9.2-6.el5.i386.rpm event-2.0.17-2.i386.rpm libevent-devel-2.0.17-2.i386.rpm --nodeps
也可以这样来安装
wget
wget
wget
wget
wget
wget
wget
wget
wget
wget ftp://ftp.imagemagick.org/pub/ImageMagick/ImageMagick.tar.gz
wget
编译安装php所需的支持库
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tar zxvf libiconv-1.13.1.tar.gz
cd libiconv-1.13.1/
./configure --prefix=/usr/local
make
make install
cd ../
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tar zxvf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8/
./configure
make
make install
/sbin/ldconfig
cd libltdl/
./configure --enable-ltdl-install
make
make install
cd ../../
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tar zxvf mhash-0.9.9.9.tar.gz
cd mhash-0.9.9.9/
./configure
make
make install
cd ../
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ln -s /usr/local/lib/libmcrypt.la /usr/lib/libmcrypt.la
ln -s /usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.so
ln -s /usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4
ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib/libmcrypt.so.4.4.8
ln -s /usr/local/lib/libmhash.a /usr/lib/libmhash.a
ln -s /usr/local/lib/libmhash.la /usr/lib/libmhash.la
ln -s /usr/local/lib/libmhash.so /usr/lib/libmhash.so
ln -s /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2
ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib/libmhash.so.2.0.1
ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tar zxvf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8/
/sbin/ldconfig
./configure
make
make install
cd ../
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
编译安装PHP(FastCGI模式)
cd php目录
./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
--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-soap
make ZEND_EXTRA_LIBS='-liconv'
make install
cp php.ini-dist /usr/local/php/etc/php.ini 或者cp php.ini-production /usr/local/php/etc/php.ini
cd ../
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
编译安装PHP5扩展模块
》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》
tar zxvf memcache-2.2.5.tgz
cd memcache-2.2.5/
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make
make install
cd ../
》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》
tar jxvf eaccelerator-0.9.6.1.tar.bz2
cd eaccelerator-0.9.6.1/
/usr/local/php/bin/phpize
./configure --enable-eaccelerator=shared \
--with-php-config=/usr/local/php/bin/php-config
make
make install
cd ../
》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》
tar zxvf PDO_MYSQL-1.0.2.tgz
cd 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/mysql
make
make install
cd ../
》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》
tar zxvf ImageMagick.tar.gz
cd ImageMagick-6.5.1-2/
./configure
make
make install
cd ../
》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》
tar zxvf imagick-2.3.0.tgz
cd imagick-2.3.0/
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make
make install
cd ../
》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》
修改php.ini文件
手工修改:
查找/usr/local/php/etc/php.ini中的extension_dir = "./"
修改为
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 修改为 On
再查找 ;cgi.fix_pathinfo=0 去掉“;”号,防止Nginx文件类型错误解析漏洞。
》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》
配置eAccelerator加速PHP:
mkdir -p /usr/local/eaccelerator_cache
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"
》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》
创建php-fpm配置文件(php-fpm是为PHP打的一个FastCGI管理补丁,可以平滑变更php.ini配置而无需重启php-cgi):
在/usr/local/php/etc/目录中创建php-fpm.conf文件:
rm -f /usr/local/php/etc/php-fpm.conf
vim /usr/local/php/etc/php-fpm.conf
................................................................
输入以下内容
Error log file
Log level
When this amount of php processes exited with SIGSEGV or SIGBUS ...
... in a less than this interval of time, a graceful restart will be initiated.
Useful to work around accidental curruptions in accelerator's shared memory.
Time limit on waiting child's reaction on signals from master
Set to 'no' to debug fpm
Address to accept fastcgi requests on.
Valid syntax is 'ip.ad.re.ss:port' or just 'port' or '/path/to/unix/socket'
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.
Additional php.ini defines, specific to this pool of workers.
Unix user of processes
Unix group of processes
Process manager settings
Valid values are 'static' and 'apache-like'
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.
Settings group for 'apache-like' pm style
Used only when 'apache-like' pm_style is selected
Sets the desired minimum number of idle server processes.
Used only when 'apache-like' pm_style is selected
Sets the desired maximum number of idle server processes.
Used only when 'apache-like' pm_style is selected
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'
The timeout (in seconds) for serving of single request after which a php backtrace will be dumped to slow.log file
'0s' means 'off'
The log file for slow requests
Set open file desc rlimit
Set max core size rlimit
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
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
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
................................................................
》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》
启动php-cgi进程,监听127.0.0.1的9000端口,进程数为128(如果服务器内存小于3GB,可以只开启64个进程),用户为www:
ulimit -SHn 65535
/usr/local/php/sbin/php-fpm start
注意:如果要重启,可以使用 reload 命令
》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》
2、下载编译php源码包
首先下载php-5.3.6 源码包至本地目录,可根据需要下载对应的源码包。
# tar xf php-5.3.6.tar.bz2
# ./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/php --with-config-file-scan-dir=/etc/php --with-bz2 --with-curl
说明:如果前面第1步解决依赖关系时安装mcrypt相关的两个rpm包,此./configure命令还可以带上—with-mcrypt选项以让php支持mycrpt扩展
# make && make install #编译之后可以执行make, 这里肯能会花费一会时间,根据你的cpu性能决定你编译的时间长短,请稍等!
3.为php提供配置文件:
# cp php.ini-production /etc/php/php.ini #复制生成的配置文件并且自己重命名为php.ini
4.为php-fpm提供sysv 脚本
为php-fpm提供Sysv init脚本,并将其添加至服务列表:
# cp sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm
# chmod +x /etc/rc.d/init.d/php-fpm #添加执行权限
# chkconfig --add php-fpm #将php-fpm添加至服务中
# chkconfig --level 2345 php-fpm on
5.启动fastcgi:
为php-fpm提供配置文件:
# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
6.编辑php-fpm的配置文件:
# vim /usr/local/php/etc/php-fpm.conf
配置pm.的相关选项为你所需要的值,并启用pid文件(如下最后一行):
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 2 #定义最少空闲的server个数
pm.max_spare_servers = 8 #定义最多空闲的server 个数
pid = /var/run/php-fpm.pid #此行尤为重要服务需要的pid 文件
7.启动php-fpm:
# service php-fpm start
使用如下命令来验正(如果此命令输出有中几个php-fpm进程就说明启动成功了):
# ps aux | grep php-fpm
vim /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;
在/usr/html新建info.php的测试页面,测试php是否能正常工作:
# cat > /usr/html/index.php << EOF
phpinfo();
?>
接着就可以通过浏览器访问此测试页面了
安装xcache,为php加速
1、下载源码包并编译安装
# tar xf xcache-1.3.2.tar.gz
# cd xcache-1.3.2
# /usr/local/php/bin/phpize
# ./configure --enable-xcache --with-php-config=/usr/local/php/bin/php-config
# make
# make install
安装结束时,会出现类似如下行:
Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/
2、编辑php.ini,整合php和xcache:
首先将xcache提供的样例配置导入php.ini
# cat xcache.ini >> /usr/local/php/lib/php.ini
说明:xcache.ini文件在xcache的源码目录中。
接下来编辑/usr/local/php/lib/php.ini,找到zend_extension开头的行,修改为如下行:
zend_extension = /usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/xcache.so
注意:如果php.ini文件中有多条zend_extension指令行,要确保此新增的行排在第一位。
3、重新启动php-fpm
# service php-fpm restart
可以帮助到你那是最好的(LNMP完成)