1.关闭防火墙、安装依赖库
关闭防火墙
/etc/init.d/iptables stop#yum install wget
#yum install pcre
#yum install openssl* 含MD5 不然nginx --with-http_ssl_module 会报错 ------
yum -y install gcc gcc-c++ autoconf 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 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers make cmake gd gd2 gd-devel gd2-devel libaio
添加nginx用户组
/usr/sbin/groupadd www
/usr/sbin/useradd -g www www
修改Linux最大连接数
ulimit -SHn 65535
sh -x /usr/local/sh/tar_all.sh
2、安装nginx
安装pcre
cd pcre-8.32
./configure --prefix=/usr/local/pcre
make && make install
cd ..
安装openssl
cd openssl-1.0.0e
./config --prefix=/usr/local/openssl
make
make install
cd ..
cd nginx-1.5.2
./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre=/usr/local/source/pcre-8.32 --with-http_realip_module --with-http_image_filter_module --with-openssl=/usr/local/source/openssl-1.0.0e
make
make install
cd ..
jpeg9 libpng freetype libmcrypt mcrypt -------------------------
3、安装PHP依赖库
mkdir -p /usr/local/jpeg9
cd jpeg-9/
./configure --enable-shared --enable-static --prefix=/usr/local/jpeg9
make
make install
cd ..
安装libpng
cd libpng-1.6.10
./configure --prefix=/usr/local/libpng
make
make install
cd ..
安装freetype
cd freetype-2.4.12/
./configure --prefix=/usr/local/freetype
make
make install
cd ../
安装libmcrypt
cd libmcrypt-2.5.8/
./configure --prefix=/usr/local/libmcrypt --enable-ltdl-install
make
make install
cd ../
cd mhash-0.9.9.9/
./configure --prefix=/usr/local/mhash
make
make install
cd ..
php安装mcrypt
yum -y install libmcrypt mhash php-mcrypt //yum安装
cd mcrypt-2.6.8/
export LD_LIBRARY_PATH=/usr/local/libmcrypt/lib:/usr/local/mhash/lib
export LDFLAGS="-L/usr/local/mhash/lib/ -I/usr/local/mhash/include/"
export CFLAGS="-I/usr/local/mhash/include/"
./configure --prefix=/usr/local/mcrypt --with-libmcrypt-prefix=/usr/local/libmcrypt
make
make install
cd ../
4、编译安装mysql
mysql5.5编译安装步骤
一,安装过程
//创建mysql安装目录,创建数据存放目录,创建用户和用户组与赋予数据存放目录权限
groupadd mysql
useradd -g mysql mysql
mkdir -p /usr/local/mysql
mkdir -p /var/data/mysql
chown mysql:mysql -R /usr/local/mysql
//安装mysql
cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr/local/mysql \
-DMYSQL_DATADIR:PATH=/var/data/mysql \
-DMYSQL_USER=mysql
make
make install
//如果没有出现报错,安装完成
二、mysql安装后的设置和测试;
//复制配置文件
cp support-files/my-default.cnf /etc/my.cnf
//设置mysqld的开机启动
cp support-files/mysql.server /etc/init.d/mysqld 复制到系统
chmod 755 /etc/init.d/mysqld 修改属性
chkconfig --add /etc/init.d/mysqld -------添加为服务
chkconfig mysql on
//初始化数据库 (必须的,很重要)
chmod 755 scripts/mysql_install_db
scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/var/data/mysql
//配置环境 (为了方便,将mysql 的bin目录加到PATH中,在/etc/profile中加入myslq/bin)
export PATH=/usr/local/mysql/bin:$PATH (命令行中直接使用mysql命令)
ln -s /usr/local/mysql/bin/mysql /usr/bin 做个链接即可
//启动mysql服务
/etc/init.d/mysqld start
//查看是否启动
ps -ef |grep mysqld
设置root帐户的密码
mysqladmin -u root password 'archermind'
删除本机匿名连接的空密码帐号
use mysql;
update user set password='archermind' where user = '127.0.0.1'; //给本地账户设置一个密码
delete from user where password=""; //删除空密码
flush privileges; //使设置生效
-------------------------------------------------------------------------------------------------------------------------------------
//安装mysql
下载mysql-5.5.16.tar.gz(已经下载在本地 H:\linux下软件安装包\)
tar zxvf mysql-5.5.16.tar.gz
cd mysql-5.5.16
用cmake进行编译:
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
-----------------------------------------------------------------------------------------------------------------------------
三、实现MySQL远程连接的实际操作流程
mysql –u root –p
use mysql;
select user,password,host from user;
update user set host = '192.168.%' where user = '127.0.0.1'; //设置本地用户可以在任何终端登录
GRANT ALL PRIVILEGES ON *.* TO IDENTIFIED BY 'root密码' WITH GRANT OPTION; //给root远程登录的权限
FLUSH PRIVILEGES; //使设置生效
jpeg9 libpng freetype libmcrypt mcrypt -------------------------
5、编译安装PHP 5.5
tar zxvf php-5.5.1.tar.gz
cd php-5.5.1/
//export LIBS="-lm -ltermcap -lresolv"
//export DYLD_LIBRARY_PATH="/usr/lib/mysql/lib/:/lib/:/usr/lib/:/usr/local/lib:/lib64/:/usr/lib64/:/usr/local/lib64"
//export LD_LIBRARY_PATH="/Data/apps/mysql/lib/:/lib/:/usr/lib/:/usr/local/lib:/lib64/:/usr/lib64/:/usr/local/lib64"
./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=/usr/local/freetype --with-jpeg-dir=/usr/local/jpeg9 --with-png-dir=/usr/local/libpng --with-zlib --with-libxml-dir=/usr --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-fpm --enable-mbstring=all --with-mcrypt=/usr/local/libmcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash=/usr/local/mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --enable-opcache --enable-pdo --with-pdo-mysql --enable-maintainer-zts
---------------------------------------------------------------------------------------------------------------------------------------------------
ln -s /usr/lib64/mysql /usr/lib
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql=/usr --with-mysqli=/usr/bin/mysql_config --with-iconv-dir --with-freetype-dir=/usr/local/freetype --with-jpeg-dir=/usr/local/jpeg9 --with-png-dir=/usr/local/libpng --with-zlib --with-libxml-dir=/usr --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-fpm --enable-mbstring=all --with-mcrypt=/usr/local/libmcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash=/usr/local/mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --enable-opcache --enable-pdo --with-pdo-mysql --enable-maintainer-zts --disable-fileinfo
---------------------------------------------------------------------------------------------------------------------------------------------------
make install
cd ../
#进行PHP配置文件配置
cp php.ini-production /usr/local/php/etc/php.ini
./build/shtool install -e ext/phar/phar.phar /usr/local/php/bin/
ln -s -f /usr/local/php/bin/phar.phar /usr/local/php/bin/phar
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
cd /usr/local/php/etc/
cp php-fpm.conf.default php-fpm.conf
启动php-fpm
/usr/local/php/sbin/php-fpm
/usr/local/php/sbin/php-fpm
pkill php-fpm
启动nginx
/usr/local/nginx/sbin/nginx
/usr/local/nginx/sbin/nginx -s reload
/usr/local/nginx/sbin/nginx -s reopen
测试配置文件是否正确 #./nginx -t
#将nginx添加到自启动中
echo "/usr/local/nginx/sbin/nginx">> /etc/rc.d/rc.local
#将php添加到自启动中
echo "/usr/local/php/sbin/php-fpm start">> /etc/rc.d/rc.local
5、编译安装PHP扩展
wget http://ftp.gnu.org/gnu/autoconf/autoconf-latest.tar.gz
tar zxvf autoconf-latest.tar.gz
cd autoconf-2.69/
./configure --prefix=/Data/apps/libs
make
make install
cd ../
wget http://pecl.php.net/get/memcache-2.2.7.tgz
tar zxvf memcache-2.2.7.tgz
cd memcache-2.2.7/
export PHP_AUTOCONF="/Data/apps/libs/bin/autoconf"
export PHP_AUTOHEADER="/Data/apps/libs/bin/autoheader"
/Data/apps/php/bin/phpize
./configure --with-php-config=/Data/apps/php/bin/php-config
make
make install
cd ../
打开 /Data/apps/php/etc/php.ini 查找 ; extension_dir = "ext"
在其后增加一行:
extension = "memcache.so"
---------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------
?配置讲解
nginx将会连接回环地址9000端口执行PHP文件,需要使用tcp/ip协议,速度比较慢.建议大家换成使用socket方式连接。将fastcgi_pass 127.0.0.1:9000;改成fastcgi_pass unix:/var/run/phpfpm.sock;
---------------------------------------------------------------------------------------------------