LNMP 这种架构因此也就非常流行,尤其VPS和云主机的出现,更加推动了,LNMP 的架构发展融合,从php5.4开始就已经原生的支持了php-fpm的方式。PHP-FPM是一个PHP FastCGI管理器,不再是第三方的包了, PHP-FPM 提供了更好的PHP进程管理方式,可以有效控制内存和进程、可以平滑重载PHP配置,比spawn-fcgi具有更多优点。
之前一直用,很方便 ,全程自动安装。今天也试试自己搭建
准备工作:
最小化安装centos6.5
建立一个软件包目录存放
mkdir -p /usr/local/src/
清理已经安装包
rpm -e httpdrpm -e mysqlrpm -e phpyum -y remove httpdyum -y remove mysqlyum -y remove php
#搜索apache包
rpm -qa http*#强制卸载apache包
rpm -e –nodeps 查询出来的文件名#检查是否卸载干净
rpm -qa|grep http*selinux可能会致使编译安装失败,我们先禁用它。永久禁用,需要重启生效
安装必备工具
yum -y install make gcc gcc-c++ gcc-g77 flex bison file libtool libtool-libs autoconf kernel-devel libjpeg libjpeg-devel libpng libpng-devel libpng10 libpng10-devel gd gd-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glib2 glib2-devel bzip2 bzip2-devel libevent libevent-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel gettext gettext-devel ncurses-devel gmp-devel pspell-devel unzip libcap lsof
安装mysql5.6.23
按照标准需要给mysql创建所属用户和用户组
创建群组groupadd mysql创建一个用户,不允许登陆和不创主目录useradd -s /sbin/nologin -g mysql -M mysql检查创建用户tail -1 /etc/passwd
centos最小化安装后,会有mysql的库因此先卸载!
检查安装与否 rpm -qa|grep mysql 强制卸载 rpm -e mysql-libs-5.1.73-3.el6_5.x86_64 –nodepsMySQL从5.5版本开始,通过./configure进行编译配置方式已经被取消,取而代之的是cmake工具。 因此,我们首先要在系统中源码编译安装cmake工具。
wget http://www.cmake.org/files/v2.8/cmake-2.8.12.2.tar.gztar zxvf cmake-2.8.12.2.tar.gzcd cmake-2.8.12.2./configuremake && make install
tar zxvf mysql-5.6.23.tar.gzcd mysql-5.6.23cmake \-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \-DMYSQL_DATADIR=/usr/local/mysql/data \-DSYSCONFDIR=/etc \-DWITH_MYISAM_STORAGE_ENGINE=1 \-DWITH_INNOBASE_STORAGE_ENGINE=1 \-DWITH_MEMORY_STORAGE_ENGINE=1 \-DWITH_READLINE=1 \-DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock \-DMYSQL_TCP_PORT=3306 \-DENABLED_LOCAL_INFILE=1 \-DWITH_PARTITION_STORAGE_ENGINE=1 \-DEXTRA_CHARSETS=all \-DDEFAULT_CHARSET=utf8 \-DDEFAULT_COLLATION=utf8_general_ci \-DMYSQL_USER=mysql \-DWITH_DEBUG=0 \-DWITH_SSL=systemmake && make install
修改/usr/local/mysql权限
chmod +w /usr/local/mysqlchown -R mysql:mysql /usr/local/mysql
编辑/etc/my.cnf
关于my.cnf配置文件:
在启动MySQL服务时,会按照一定次序搜索my.cnf,先在/etc目录下找,找不到则会搜索”$basedir/my.cnf” 就是安装目录下 /usr/local/mysql/my.cnf,这是新版MySQL的配置文件的默认位置! 注意:在CentOS 6.x版操作系统的最小安装完成后,在/etc目录下会存在一个my.cnf,需要将此文件更名为其他的名字。 如:/etc/my.cnf.bak,否则,该文件会干扰源码安装的MySQL的正确配置,造成无法启动。 由于我们已经卸载了最小安装完成后的mysq库所以,就没必要操作了。
进入support-files目录
cd support-files/如果还有my.cnf请备份mv /etc/my.cnf /etc/my.cnf.bak如果愿意也可以复制配置文件到etc下cp my-default.cnf /etc/my.cnf
这里我配置文件进行修改 使用lnmp.org的lnmp安装包1.2的mysql配置
修改my.cnf
# Example MySQL config file for medium systems.## This is for a system with little memory (32M - 64M) where MySQL plays# an important part, or systems up to 128M where MySQL is used together with# other programs (such as a web server)## MySQL programs look for option files in a set of# locations which depend on the deployment platform.# You can copy this option file to one of those# locations. For information about these locations, see:# http://dev.mysql.com/doc/mysql/en/option-files.html## In this file, you can use all long options that a program supports.# If you want to know which options a program supports, run the program# with the "--help" option.# The following options will be passed to all MySQL clients[client]#password = your_passwordport = 3306socket = /tmp/mysql.sock# Here follows entries for some specific programs# The MySQL server[mysqld]port = 3306socket = /tmp/mysql.sockskip-external-lockingkey_buffer_size = 16Mmax_allowed_packet = 1Mtable_open_cache = 64sort_buffer_size = 512Knet_buffer_length = 8Kread_buffer_size = 256Kread_rnd_buffer_size = 512Kmyisam_sort_buffer_size = 8M# Don't listen on a TCP/IP port at all. This can be a security enhancement,# if all processes that need to connect to mysqld run on the same host.# All interaction with mysqld must be made via Unix sockets or named pipes.# Note that using this option without enabling named pipes on Windows# (via the "enable-named-pipe" option) will render mysqld useless!##skip-networking# Replication Master Server (default)# binary logging is required for replicationlog-bin=mysql-bin# binary logging format - mixed recommendedbinlog_format=mixed# required unique id between 1 and 2^32 - 1# defaults to 1 if master-host is not set# but will not function as a master if omittedserver-id = 1#loose-innodb-trx=0#loose-innodb-locks=0#loose-innodb-lock-waits=0#loose-innodb-cmp=0#loose-innodb-cmp-per-index=0#loose-innodb-cmp-per-index-reset=0#loose-innodb-cmp-reset=0#loose-innodb-cmpmem=0#loose-innodb-cmpmem-reset=0#loose-innodb-buffer-page=0#loose-innodb-buffer-page-lru=0#loose-innodb-buffer-pool-stats=0#loose-innodb-metrics=0#loose-innodb-ft-default-stopword=0#loose-innodb-ft-inserted=0#loose-innodb-ft-deleted=0#loose-innodb-ft-being-deleted=0#loose-innodb-ft-config=0#loose-innodb-ft-index-cache=0#loose-innodb-ft-index-table=0#loose-innodb-sys-tables=0#loose-innodb-sys-tablestats=0#loose-innodb-sys-indexes=0#loose-innodb-sys-columns=0#loose-innodb-sys-fields=0#loose-innodb-sys-foreign=0#loose-innodb-sys-foreign-cols=0# Uncomment the following if you are using InnoDB tables#innodb_data_home_dir = /usr/local/mysql/data#innodb_data_file_path = ibdata1:10M:autoextend#innodb_log_group_home_dir = /usr/local/mysql/data# You can set .._buffer_pool_size up to 50 - 80 %# of RAM but beware of setting memory usage too high#innodb_buffer_pool_size = 16M#innodb_additional_mem_pool_size = 2M# Set .._log_file_size to 25 % of buffer pool size#innodb_log_file_size = 5M#innodb_log_buffer_size = 8M#innodb_flush_log_at_trx_commit = 1#innodb_lock_wait_timeout = 50[mysqldump]quickmax_allowed_packet = 16M[mysql]no-auto-rehash# Remove the next comment character if you are not familiar with SQL#safe-updates[myisamchk]key_buffer_size = 20Msort_buffer_size = 20Mread_buffer = 2Mwrite_buffer = 2M[mysqlhotcopy]interactive-timeout
执行初始化配置脚本,创建系统自带的数据库和表,注意配置文件的路径
/usr/local/mysql/scripts/mysql_install_db --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql
拷贝mysql安装目录下support-files服务脚本到init.d目录
#拷贝脚本cp support-files/mysql.server /etc/init.d/mysqld#赋予权限chmod +x /etc/init.d/mysqld
设置开机启动
chkconfig mysqld on启动MySQLservice mysqld start或者/etc/init.d/mysql start
登陆测试,默认是没有密码,直接回车就可进入
mysql -uroot -p
设置mysql密码
/usr/local/mysql/bin/mysqladmin -uroot -p password '你的密码'
登陆进命令行模式
mysql -uroot -p
查看用户
select user,host from mysql.user;
删除不必要的用户
drop user ""@localhost;drop user ""@localhost.localdomain;drop user root@localhost.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'@'localhost.localdomain' IDENTIFIED BY '你的密码' WITH GRANT OPTION;
安装php5.6
wget http://cn2.php.net/distributions/php-5.6.17.tar.gztar zxvf php-5.6.17.tar.gz
安装依赖关系
libiconv库为需要做转换的应用提供了一个iconv()的函数,以实现一个字符编码到另一个字符编码的转换。 错误提示:configure: error: Please reinstall the iconv library.
wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gztar zxvf libiconv-1.14.tar.gzcd libiconv-1.14./configure --prefix=/usr/local/libiconvmake && make installcd ..
libmcrypt是加密算法扩展库。 错误提示:configure: error: Cannot find imap library (libc-client.a). Please check your c-client installation.
wget http://iweb.dl.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gztar zxvf libmcrypt-2.5.8.tar.gzcd libmcrypt-2.5.8./configuremake && make installcd ..
Mhash是基于离散数学原理的不可逆向的php加密方式扩展库,其在默认情况下不开启。 mhash的可以用于创建校验数值,消息摘要,消息认证码,以及无需原文的关键信息保存 错误提示:configure: error: “You need at least libmhash 0.8.15 to compile this program. http://mhash.sf.net/”
wget http://hivelocity.dl.sourceforge.net/project/mhash/mhash/0.9.9.9/mhash-0.9.9.9.tar.bz2tar jxvf mhash-0.9.9.9.tar.bz2cd mhash-0.9.9.9./configuremake && make installcd ..
mcrypt 是 php 里面重要的加密支持扩展库,Mcrypt扩展库可以实现加密解密功能,就是既能将明文加密,也可以密文还原。
wget http://iweb.dl.sourceforge.net/project/mcrypt/MCrypt/2.6.8/mcrypt-2.6.8.tar.gztar zxvf mcrypt-2.6.8.tar.gzcd mcrypt-2.6.8./configuremake && make installcd ..
编译mcrypt可能会报错:configure: error: *** libmcrypt was not found
vi /etc/ld.so.conf最后一行添加/usr/local/lib/载入ldconfig
编译mcrypt可能会报错:/bin/rm: cannot remove `libtoolT’: No such file or directory
修改 configure 文件,把RM='$RM'改为RM='$RM -f' 这里的$RM后面一定有一个空格。 如果后面没有空格,直接连接减号,就依然会报错。
正式开始编译php!
tar zxvf php-5.6.17.tar.gzcd php-5.6.17 ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-iconv-dir=/usr/local/ --with-freetype-dir=/usr/local/freetype --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 --enable-mbregex --enable-mbstring --with-mcrypt --enable-ftp --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --with-gettext --disable-fileinfo make && make install
修改fpm配置php-fpm.conf.default文件名称
mv /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
复制php.ini配置文件
cp php.ini-production /usr/local/php/etc/php.ini
复制php-fpm启动脚本到init.d
cp 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-fpm创建一个指定的用户和组
创建群组groupadd www创建一个用户,不允许登陆和不创主目录 useradd -s /sbin/nologin -g www -M www
立即启动php-fpm
service php-fpm start#或者/etc/init.d/php-fpm start
回到/usr/local/src/目录
安装nginx1.7
nginx所需的依赖关系,一般我们都需要先装pcre, zlib,前者为了重写rewrite,后者为了gzip压缩。如果系统已经yum 安装了这些库也没关系,无需卸载。直接编译安装最新的就可以了。为了一次性完成编译,先准备编译下面的依赖关系!
1.安装PCRE库
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.35.tar.gz tar -zxvf pcre-8.35.tar.gzcd pcre-8.35./configuremake && make install
2.安装zlib库
wget http://zlib.net/zlib-1.2.8.tar.gztar -zxvf zlib-1.2.8.tar.gzcd zlib-1.2.8./configuremake && make install
3.安装ssl
自由选择是否需要编译wget http://www.openssl.org/source/openssl-1.0.1g.tar.gztar -zxvf openssl-1.0.1g.tar.gz
准备工作完成,现在开始安装nginx!,这里添加了前面准备的库关系,注意路径!
wget http://nginx.org/download/nginx-1.7.0.tar.gztar zxvf nginx-1.7.0.tar.gzcd nginx-1.7.0./configure \--user=www \--group=www \--prefix=/usr/local/nginx \--with-http_stub_status_module \--with-http_ssl_module \--with-http_gzip_static_module \cd ..
简单配置nginx
user www www;worker_processes 1;#error_log logs/error.log;#error_log logs/error.log notice;#error_log logs/error.log info;#pid logs/nginx.pid;events { worker_connections 1024;}http { include mime.types; default_type application/octet-stream; #log_format main '$remote_addr - $remote_user [$time_local] "$request" ' # '$status $body_bytes_sent "$http_referer" ' # '"$http_user_agent" "$http_x_forwarded_for"'; #access_log logs/access.log main; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on; server { listen 80; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / { root /data/app/test; index index.php index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } location ~ \.php$ { root /data/app/test; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } } include vhost/*.conf;
vi /data/app/test/index.php<?php phpinfo();保存退出
nginx -s reload
访问localhost/index.php访问