selinux可能会致使编译安装失败,我们先禁用它。永久禁用,需要重启生效
sed -i ‘s/SELINUX=enforcing/SELINUX=disabled/g’ /etc/selinux/config
临时禁用,不需要重启
setenforce 0iptables -I INPUT -p tcp –dport 80 -j ACCEPT
安装必备工具
yum -y install gcc automake autoconf libtool make gcc-c++ glibc libxslt-devel 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-devel libidn libidn-devel openssl openssl-devel pcre pcre-devel libmcrypt libmcrypt-devel cmake
几点说明:
pcre、openssl、zlib是安装nginx时需要的
cmake是安装MySQL时需要的配置下载地址
cat > /usr/local/src/url << “EOF”http://www.cmake.org/files/v2.8/cmake-2.8.10.2.tar.gzhttp://nginx.org/download/nginx-1.8.1.tar.gzhttp://jp2.php.net/distributions/php-5.6.30.tar.gzhttp://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.30.tar.gzEOF
下载
wget -P /usr/local/src -i /usr/local/src/url
解压
cd /usr/local/srcfor i in *.tar.gz ; do tar zxvf $i; done
安装cmake
cd cmake-2.8.10.2./bootstrapgmake && gmake install
安装mysql
创建mysql安装目录、组、账号
groupadd mysql ; useradd -g mysql -s /sbin/nologin mysqlmkdir -p /data/mysql ; chown -R mysql:mysql /data/mysqlmkdir -p /usr/local/mysql ; chown -R mysql:mysql /usr/local/mysql
开始安装
cd ../mysql-5.6.30cmake \ -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \-DDEFAULT_CHARSET=utf8 \-DDEFAULT_COLLATION=utf8_general_ci \-DWITH_INNOBASE_STORAGE_ENGINE=1 \-DWITH_ARCHIVE_STORAGE_ENGINE=1 \-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \-DMYSQL_DATADIR=/data/mysql \-DMYSQL_TCP_PORT=3306 \-DENABLE_DOWNLOADS=1 .make && make install
初始化数据库 拷贝配置文件
cd /usr/local/mysql/scripts/mysql_install_db –user=mysql –datadir=/data/mysqlcp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnfcp support-files/mysql.server /etc/init.d/mysqld
添加启动目录
vim /etc/profile
按G移动光标到最后一行o插入以下两行
PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATHexport PATH
更新配置文件
source /etc/profile
设置开机启动并启动
chkconfig mysqld onservice mysqld start
登陆测试,默认是没有密码,直接回车就可进入
mysql -uroot -p
设置mysql密码
SET PASSWORD FOR ‘root’@’localhost’ = PASSWORD(‘password’);
查看用户
select user,host from mysql.user;
删除不必要的用户
drop user “”@localhost;drop user “”@c65mini.localdomain;drop user root@c65mini.localdomain;drop user root@’::1′;
赋予账号远程访问的权限
GRANT ALL PRIVILEGES ON *.* TO ‘root’@’127.0.0.1’ IDENTIFIED BY ‘你的密码’ WITH GRANT OPTION;GRANT ALL PRIVILEGES ON *.* TO ‘root’@’localhost’ IDENTIFIED BY ‘你的密码’ WITH GRANT OPTION;GRANT ALL PRIVILEGES ON *.* TO ‘root’@’c65mini.localdomain’ IDENTIFIED BY ‘你的密码’ WITH GRANT OPTION;
针对数据库创建一个全部权限的用户
grant all on wordpress.* to ‘admin’@’localhost’ identified by ‘123456’;UPDATE user SET password=PASSWORD(‘123456′) WHERE user=’root’;
其它一些信息查询: 检查mysql版本
mysql -uroot -p”密码” -e “select version();”
安装php
cd /usr/local/src/php-5.6.30./configure \–prefix=/usr/local/php \–with-config-file-path=/usr/local/php/etc \–enable-fpm \–with-fpm-user=php-fpm \–with-fpm-group=php-fpm \–with-mysql=/usr/local/mysql \–with-mysql-sock=/usr/local/mysql/mysql.sock \–with-libxml-dir \–with-gd \–with-jpeg-dir \–with-png-dir \–with-freetype-dir \–with-iconv-dir \–with-zlib-dir \–with-mcrypt \–enable-soap \–enable-gd-native-ttf \–enable-ftp \–enable-mbstring \–enable-exif \–enable-zend-multibyte \–disable-ipv6 \–with-pear \–with-curl \–with-openssl \–disable-fileinfomake && make install
创建用户
groupadd www ; useradd -g www /sbin/nologin www
修改配置文件
cp php.ini-production /usr/local/php/etc/php.inicat > /usr/local/php/etc/php-fpm.conf << “EOF”[global]pid = /usr/local/php/var/run/php-fpm.piderror_log = /usr/local/php/var/log/php-fpm.log[www]listen = /tmp/php-fcgi.sockuser = wwwgroup = wwwlisten.owner = wwwlisten.group = wwwpm = dynamicpm.max_children = 50pm.start_servers = 20pm.min_spare_servers = 5pm.max_spare_servers = 35pm.max_requests = 500rlimit_files = 1024EOF
保存配置文件后,检验配置是否正确的方法, 如果出现诸如 “test is successful” 字样,说明配置没有问题。
/usr/local/php/sbin/php-fpm -t
启动php-fpm
cp /usr/local/src/php-5.6.30/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpmchmod 755 /etc/init.d/php-fpmservice php-fpm startchkconfig php-fpm on
检测是否启动:
ps aux |grep php-fpm
看看是不是有很多个进程(大概20多个)。
安装nginx
cd ../nginx-1.8.1./configure \–prefix=/usr/local/nginx \–user=www \–group=www \–with-http_realip_module \–with-http_sub_module \–with-http_gzip_static_module \–with-pcre
编译nginx
make && make install
因为nginx比较小,所以很快就会安装完,而且也不会出什么错误
编写nginx启动脚本,并加入系统服务
cat > /etc/init.d/nginx <<“EOF”#!/bin/bash# chkconfig: – 30 21# description: http service.# Source Function Library. /etc/init.d/functions# Nginx SettingsNGINX_SBIN=”/usr/local/nginx/sbin/nginx”NGINX_CONF=”/usr/local/nginx/conf/nginx.conf”NGINX_PID=”/usr/local/nginx/logs/nginx.pid”RETVAL=0prog=”Nginx”start() {echo -n $”Starting $prog: “mkdir -p /dev/shm/nginx_tempdaemon $NGINX_SBIN -c $NGINX_CONFRETVAL=$?echoreturn $RETVAL}stop() {echo -n $”Stopping $prog: “killproc -p $NGINX_PID $NGINX_SBIN -TERMrm -rf /dev/shm/nginx_tempRETVAL=$?echoreturn $RETVAL}reload(){echo -n $”Reloading $prog: “killproc -p $NGINX_PID $NGINX_SBIN -HUPRETVAL=$?echoreturn $RETVAL}restart(){stopstart}configtest(){$NGINX_SBIN -c $NGINX_CONF -treturn 0}case “$1” instart)start;;stop)stop;;reload)reload;;restart)restart;;configtest)configtest;;*)echo $”Usage: $0 {start|stop|reload|restart|configtest}”RETVAL=1esacexit $RETVALEOF
保存后,更改权限:
chmod 755 /etc/init.d/nginxchkconfig –add nginxchkconfig nginx on
更改nginx配置
首先把原来的配置文件清空: 写入如下内容:
cat > /usr/local/nginx/conf/nginx.conf << “EOF”user www www;worker_processes 2;error_log /usr/local/nginx/logs/nginx_error.log crit;pid /usr/local/nginx/logs/nginx.pid;worker_rlimit_nofile 51200;events{use epoll;worker_connections 6000;}http{include mime.types;default_type application/octet-stream;server_names_hash_bucket_size 3526;server_names_hash_max_size 4096;log_format combined_realip ‘$remote_addr $http_x_forwarded_for [$time_local]’‘$host “$request_uri” $status’‘”$http_referer” “$http_user_agent”‘;sendfile on;tcp_nopush on;keepalive_timeout 30;client_header_timeout 3m;client_body_timeout 3m;send_timeout 3m;connection_pool_size 256;client_header_buffer_size 1k;large_client_header_buffers 8 4k;request_pool_size 4k;output_buffers 4 32k;postpone_output 1460;client_max_body_size 10m;client_body_buffer_size 256k;client_body_temp_path /usr/local/nginx/client_body_temp;proxy_temp_path /usr/local/nginx/proxy_temp;fastcgi_temp_path /usr/local/nginx/fastcgi_temp;fastcgi_intercept_errors on;tcp_nodelay on;gzip on;gzip_min_length 1k;gzip_buffers 4 8k;gzip_comp_level 5;gzip_http_version 1.1;gzip_types text/plain application/x-javascript text/css text/htm application/xml;include vhosts/*.conf;}EOF
mkdir -p /usr/local/nginx/conf/vhosts
cat > /usr/local/nginx/conf/vhosts/default.conf << “EOF”server{listen 80 default_server;server_name localhost;index index.html index.htm index.php;root /tmp/403;deny all;}EOF
mkdir -p /data/www/test
cat > /usr/local/nginx/conf/vhosts/test.conf << “EOF”server{listen 80;server_name test.com;index index.html index.htm index.php;root /data/www/test;location ~ \.php$ {include fastcgi_params;fastcgi_pass unix:/tmp/php-fcgi.sock;fastcgi_index index.php;fastcgi_param SCRIPT_FILENAME /data/www/test$fastcgi_script_name;}}EOF
保存配置后,先检验一下配置文件是否有错误存在:
/usr/local/nginx/sbin/nginx -t
启动看是否有进程。
service nginx startps aux |grep nginx
测试是否解析php文件
cat > /data/www/test/2.php << “EOF” EOF
测试php是否解析
curl -x127.0.0.1:80 test.com/2.php