今天是: 收藏本站 设为主页
网站首页 >  技术专栏  >  linux  > 

CentOS 6 编译安装Nginx+PHP+Mysql

日期:2012-07-09  点击率:1172


[1].安装Nginx

1,添加一个不能登录且没有主目录的用户:

1 # useradd www -M -s /sbin/nologin

2,必要的组件

# wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.13.zip
# unzip pcre-8.13.zip
# cd pcre-8.13
# ./configure
# make && make install

3,编译nginx并安装
# 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,安装必要的组件

# yum -y install libjpeg-devel libpng-devel
# wget ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/libmcrypt-2.5.7.tar.gz
# 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并安装

# 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配置文件

# 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

[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

[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,添加服务启动脚本
# 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, 创建用户和用户组与赋予数据存放目录权限

# useradd mysql -M -s /sbin/nologin
# chown mysql.mysql -R /data/mysql/

3.4, 安装必要的组件

# yum -y install cmake
# yum -y install ncurses-devel

3.5, 编译安装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, 初始化数据库

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

3.7, 配置环境

# 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, 启动并设置初始密码

# /etc/init.d/mysql start
# mysqladmin -uroot password '123123'

进行再修改密码的语句
1: UPDATE mysql.user SET Password = PASSWORD(‘newpwd’) WHERE User = ‘root’;(生新设置密码)
2: flush privileges;(刷新权限)




下一篇:CentOS 5.x编译安装配置ProFTPd与添加MySQL虚拟用户   上一篇:linux如何设置swap交换分区