Linux+Nginx+Mysql+PHP
1. mkdir –p /data0/software2. cd /data0/software3. yum install gcc gcc-c++ autoconf automake make libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncursesncurses-devel curl curl-devel e2fsprogse 2fsprogs-devel krb5 krb5-devel libidn libidn-devel opensslopenssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers kernel-headers kernel-devel pcre pcre-devel openssl openssl-devel cmake ncurses-devel bison libtool-ltdl libtool-ltdl-devellibevent-devel unixODBC unixODBC-devel libmcrypt-devel mhash-devel libxslt-devel libidn libidn-devel pcre pcre-devel krb5-libs krb5-devel4. 为安装PHP做准备:1.安装libiconv1.4libiconv库为需要做转换的应用提供了iconv() 函数,以实现字符编码间的转换。tar zxvf libiconv-1.14.tar.gzcd libiconv-1.14/./configure --prefix=/usr/localmake && make installcd ../2.安装libmcryptlibmcrypt是加密算法扩展库,支持DES, 3DES, RIJNDAEL, Twofish, IDEA, GOST, CAST-256, ARCFOUR, SERPENT, SAFER+等算法。tar -zxvf libmcrypt-2.5.8.tar.gzcd libmcrypt-2.5.8./configuremake && make install/sbin/ldconfigcd libltdl./configure -enable-ltdl-installmake && make installcd ../../3.安装支持库mhashtar –zxvf mhash-0.9.9.9.tar.gzcd mhash-0.9.9.9./configuremake && make installcd ../4.建立链接文件: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.a ln -s /usr/local/lib/libmhash.la/usr/lib/libmhash.laln -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
5.安装mcrypt-2.6.8 tar -zxvfmcrypt-2.6.8.tar.gz
cdmcrypt-2.6.8
/sbin/ldconfig
./configure
make&& make installcd ../5. 安装MySQL:useradd mysqltar -zxvfmysql-5.1.38.tar.gzcd mysql-5.1.38./configure --prefix=/usr/local/mysql/--enable-assembler --with-extra-charsets=complex --enable-thread-safe-client--with-big-tables --with-readline --with-ssl --with-embedded-server--enable-local-infile--with-plugins=innobasemake && make installchmod +w/usr/local/mysqlchown -R mysql:mysql /usr/local/mysqlmkdir –p /data0/mysql/3306/data/chown –R mysql:mysql /data0/mysqlsu – mysql/usr/local/mysql/bin/mysql_install_db –basedir=/usr/local/mysql –datadir=/data0/mysql/3306/data–user=mysqlcd/usr/local/mysql/share/mysqlcp my-huge.cnf/data0/mysql/3306/my.cnfcd/data0/mysql/3306/cp my.cnf my.cnf.bakvim my.cnf,修改文件,内容如下:more/data0/mysql/3306/my.cnf|grep -v '^$'|grep -v '#'default-character-set= utf8port = 3306socket = /tmp/mysql.sockuser = mysqlport = 3306socket = /tmp/mysql.sockbasedir =/usr/local/mysqldatadir =/data0/mysql/3306/dataskip-lockingkey_buffer_size =384Mmax_allowed_packet =1Mtable_open_cache =512sort_buffer_size =2Mread_buffer_size =2Mread_rnd_buffer_size= 8Mmyisam_sort_buffer_size= 64Mthread_cache_size =8query_cache_size =32Mthread_concurrency =8log-bin=/data0/mysql/3306/binlogserver-id = 1quickmax_allowed_packet =16Mno-auto-rehashprompt="(\u:linxi.com:)[\d]>"key_buffer_size =256Msort_buffer_size =256Mread_buffer = 2Mwrite_buffer = 2Minteractive-timeout 编辑mysql的启动文件:
vim/data0/mysql/3306/mysql,文件内容如下:
more/data0/mysql/3306/mysql |grep -v '^$'|grep -v '#'
mysql_port=3306
mysql_username="admin"
mysql_password="12345678"
function_start_mysql()
{
printf"Starting MySQL...\n"
/bin/sh/usr/local/mysql/bin/mysqld_safe--defaults-file=/data0/mysql/${mysql_port}/my.cnf 2>&1 > /dev/null&
}
function_stop_mysql()
{
printf "Stoping MySQL...\n"
/usr/local/mysql/bin/mysqladmin -u ${mysql_username}-p${mysql_password} -S /tmp/mysql.sock shutdown
}
function_restart_mysql()
{
printf"Restarting MySQL...\n"
function_stop_mysql
sleep 5
function_start_mysql
}
function_kill_mysql()
{
kill -9$(ps -ef|grep 'bin/mysqld_safe'|grep ${mysql_port}|awk '{printf
$2}')
kill -9$(ps -ef|grep 'libexec/mysqld'|grep ${mysql_port}|awk '{printf $
2}')
}
if [ "$1" = "start" ]; then
function_start_mysql
elif [ "$1" = "stop" ]; then
function_stop_mysql
elif [ "$1" = "restart" ]; then
function_restart_mysql
elif [ "$1" = "kill" ]; then
function_kill_mysql
else
printf "Usage: /data0/mysql/${mysql_port}/mysql {start|stop|restart|kill
}\n"
fi
chmod +x /data0/mysql/3306/mysql
/data0/mysql/3306/mysqlstart
/usr/local/mysql/bin/mysql –uroot –p –S/tmp/mysql.sock
grant all privileges on *.* to ‘admin’@’localhost’identified by ‘12345678’;
grant all privileges on *.* to ‘admin’@’127.0.0.1’identified by ‘12345678’;
grant all privileges on *.* to ‘admin’@’%’ identifiedby ‘12345678’;
flush privileges;
use mysql;
select host,user,password from user;
lsof –n –i:3306
ps –ef|grep mysqld|grep –v grep
/data0/mysql/3306/mysqlstop
6. 编译安装PHP(FastCGI模式):
tar -zxvfphp-5.4.22.tar.gzcd php-5.4.22cp -frp /usr/lib64/libldap* /usr/lib/./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-bcmath --enable-shmop--enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers--enable-mbregex --enable-fpm --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 --with-pearmake ZEND_EXTRA_LIBS='-liconv'make installcp php.ini-production /usr/local/php/etc/php.inicp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.confcp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpmvim /etc/profile,添加:PATH=/usr/local/php/bin:$PATHPATH=/usr/local/php/sbin:$PATHchmod 755/etc/init.d/php-fpm chkconfig --addphp-fpm/usr/local/php/sbin/php-fpmps -ef|grep php7. 编译安装PHP的扩展:tar -zxvfmemcache-2.2.5.tgz cdmemcache-2.2.5/usr/local/php/bin/phpize./configure--with-php-config=/usr/local/php/bin/php-config make&& make installcd ../tar –zxvfeaccelerator-eaccelerator-42067ac.tar.gzcdeaccelerator-eaccelerator-42067ac/usr/local/php/bin/phpize./configure--enable-eaccelerator=shared --with-php-config=/usr/local/php/bin/php-config make
make install
cd ../
tar –zxvfPDO_MYSQL-1.0.2.tgz
cd PDO_MYSQL-1.0.2/usr/local/php/bin/phpize ln -s/usr/local/mysql/include/mysql/* /usr/local/include/
./configure--with-php-config=/usr/local/php/bin/php-config --with-pdo-mysql=/usr/local/mysqlmake&& make installcd ../ tar -zxvfImageMagick-6.8.7-10.tar.gz
cd ImageMagick-6.8.7-10./configure make && make install
cd ../
tar -zxvfimagick-3.1.2.tgz
cd imagick-3.1.2
/usr/local/php/bin/phpize
./configure--with-php-config=/usr/local/php/bin/php-config
make
make install
cd ../
8.修改php.ini文件:
cp php.ini php.ini.bak
手工修改,查找php.ini中的extension_dir=”./”修改为:
extension_dir=”/usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/”
并在此行后增加几行:
extension=”memcache.so”extension=”pdo_mysql.so”extension=”imagick.so”查找output_buffering= Off改为:output_buffering= On修改php.ini时区:date.timezone= Asia/Shanghai9.配置eAccelerator加速PHP:
mkdir -p /usr/local/eaccelerator_cache
vim php.ini:
按shift+g,跳转到配置文件的最末尾,加上配置信息:
zend_extension="/usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/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"
10.创建www用户和组,创建虚拟机的目录:
useradd www
mkdir -p /data0/htdocs/blog
chmod +w /data0/htdocs/blog/
chown -R www:www /data0/htdocs/blog/
mkdir -p /data0/htdocs/www
chmod +w /data0/htdocs/www
chown -R www:www /data0/htdocs/www
11.创建php-fpm配置文件:
cp /usr/local/php/etc/php-fpm.conf/usr/local/php/etc/php-fpm.conf.bak
vim /usr/local/php/etc/php-fpm.conf:
修改成下面的结果:
more php-fpm.conf|grep -v '^$'|grep -v ';'
pid = run/php-fpm.pid
error_log = log/php-fpm.log
log_level = notice
emergency_restart_threshold = 10
emergency_restart_interval = 1m
process_control_timeout = 5s
daemonize = yes
events.mechanism = epoll
user = www
group = www
listen = 127.0.0.1:9000
listen.mode = 0666
listen.allowed_clients = 127.0.0.1
pm = static
pm.max_children = 128
pm.start_servers = 20
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.max_requests = 102400
slowlog = log/$pool.log.slow
request_slowlog_timeout = 0s
request_terminate_timeout = 0
rlimit_files = 65535
rlimit_core = 0
chroot =
catch_workers_output = yes
env = $HOSTNAME
env = /usr/local/bin:/usr/bin:/bin
env = /tmp
env = /tmp
env = /tmp
env = $OSTYPE
env = $MACHTYPE
env = 2
php_admin_value = /usr/sbin/sendmail-t -i -f www@my.domain.com
php_flag = on
启动php-fpm:
/usr/local/php/sbin/php-fpm
ps –ef|grep php-fpm|grep –v ‘grep’
页:
[1]