1、#安装编码格式转换库
wget http://www.eduicc.com/soft/libiconv-1.13.tar.gz
tar -zxvf libiconv-1.13.tar.gz
cd libiconv-1.13
./configure --prefix=/usr/local
make && make install
cd ..
#安装libmcrypt库
wgethttp://lnamp-web-server.googlecode.com/files/libmcrypt-2.5.8.tar.gz
tar –xvzf 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
#安装php-mhash扩展库
wget http://www.eduicc.com/soft/mhash-0.9.9.9.tar.gz
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
wget http://www.eduicc.com/soft/mcrypt-2.6.8.tar.gz
tar -zxvf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8
/sbin/ldconfig
./configure
make
make install
cd ..
2、安装mysql
wgethttp://downloads.mysql.com/archives/mysql-5.1/mysql-5.1.54.tar.gz
tar -zxvf mysql-5.1.54.tar.gz
cd mysql-5.1.54
./configure --prefix=/usr/local/mysql --enable-assembler --with-charset=utf8 --enable-thread-safe-client --with-extra-charsets=all --with-big-tables --with-readline --with-ssl --with-embedded-server --enable-local-infile
make && make install
cd ..
编译源码提示 No curses/termcap library found,但安装curses termcap都提示已经安装。
yum install ncurses-devel
#添加mysql用户和用户组
groupadd mysql
useradd -g mysql mysql
cp /usr/local/mysql/share/mysql/my-medium.cnf /etc/my.cnf
/usr/local/mysql/bin/mysql_install_db --user=mysql
chown -R mysql /usr/local/mysql
chgrp -R mysql /usr/local/mysql/.
#设置mysql开机自启动
cp /usr/local/mysql/share/mysql/mysql.server /etc/init.d/mysql
chmod 755 /etc/init.d/mysql
chkconfig --level 345 mysql on
#增加mysql动态链接库文件
echo "/usr/local/mysql/lib/mysql" >> /etc/ld.so.conf
echo "/usr/local/lib" >>/etc/ld.so.conf
ldconfig
ln -s /usr/local/mysql/lib/mysql /usr/lib/mysql
ln -s /usr/local/mysql/include/mysql /usr/include/mysql
service mysql restart
#添加root密码
/etc/init.d/mysql start
/usr/local/mysql/bin/mysqladmin -u root password root
/etc/init.d/mysql restart
/etc/init.d/mysql stop
登陆mysql
/usr/local/mysql/bin/mysql -u root -p
#去掉mysql集群服务
chkconfig mysql-ndb off
chkconfig mysql-ndb-mgm off
3、Php安装
wgethttp://wcoserver.googlecode.com/files/php-5.2.17-fpm-0.5.14.diff.gz
wgethttp://cn.php.net/distributions/php-5.2.17.tar.gz
tar -zxvf php-5.2.17.tar.gz
gzip -cd php-5.2.17-fpm-0.5.14.diff.gz | patch -d php-5.2.17 -p1
cd php-5.2.17
./buildconf –force
./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--with-curl --with-curlwrappers --enable-inline-optimization --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-xmlrpc --enable-zip --enable-ftp --without-pear
make ZEND_EXTRA_LIBS='-liconv'
make install
cp php.ini-dist /usr/local/php/etc/
checking for cURL in default path... not found
configure: error: Please reinstall the libcurl distribution -
easy.h should be in /include/curl/
其实就是curl的dev包没有安装, 解决方案:
终端下
# yum -y install curl-devel
configure: error: libpng.(a|so) not found
解决之道差不多, 同样通过安装libpng-devel解决.
yum install libpng-devel
4、安装PHP扩展模块
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 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 jxvf eaccelerator-0.9.6.tar.bz2
cd eaccelerator-0.9.6/
/usr/local/php/bin/phpize
./configure --enable-eaccelerator=shared --with-php-config=/usr/local/php/bin/php-config
make
make install
cd ../
5、php-fpm.conf配置
/usr/local/php/etc/php-fpm.conf
<configuration>
All relative paths in this config are relative to php's install prefix
<section name="global_options">
Pid file
<value name="pid_file">/usr/local/php/logs/php-fpm.pid</value>
Error log file
<value name="error_log">/usr/local/php/logs/php-fpm.log</value>
Log level
<value name="log_level">notice</value>
When this amount of php processes exited with SIGSEGV or SIGBUS ...
<value name="emergency_restart_threshold">10</value>
... 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.
<value name="emergency_restart_interval">1m</value>
Time limit on waiting child's reaction on signals from master
<value name="process_control_timeout">5s</value>
Set to 'no' to debug fpm
<value name="daemonize">yes</value>
</section>
<workers>
<section name="pool">
Name of pool. Used in logs and stats.
<value name="name">default</value>
Address to accept fastcgi requests on.
Valid syntax is 'ip.ad.re.ss:port' or just 'port' or '/path/to/unix/socket'
<value name="listen_address">127.0.0.1:9000</value>
<value name="listen_options">
Set listen(2) backlog
<value name="backlog">-1</value>
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.
<value name="owner"></value>
<value name="group"></value>
<value name="mode">0666</value>
</value>
Additional php.ini defines, specific to this pool of workers.
<value name="php_defines">
<value name="sendmail_path">/usr/sbin/sendmail -t -i</value>
<value name="display_errors">1</value>
</value>
Unix user of processes
<value name="user">www</value>
Unix group of processes
<value name="group">www</value>
Process manager settings
<value name="pm">
Sets style of controling worker process count.
Valid values are 'static' and 'apache-like'
<value name="style">static</value>
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.
<value name="max_children">128</value>php-cgi进程数
Settings group for 'apache-like' pm style
<value name="apache_like">
Sets the number of server processes created on startup.
Used only when 'apache-like' pm_style is selected
<value name="StartServers">20</value>
Sets the desired minimum number of idle server processes.
Used only when 'apache-like' pm_style is selected
<value name="MinSpareServers">5</value>
Sets the desired maximum number of idle server processes.
Used only when 'apache-like' pm_style is selected
<value name="MaxSpareServers">35</value>
</value>
</value>
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'
<value name="request_terminate_timeout">0s</value>
The timeout (in seconds) for serving of single request after which a php backtrace will be dumped to slow.log file
'0s' means 'off'
<value name="request_slowlog_timeout">0s</value>
The log file for slow requests
<value name="slowlog">logs/slow.log</value>
Set open file desc rlimit
<value name="rlimit_files">51200</value>
Set max core size rlimit
<value name="rlimit_core">0</value>
Chroot to this directory at the start, absolute path
<value name="chroot"></value>
Chdir to this directory at the start, absolute path
<value name="chdir"></value>
Redirect workers' stdout and stderr into main error log.
If not set, they will be redirected to /dev/null, according to FastCGI specs
<value name="catch_workers_output">yes</value>
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
<value name="max_requests">10240</value>
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.
<value name="allowed_clients">127.0.0.1</value>
Pass environment variables like LD_LIBRARY_PATH
All $VARIABLEs are taken from current environment
<value name="environment">
<value name="HOSTNAME">$HOSTNAME</value>
<value name="PATH">/usr/local/bin:/usr/bin:/bin</value>
<value name="TMP">/tmp</value>
<value name="TMPDIR">/tmp</value>
<value name="TEMP">/tmp</value>
<value name="OSTYPE">$OSTYPE</value>
<value name="MACHTYPE">$MACHTYPE</value>
<value name="MALLOC_CHECK_">2</value>
</value>
</section>
</workers>
</configuration>
开机启动启动php-fpm/usr/local/php/sbin/php-fpm start设置开机启动
echo "/usr/local/php/sbin/php-fpm start" >> /etc/rc.local
6、Nginx.conf配置
=====本机测试完整配置===================================================
#user nobody;
worker_processes 8;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
pid logs/nginx.pid;
events {
worker_connections 204800;
}
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;
client_header_timeout 3m;
client_body_timeout 3m;
send_timeout 3m;
client_header_buffer_size 1k;
large_client_header_buffers 4 4k;
gzip on;
gzip_min_length 1100;
gzip_buffers 4 8k;
gzip_types text/plain;
output_buffers 1 32k;
postpone_output 1460;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
#send_lowat 12000;
keepalive_timeout 75 20;
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;
server {
listen 80;
server_name localhost;
root /usr/local/nginx/html;
index index.html index.htm index.php;
#charset koi8-r;
#access_log logs/host.access.log main;
#location / {
#root /usr/local/nginx/html;
#index index.html index.htm index.php;
#}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
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.conf;
}
location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|html)$ {
access_log off;
expires 30d;
root /usr/local/nginx/html;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
# another virtual host using mix of IP-, name-, and port-based configuration
#
server {
listen 80;
#listen somename:8080;
server_name 10.0.0.116;
root /usr/local/nginx/html/wordpress;
index index.html index.htm index.php;
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.conf;
}
}
}
测试
cd /usr/local/nginx/html
vi index.php
<?php phpinfo(); ?>
保存
chmod 755 index.php
http://127.0.0.1/index.php出现php测试页面
7、phpMyAdmin 配置
phpMyAdmin 解压后放到/usr/local/nginx/html 下
vi config.sample.inc.php
$cfg['blowfish_secret'] = 'root'; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */
// $cfg['Servers'][$i]['controluser'] = 'root';
// $cfg['Servers'][$i]['controlpass'] = 'root';
测试: http://localhost/MyAdminphp
8、加速php
Vi /etc/php.ini 最后加入
zend_extension="/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/eaccelerator.so"
eaccelerator.shm_size="64"
eaccelerator.cache_dir="/tmp/eaccelerator"
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"
eaccelerator.shm_size
指定 eAccelerator 能够使用的共享内存数量,单位:MB。
"0" 代表操作系统默认。默认值为 "0"。
eaccelerator.cache_dir
用户磁盘缓存的目录。eAccelerator 在该目录中存储预编译代码、session 数据、内容等。
相同的数据也可以存储于共享内存中(以获得更快的存取速度)。默认值为 "/tmp/eaccelerator"。
eaccelerator.enable
开启或关闭 eAccelerator。"1" 为开启,"0" 为关闭。默认值为 "1"。
eaccelerator.optimizer
开启或关闭内部优化器,可以提升代码执行速度。"1" 为开启,"0" 为关闭。默认值为 "1"。
eaccelerator.debug
开启或关闭调试日志记录。"1" 为开启,"0" 为关闭。默认值为 "0"。
eaccelerator.check_mtime
开启或关闭 PHP 文件改动检查。"1" 为开启,"0" 为关闭。如果您想要在修改后重新编译 PHP
程序则需要设置为 "1"。默认值为 "1"。
eaccelerator.filter
判断哪些 PHP 文件必须缓存。您可以指定缓存和不缓存的文件类型(如 "*.php *.phtml"等)
如果参数以 "!" 开头,则匹配这些参数的文件被忽略缓存。默认值为 "",即,所有 PHP 文件
都将被缓存。
eaccelerator.shm_max
当使用 " eaccelerator_put() " 函数时禁止其向共享内存中存储过大的文件。该参数指定允许
存储的最大值,单位:字节 (10240, 10K, 1M)。"0" 为不限制。默认值为 "0"。
eaccelerator.shm_ttl
当 eAccelerator 获取新脚本的共享内存大小失败时,它将从共享内存中删除所有在
最后 "shm_ttl" 秒内无法存取的脚本缓存。默认值为 "0",即:不从共享内春中删除
任何缓存文件。
eaccelerator.shm_prune_period
当 eAccelerator 获取新脚本的共享内存大小失败时,他将试图从共享内存中删除早于
"shm_prune_period" 秒的缓存脚本。默认值为 "0",即:不从共享内春中删除
任何缓存文件。
eaccelerator.shm_only
允许或禁止将已编译脚本缓存在磁盘上。该选项对 session 数据和内容缓存无效。默认
值为 "0",即:使用磁盘和共享内存进行缓存。
eaccelerator.compress
允许或禁止压缩内容缓存。默认值为 "1",即:允许压缩。
eaccelerator.compress_level
指定内容缓存的压缩等级。默认值为 "9",为最高等级。
eaccelerator.name_sapce