CentOS6.2编译安装Nginx1.0.14+MySQL5.5.22+PHP5.3.10步骤分享
在CentOS6.2下编译安装Nginx、MySQL、PHP需要经历多个步骤,下面将详细介绍整个过程。
1. 安装常用开发工具
执行下列命令安装常用的开发工具
yum -y update
yum -y groupinstall "Development Tools"
yum -y install wget unzip libtool-ltdl-devel openssl-devel perl-core zlib-devel
2. MySQL安装
安装MySQL5.5.22
cd /usr/local/src/
wget http://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.22.tar.gz
tar xzvf mysql-5.5.22.tar.gz
cd mysql-5.5.22/
./configure --prefix=/usr/local/mysql --with-extra-charsets=complex --enable-thread-safe-client --enable-assembler --with-ssl
make && make install
groupadd mysql
useradd -r -g mysql mysql
cd /usr/local/mysql/
chown -R mysql .
chgrp -R mysql .
scripts/mysql_install_db --user=mysql
chown -R root .
chown -R mysql data
cp support-files/my-medium.cnf /etc/my.cnf
/usr/local/mysql/bin/mysqld_safe &
/usr/local/mysql/bin/mysqladmin -u root password '123456'
此时MySQL已成功安装并创建一个root用户,并且设置了密码为123456。
3. PHP安装
编译安装PHP5.3.10
cd /usr/local/src/
wget http://cn2.php.net/distributions/php-5.3.10.tar.gz
tar zxvf php-5.3.10.tar.gz
cd php-5.3.10/
./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 \
--with-curlwrappers \
--enable-mbregex \
--enable-fpm \
--enable-mbstring \
--with-mcrypt \
--enable-sockets \
--with-ldap \
--with-ldap-sasl \
--with-bz2 \
--with-gd \
--enable-gd-native-ttf \
--with-gmp \
--with-openssl \
--with-mhash \
--enable-zip \
--enable-soap \
--with-xsl \
--with-pear \
--with-gettext
make && make install
cp php.ini-development /usr/local/php/etc/php.ini
cp /usr/local/src/php-5.3.10/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm
chkconfig --add php-fpm
chkconfig php-fpm on
通过上面的命令,已将PHP安装到了/usr/local/php目录下,并且启用了fpm模式。
4. Nginx安装
编译安装Nginx1.0.14
cd /usr/local/src/
wget http://nginx.org/download/nginx-1.0.14.tar.gz
tar zxvf nginx-1.0.14.tar.gz
cd nginx-1.0.14/
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --without-mail_imap_module --without-mail_pop3_module --without-mail_smtp_module --with-pcre
make && make install
通过上述命令,Nginx成功安装到了/usr/local/nginx目录下,并且开启了http_stub_status_module、http_ssl_module、http_gzip_static_module。
5. 配置Nginx和PHP
修改Nginx配置文件/usr/local/nginx/conf/nginx.conf
user nginx nginx;
worker_processes 4;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
server_tokens off;
access_log off;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 5;
gzip on;
gzip_types text/plain application/xml text/css text/javascript application/x-javascript application/json;
gzip_comp_level 2;
server {
listen 80;
server_name localhost;
root /usr/local/nginx/html;
index index.php index.html index.htm;
error_page 404 /404.html;
location = /404.html {
internal;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
internal;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.(ht|htaccess)$ {
deny all;
}
}
}
修改PHP-fpm的配置文件,在/usr/local/php/etc/php-fpm.conf
文件中找到以下这一段
[pool www]
user = nginx
group = nginx
listen = 127.0.0.1:9000
listen.owner = nginx
listen.group = nginx
pm = dynamic
pm.max_children = 50
并将配置中的user和group改为nginx,适应之前修改的Nginx配置。
最后,重启Nginx和PHP-fpm。
/usr/local/nginx/sbin/nginx -s reload
/etc/init.d/php-fpm restart
通过上述步骤,CentOS6.2下编译安装Nginx1.0.14+MySQL5.5.22+PHP5.3.10已完成。