CentOS 6 编译安装Nginx+PHP+Mysql[服务器安全]
本文“CentOS 6 编译安装Nginx+PHP+Mysql[服务器安全]”是由七道奇为您精心收集,来源于网络转载,文章版权归文章作者所有,本站不对其观点以及内容做任何评价,请读者自行判断,以下是其具体内容:
[1].安装 Nginx
1,增添一个不能登录且没有主目录的用户:
1
# useradd www -M -s /sbin/nologin
2,必要的组件
1
2
3
4
5
# wget
# unzip pcre-8.13.zip
# cd pcre-8.13
# ./configure
# make && make install
3,编译nginx并安装
1
2
3
4
# tar -zxvf nginx-1.1.2.tar.gz
# cd nginx-1.1.2
# ./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_stub_status_module --with-http_ssl_module
# make && make install
[2].安装 PHP
1,安装必要的组件
1
2
3
4
5
6
# yum -y install libjpeg-devel libpng-devel
# wget
# tar -zxvf libmcrypt-2.5.7.tar.gz
# cd libmcrypt-2.5.7
# ./configure
# make && make install
==64位系统==
1
# ln -s /usr/lib64/mysql/ /usr/lib/mysql
==64位系统==
2,编译php并安装
1
2
3
# cd php-5.3.8
# ./configure --prefix=/usr/local/php --with-iconv --with-zlib --enable-xml --disable-rpath --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-mysql --with-mysqli --enable-sqlite-utf8 --with-pdo-mysql --enable-ftp --with-jpeg-dir --with-freetype-dir --with-png-dir --enable-fpm --with-fpm-user=www --with-fpm-group=www
# make && make install
3,拷贝和改正php配置文件
1
2
3
# cp php.ini-production /usr/local/php/lib/php.ini 或是 /usr/local/lib/php.ini
# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
# /usr/local/php/bin/php --ini //测试ini文件能否加载
改正php.ini
1
2
3
4
5
6
7
8
9
10
[PHP]
safe_mode = On
register_globals = Off
magic_quotes_gpc = Off
allow_url_fopen = Off
allow_url_include = Off
expose_php=Off
disable_functions = shell_exec,system,exec,passthru,show_source,curl_exec,curl_multi_exec,get_cfg_var
[Date]
date.timezone = “Asia/Shanghai”
改正php-fpm.conf
1
2
3
4
5
6
7
8
9
10
11
[global]
pid = run/php-fpm.pid
error_log = log/php-fpm.log
log_level = notice
emergency_restart_threshold = 0
emergency_restart_interval = 0
[www]
pm.start_servers = 20
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.max_requests = 500
4,增添服务启动脚本
1
2
3
4
5
6
7
8
# cp nginx /etc/init.d/nginx
# cp php-fpm /etc/init.d/php-fpm
# chmod 755 /etc/init.d/nginx
# chmod 755 /etc/init.d/php-fpm
# chkconfig --add nginx
# chkconfig --add php-fpm
# chkconfig nginx on
# chkconfig php-fpm on
[3].安装 Mysql
3.1, 成立mysql安装目录
1
# mkdir -p /usr/local/mysql/
3.2, 成立数据存放目录
1
# mkdir -p /data/mysql/
3.3, 成立用户和用户组与赋予数据存放目录权限
1
2
# useradd mysql -M -s /sbin/nologin
# chown mysql.mysql -R /data/mysql/
3.4, 安装必要的组件
1
2
# yum -y install cmake
# yum -y install ncurses-devel
3.5, 编译安装Mysql
1
2
# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_UNIX_ADDR=/data/mysql/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS:STRING=utf8,gbk -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1 -DMYSQL_DATADIR=/data/mysql -DMYSQL_USER=mysql -DMYSQL_TCP_PORT=3306
# make && make install
3.6, 初始化数据库
1
2
# cd /usr/local/mysql
# scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql/
3.7, 配置环境
1
2
3
4
5
# cp support-files/my-medium.cnf /etc/my.cnf
# cp support-files/mysql.server /etc/init.d/mysql
# chmod 755 /etc/init.d/mysql
# chkconfig mysql on
# export PATH=/usr/local/mysql/bin:$PATH
3.8, 启动并设置初始密码
1
2
# /etc/init.d/mysql start
# mysqladmin -uroot password '123123'
举行再改正密码的语句
1: UPDATE mysql.user SET Password = PASSWORD(‘newpwd’) WHERE User = ‘root’;(生新设置密码)
2: flush privileges;(革新权限)
以上是“CentOS 6 编译安装Nginx+PHP+Mysql[服务器安全]”的内容,如果你对以上该文章内容感兴趣,你可以看看七道奇为您推荐以下文章:
本文地址: | 与您的QQ/BBS好友分享! |