当前位置:Gxlcms > mysql > centos6.4(64位)安装nginx1.7.1+php-5.5.13+mysql-5.5.25_MySQL

centos6.4(64位)安装nginx1.7.1+php-5.5.13+mysql-5.5.25_MySQL

时间:2021-07-01 10:21:17 帮助过:7人阅读

CentOS6CentOSNginx

本文所用的所有安装包下载:http://pan.baidu.com/s/1zWTDc

第一步:安装所需依赖包

yum -y install gcc gcc-c++ autoconf cmake libjpeg libjpeg-devel libpng /libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel /glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel /curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel /openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients /openldap-servers gd gd2 gd-devel gd2-devel perl-CPAN

第二步:安装mysql-5.5.25

创建mysql用户和组

groupadd mysqluseradd -g mysql -s /usr/sbin/nologin mysqlmkdir -p /data/mysql/datamkdir /data/logschown -R mysql:mysql /usr/local/mysqlchown -R mysql:mysql /data/mysql

编译安装mysql

tar zxvf mysql-5.5.25.tar.gzcd mysql-5.5.25cmake  -DCMAKE_INSTALL_PREFIX=/usr/local/mysql  -DMYSQL_DATADIR=/data/mysql/data  -DDEFAULT_CHARSET=utf8  -DDEFAULT_COLLATION=utf8_unicode_ci  -DWITH_READLINE=1  -DWITH_SSL=system  -DWITH_EMBEDDED_SERVER=1  -DENABLED_LOCAL_INFILE=1  -DDEFAULT_COLLATION=utf8_general_ci  -DWITH_MYISAM_STORAGE_ENGINE=1  -DWITH_INNOBASE_STORAGE_ENGINE=1  -DWITH_DEBUG=0make && make install

配置开机自启动

cp ./support-files/mysql.server /etc/init.d/mysqldchmod +x /etc/init.d/mysqldchkconfig --add mysqldchkconfig mysqld on

添加MySQL的软链接以适应init脚本

ln -sv /usr/local/mysql/bin/mysql  /usr/sbin/mysqlln -sv /usr/local/mysql/bin/mysqladmin  /usr/sbin/mysqladminln -sv /usr/local/mysql/bin/mysqldump  /usr/sbin/mysqldump

修改配置文件

cp ./support-files/my-medium.cnf /etc/my.cnfvi /etc/my.cnf# 输入以下内容(可以先清空默认内容):[mysqld]datadir=/data/mysql/datasocket=/tmp/mysql.sockuser=mysqlsymbolic-links=0[mysqld_safe]log-error=/data/mysql/logs/mysqld.logpid-file=/data/mysql/mysqld.piduser=mysqltmpdir=/tmp

初始化数据库

/usr/local/mysql/scripts/mysql_install_db  --user=mysql  --basedir=/usr/local/mysql  --datadir=/data/mysql/data

启动mysql

service mysqld start  # 或 /etc/init.d/mysqld start

进入mysql(直接回车即可进入mysql)

/usr/local/mysql/bin/mysql

输入以下SQL语句,创建一个具有root权限的用户(admin)和密码(12345678)

GRANT ALL PRIVILEGES ON *.* TO 'admin'@'localhost' IDENTIFIED BY '12345678';GRANT ALL PRIVILEGES ON *.* TO 'admin'@'127.0.0.1' IDENTIFIED BY '12345678';DELETE FROM user WHERE User!=‘admin’; #删除原先默认的用户,仅保留新建的admin用户

第三步:安装nginx1.7.1

添加www用户和组、创建网站虚拟目录

groupadd wwwuseradd -g www -s /usr/sbin/nologin wwwmkdir -p /data/htdocs/wwwchmod +w /data/htdocs/wwwchown -R www:www /data/htdocs/www

安装Nginx所需的pcre库

tar zxvf pcre-8.33.tar.gzcd pcre-8.33./configuremake && make installln -s /usr/local/lib/libpcre.so.1 /usr/lib64/libpcre.so.1cd ../

安装nginx1.7.1

