CentOS6.7系统下编译安装Nginx-1.6.2 + MySQL-5.5.16 + PHP-5.6.2 WEB环境,简称LNMP架构。
##一、编译安装PHP##
####1. 下载并解压####
wget http://cn2.php.net/distributions/php-5.6.2.tar.gz
tar -zxvf php-5.6.2.tar.gz
####2. 编译安装####
进入目录、配置
cd php-5.6.2
./configure --enable-fpm --prefix=/usr/local/servers/php --with-config-file-path=/usr/local/servers/php/etc --enable-mbstring --enable-sockets --with-curl --with-mcrypt
如果提示下面的错误,请执行安装
configure: error: xml2-config not found. Please check your libxml2 installation.
yum install libxml2
yum install libxml2-devel -y
如果提示下面的错误,请执行安装
configure: error: Please reinstall the libcurl distribution - easy.h should be in <curl-dir>/include/curl/
yum install curl curl-devel
如果提示下面的错误,请执行安装
configure: error: mcrypt.h not found. Please reinstall libmcrypt.
yum install -y libmcrypt-devel
执行编译并安装
make && make install
如果提示下面的错误,加入--disable-fileinfo
参数,重新执行配置,在编译安装
make: *** [ext/fileinfo/libmagic/apprentice.lo] Error 1
####附加####
启动php-fpm
/usr/local/servers/php/sbin/php-fpm
php 5.3.3 以后的php-fpm 不再支持 php-fpm 以前具有的 /usr/local/php/sbin/php-fpm (start|stop|reload)等命令,所以不要再看这种老掉牙的命令了,需要使用信号控制:
master进程可以理解以下信号
INT, TERM
立刻终止
QUIT
平滑终止
USR1
重新打开日志文件
USR2
平滑重载所有worker进程并重新载入配置和二进制模块
先查看php-fpm的master进程号
ps aux|grep php-fpm
nobody 14692 0.0 2.6 282944 13268 ? S 13:46 0:01 php-fpm: pool www
root 14772 0.0 0.1 103308 836 pts/2 S+ 14:50 0:00 grep php-fpm
root 25710 0.0 0.6 200700 3480 ? Ss Sep20 0:02 php-fpm: master process (/usr/local/servers/php/etc/php-fpm.conf)
重启php-fpm
kill -USR2 25710
关闭php-fpm
kill -QUIT 25710
##二、编译安装Nginx##
####1. 下载并解压####
wget http://nginx.org/download/nginx-1.6.2.tar.gz
tar zxvf nginx-1.6.2.tar.gz
####2. 编译安装####
进入目录、配置
cd nginx-1.6.2
./configure --prefix=/usr/local/servers/nginx --with-http_realip_module --with-http_sub_module --with-http_gzip_static_module --with-http_stub_status_module --with-pcre
如果提示下面的错误,请执行安装
./configure: error: the HTTP rewrite module requires the PCRE library. You can either disable the module by using --without-http_rewrite_module option, or install the PCRE library into the system, or build the PCRE library statically from the source with nginx by using --with-pcre=<path> option.
yum -y install pcre-devel
执行编译并安装
make && make install
####附加####
启动Nginx服务
/usr/local/servers/nginx/sbin/nginx
重启Nginx服务
/usr/local/servers/nginx/sbin/nginx -s reload
修改Nginx配置,使其支持执行PHP
vim /usr/local/servers/nginx/conf/nginx.conf
server {
listen 80;
server_name www.zhile.name;
root /srv/www/zhile/;
location / {
index index.html index.htm index.php;
if (!-e $request_filename){
rewrite ^/(.*) /index.php last;
}
}
location ~ .php {
fastcgi_pass 127.0.0.1:9000;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_script_name;
}
}
##三、编译安装MySQL##
####1. 下载并解压####
wget https://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.40.tar.gz
wget http://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.16.tar.gz
tar zxvf mysql-5.5.16.tar.gz
####2. 安装编译代码需要的包####
yum install cmake gcc-c++ ncurses-devel
####3. 编译安装####
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/servers/mysql -DMYSQL_DATADIR=/usr/local/servers/mysql/data -DMYSQL_TCP_PORT=3306 -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_DEBUG=0 -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1
gmake
make install
####4. 配置MySQL####
设置权限
使用下面的命令查看是否有mysql用户及用户组
cat /etc/passwd
cat /etc/group
如果没有就创建
groupadd mysql
useradd -c "MySQL Server" -g mysql mysql -s /sbin/nologin
修改mysql权限
chown -R mysql:mysql /usr/local/servers/mysql
初始化配置
/usr/local/servers/mysql/scripts/mysql_install_db --basedir=/usr/local/servers/mysql --datadir=/usr/local/servers/mysql/data --user=mysql
注意:启动MySQL之前,先看看MySQL的配置目录是否存在my.cnf
,如果存在,请将该配置文件删除或者改名字备份,否则会造成MySQL启动失败
查看MySQL的配置目录
/usr/local/servers/mysql/bin/mysql --help | grep my.cnf
/etc/my.cnf /etc/mysql/my.cnf /usr/local/servers/mysql/etc/my.cnf ~/.my.cnf
复制MySQL配置到配置目录
cp /usr/local/servers/mysql/support-files/my-large.cnf /etc/my.cnf
启动MySQL
添加服务,拷贝服务脚本到init.d目录,并设置开机启动
cp /usr/local/servers/mysql/support-files/mysql.server /etc/init.d/mysqld
chkconfig mysqld on
service mysqld start
设置MySQL的root账号密码
/usr/local/servers/mysql/bin/mysqladmin -uroot password 'mypassword'