构建高性能Web环境(linux/nginx/mysql/php-fastcgi)(2)

修改my.cnf文件参数(参数适用于大于2G内存服务器)

[client]port = 3306socket = /tmp/mysql.sock[mysqld]user = mysqlport = 3306socket = /tmp/mysql.sockbasedir = /usr/local/webserver/mysqldatadir = /data/mysqldata/databaselog-error = /data/mysqldata/log/mysql_error.logpid-file = /data/mysqldata/pid/mysql.pidskip-external-lockingskip-name-resolveback_log = 500key_buffer_size = 256Mmax_allowed_packet = 32Mthread_stack = 192Ktable_cache = 256sort_buffer_size = 4Mread_buffer_size = 4Mjoin_buffer_size = 4Mread_rnd_buffer_size = 8Mmyisam_sort_buffer_size = 64Mthread_cache = 128thread_cache_size = 10query_cache_size = 32Mtmp_table_size = 128Mmax_connections = 5000wait_timeout = 60max_connect_errors = 6000expire_logs_days = 30server-id = 1[mysqldump]quickmax_allowed_packet = 32M[mysql]no-auto-rehash

初始化MySQL服务

/usr/local/webserver/mysql/bin/mysql_install_db \
--basedir=http://down.chinaz.com/usr/local/webserver/mysql \
--datadir=http://down.chinaz.com/data/mysqldata/database \
--user=mysql

启动MySQL服务

/usr/local/webserver/mysql/bin/mysqld_safe --user=mysql & //启动服务
/usr/local/webserver/mysql/bin/mysqladmin -u root -p shutdown //停止服务

修改root密码

/usr/local/webserver/mysql/bin/mysqladmin -u root password ‘yourpassword’

四、编译安装PHP(FastCGI模式)

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=http://down.chinaz.com/usr/local/webserver/php \
--with-config-file-path=http://down.chinaz.com/usr/local/webserver/php/etc \
--with-mysql=http://down.chinaz.com/usr/local/webserver/mysql \
--with-mysqli=http://down.chinaz.com/usr/local/webserver/mysql/bin/mysql_config \
--with-gd \
--with-jpeg-dir \
--with-iconv-dir=http://down.chinaz.com/usr/local \
--with-libxml-dir=http://down.chinaz.com/usr \
--with-zlib \
--with-png-dir \
--with-curl \
--with-ldap \
--with-xmlrpc \
--with-openssl \
--with-mhash \
--with-mcrypt \
--with-freetype-dir \
--with-ldap-sasl \
--with-curlwrappers \
--enable-xml \
--enable-shared \
--enable-discard-path \
--enable-safe-mode \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-inline-optimization \
--enable-mbregex \
--enable-fastcgi \
--enable-fpm \
--enable-force-cgi-redirect \
--enable-mbstring=all \
--enable-gd-native-ttf \
--enable-pcntl \
--enable-sockets \
--enable-zip \
--enable-soapmake ZEND_EXTRA_LIBS='-liconv'
make install && cd ..

五、安装PHP扩展模块

tar zxvf memcache-2.2.6.tgz
cd memcache-2.2.6/
/usr/local/webserver/php/bin/phpize
./configure --with-php-config=http://down.chinaz.com/usr/local/webserver/php/bin/php-config
make && make install && cd ..tar zxvf PDO_MYSQL-1.0.2.tgz
cd PDO_MYSQL-1.0.2/
/usr/local/webserver/php/bin/phpize
./configure \
--with-php-config=http://down.chinaz.com/usr/local/webserver/php/bin/php-config \
--with-pdo-mysql=http://down.chinaz.com/usr/local/webserver/mysql
make && make install && cd ..tar jxvf eaccelerator-0.9.6.1.tar.bz2
cd eaccelerator-0.9.6.1/
/usr/local/webserver/php/bin/phpize
./configure --enable-eaccelerator=shared \
--with-php-config=http://down.chinaz.com/usr/local/webserver/php/bin/php-config
make && make install && cd .. tar zxvf ImageMagick-6.7.0-8.tar.gz
cd ImageMagick-6.7.0-8/
./configure && make && make install && cd ..tar zxvf imagick-3.0.0.tgz
cd imagick-3.0.0/
/usr/local/webserver/php/bin/phpize
./configure --with-php-config=http://down.chinaz.com/usr/local/webserver/php/bin/php-config
make && make install && cd ..

修改php.ini文件

vim /usr/local/webserver/php/etc/php.ini

查找:

extension_dir = "./"

修改为:

extension_dir = "/usr/local/webserver/php/lib/php/extensions/no-debug-non-zts-20060613/"

并在此行后增加以下几行,然后保存:

extension = "memcache.so"
extension = "pdo_mysql.so"
extension = "imagick.so"

再查找:output_buffering = Off
修改为:output_buffering = On

创建缓存目录,配置eAccelerator加速PHP:

mkdir -p /usr/local/webserver/eaccelerator_cache

将以下参数添加到php.ini文件末尾

查找:

extension_dir = "./"

修改为:

extension_dir = "/usr/local/webserver/php/lib/php/extensions/no-debug-non-zts-20060613/"

并在此行后增加以下几行,然后保存:

extension = "memcache.so"
extension = "pdo_mysql.so"
extension = "imagick.so"

再查找:output_buffering = Off
修改为:output_buffering = On

创建缓存目录,配置eAccelerator加速PHP:
mkdir -p /usr/local/webserver/eaccelerator_cache

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/10999.html