tar zxvf nginx-1.7.1.tar.gzcd nginx-1.7.1./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_realip_module --with-http_image_filter_modulemake && make installcd ../

创建nginx日志目录

mkdir -p /data/logschmod +w /data/logschown -R www:www /data/logs

创建Nginx配置文件,在/usr/local/nginx/conf/目录中创建nginx.conf文件:

rm -f /usr/local/nginx/conf/nginx.confvi /usr/local/nginx/conf/nginx.conf

输入以下内容:

user  www www;worker_processes 8;error_log  /data/logs/nginx_error.log  crit;pid        /usr/local/nginx/nginx.pid;#Specifies the value for maximum file descriptors that can be opened by this process.worker_rlimit_nofile 65535;events{    use epoll;    worker_connections 65535;}http{    include       mime.types;    default_type  application/octet-stream;    #charset  gb2312;          server_names_hash_bucket_size 128;    client_header_buffer_size 32k;    large_client_header_buffers 4 32k;    client_max_body_size 8m;          sendfile on;    tcp_nopush     on;    keepalive_timeout 60;    tcp_nodelay on;    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;    gzip on;    gzip_min_length  1k;    gzip_buffers     4 16k;    gzip_http_version 1.0;    gzip_comp_level 2;    gzip_types       text/plain application/x-javascript text/css application/xml;    gzip_vary on;    #limit_zone  crawler  $binary_remote_addr  10m;    server    {        listen       80;        server_name  localhost;        index index.html index.htm index.php;        root  /data/htdocs/www;        #limit_conn   crawler  20;                                            location ~ .*/.(php|php5)?$        {                  #fastcgi_pass  unix:/tmp/php-cgi.sock;            fastcgi_pass  127.0.0.1:9000;            fastcgi_index index.php;            include fcgi.conf;        }        location ~ .*/.(gif|jpg|jpeg|png|bmp|swf)$        {            expires      30d;        }        location ~ .*/.(js|css)?$        {            expires      1h;        }        }}

在/usr/local/nginx/conf/目录中创建fcgi.conf文件:

vi /usr/local/nginx/conf/fcgi.conf

输入一下内容:

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;# PHP only, required if PHP was built with --enable-force-cgi-redirectfastcgi_param  REDIRECT_STATUS    200;

启动nginx:

ulimit -SHn 65535/usr/local/nginx/sbin/nginx

第三步:安装php5.5.13

安装PHP所需依赖包:

tar zxvf libiconv-1.14.tar.gzcd libiconv-1.14./configure --prefix=/usr/localmakemake installcd ../tar zxvf libmcrypt-2.5.8.tar.gzcd libmcrypt-2.5.8/./configuremakemake install/sbin/ldconfigcd libltdl/./configure --enable-ltdl-installmakemake installcd ../../tar zxvf mhash-0.9.9.9.tar.gzcd mhash-0.9.9.9/./configuremakemake installcd ../# 对共享库做符号链接ln -s /usr/local/lib/libmcrypt.la /usr/lib64/libmcrypt.laln -s /usr/local/lib/libmcrypt.so /usr/lib64/libmcrypt.soln -s /usr/local/lib/libmcrypt.so.4 /usr/lib64/libmcrypt.so.4ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib64/libmcrypt.so.4.4.8ln -s /usr/local/lib/libmhash.a /usr/lib64/libmhash.aln -s /usr/local/lib/libmhash.la /usr/lib64/libmhash.laln -s /usr/local/lib/libmhash.so /usr/lib64/libmhash.soln -s /usr/local/lib/libmhash.so.2 /usr/lib64/libmhash.so.2ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib64/libmhash.so.2.0.1ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-configln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib64/libmysqlclient.so.18tar zxvf mcrypt-2.6.8.tar.gzcd mcrypt-2.6.8//sbin/ldconfig./configuremakemake installcd ../

安装php:

tar zxvf php-5.5.13.tar.gzcd php-5.5.13./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 --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 --enable-mbregex --enable-fpm --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf /--with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap /--enable-opcache=no --without-pear --disable-fileinfo#注:如果内存较大 可以去掉--disable-fileinfomake ZEND_EXTRA_LIBS='-liconv'make installcp php.ini-development /usr/local/php/etc/php.inicd ../cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.confvi /usr/local/php/etc/php-fpm.conf

修改

user = nobodygroup = nobody

user = wwwgroup = www

# 将;pid = run/php-fpm.pid前的;去掉并修改为pid = /usr/local/php/var/run/php-fpm.pid

启动php-fpm

/usr/local/php/sbin/php-fpm

将Nginx与fpm加入自启动

vi /etc/rc.local# 输入ulimit -SHn 65535/usr/local/php/sbin/php-fpm/usr/local/nginx/sbin/nginx

编译PHP扩展模块memcache、pdo_mysql、imagick

tar zxvf memcache-3.0.8.tgzcd memcache-3.0.8/usr/local/php/bin/phpize./configure --with-php-config=/usr/local/php/bin/php-configmakemake installcd ../tar zxvf PDO_MYSQL-1.0.2.tgzcd 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/mysqlln -s /usr/local/mysql/include/* /usr/local/include/makemake installcd ../tar zxvf ImageMagick.tar.gzcd ImageMagick-6.5.1-2/./configuremakemake installcd ../tar zxvf imagick-3.2.0RC1.tgzcd imagick-3.2.0RC1/usr/local/php/bin/phpizeexport PKG_CONFIG_PATH=/usr/local/lib/pkgconfig./configure --with-php-config=/usr/local/php/bin/php-configmakemake installcd ../

修改php.ini配置文件

vi /usr/local/php/etc/php.ini#查找; extension_dir = "/" 将前面的;去掉并修改为extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20121212/"#并加入extension=memcache.soextension=pdo_mysql.soextension=imagick.so

执行下面的命令使配置文件立即生效:

kill -USR2 `cat /usr/local/php/var/run/php-fpm.pid`

其他(可选):

优化linux内核参数

vi /etc/sysctl.conf

在末尾增加以下内容:

# Addnet.ipv4.tcp_max_syn_backlog = 65536net.core.netdev_max_backlog =  32768net.core.somaxconn = 32768net.core.wmem_default = 8388608net.core.rmem_default = 8388608net.core.rmem_max = 16777216net.core.wmem_max = 16777216net.ipv4.tcp_timestamps = 0net.ipv4.tcp_synack_retries = 2net.ipv4.tcp_syn_retries = 2net.ipv4.tcp_tw_recycle = 1#net.ipv4.tcp_tw_len = 1net.ipv4.tcp_tw_reuse = 1net.ipv4.tcp_mem = 94500000 915000000 927000000net.ipv4.tcp_max_orphans = 3276800#net.ipv4.tcp_fin_timeout = 30#net.ipv4.tcp_keepalive_time = 120net.ipv4.ip_local_port_range = 1024  65535

使配置立即生效:

/sbin/sysctl -p

安装opcache(因为PHP 5.5已经集成Zend Opcache,可以替代eaccelerator)

tar zxvf zendopcache-7.0.3.tgzcd zendopcache-7.0.3/usr/local/php/bin/phpize./configure --with-php-config=/usr/local/php/bin/php-configmakemake installcd ../

在php.ini中加入下面配置:

[opcache]zend_extension="/usr/local/php/lib/php/extensions/no-debug-non-zts-20121212/opcache.so"opcache.memory_consumption=128opcache.interned_strings_buffer=8opcache.max_accelerated_files=4000opcache.revalidate_freq=60opcache.fast_shutdown=1opcache.enable_cli=1

# 使php.ini配置文件立即生效kill -USR2 `cat /usr/local/php/var/run/php-fpm.pid`

常用命令:

#修改完php.ini后执行:kill -USR2 `cat /usr/local/php/var/run/php-fpm.pid`#修改完nginx.conf后执行/usr/local/nginx/sbin/nginx -s reload#重启mysql服务执行:service mysqld (start|stop|restart)

人气教程排行