centos 编译a安装lnmp
软件包存放目录: /usr/src
卸载原有的httpd mysql php 不会自行百度
安装必备的一些工具
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
安装mysql
创建群组
groupadd mysql
useradd -s /sbin/nologin -g mysql -M mysql
下载cmake
wget http://www.cmake.org/files/v2.8/cmake-2.8.12.2.tar.gz
tar zxvf cmake-2.8.12.2.tar.gz
cd cmake-2.8.12.2
./configure
make && make install
下载mysql 5.6.34
wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.34.tar.gz
tar xf mysql-5.6.34.tar.gz
cmake 与 安装 路径自行指定
cd mysql-5.6.34
cmake \
-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=system
make && make install
修改 /usr/local/mysql 权限
chmod +w /usr/local/mysql
chown -R mysql:mysql /usr/local/mysql
进入support-files 如果有/etc my.cnf 备份 复制my-default.cnf 到/etc 改名为my.cnf
cd support-files/
mv /etc/my.cnf /etc/my.cnf.bk
cp my-default.cnf /etc/my.cnf
/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
service mysqld start
vim /etc/profile
PATH=/usr/local/mysql/bin:$PATH
export PATH
source /etc/profile
进入mysql 无密码
mysql -u root -p
GRANT ALL PRIVILEGES ON *.* TO 'username'@'host' IDENTIFIED BY '你的密码' WITH GRANT OPTION;
安装php 5.5.30
安装libiconv库
wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz
tar zxvf libiconv-1.14.tar.gz
cd libiconv-1.14
./configure --prefix=/usr/local/libiconv
make && make install
cd ..
wget http://mirrors.sohu.com/php/php-5.5.30.tar.gz
tar xf php-5.5.30.tar.gz
cd php-5.5.30
./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 --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-magic-quotes --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --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 --without-pear --with-gettext --disable-fileinfo --enable-maintainer-zts
make && make install
修改fpm配置php-fpm.conf.default的文件名称
mv /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
cp php.ini-production /usr/local/php/etc/php.ini
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
groupadd php
useradd -s /sbin/nologin -g php -M php
service php-fpm start
安装pcre库
wget http://ftp.exim.llorien.org/pcre/pcre2-10.10.tar.gz
tar xf pcre2-10.10.tar.gz
cd pcre2-10.10
./configure
make && make install
wget http://zlib.net/zlib-1.2.8.tar.gz
tar -zxvf zlib-1.2.8.tar.gz
cd zlib-1.2.8
./configure
make && make install
wget http://www.openssl.org/source/openssl-1.0.1g.tar.gz
tar -zxvf openssl-1.0.1g.tar.gz
下载nginx1.8.0
wget http://mirrors.sohu.com/nginx/nginx-1.8.0.tar.gz
tar xf nginx-1.8.0.tar.gz
cd nginx-1.8.0
./configure \
--user=www \
--group=www \
--prefix=/usr/local/nginx \
--with-http_stub_status_module \
--with-http_ssl_module \
--with-http_gzip_static_module \
--with-pcre=/usr/local/src/pcre-8.35 \
--with-zlib=/usr/local/src/zlib-1.2.8 \
--with-openssl=/usr/local/src/openssl-1.0.1g
修改nginx.conf
将下面内容的注释打开
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;
}
启动nginx
phpinfo() 没问题 链接Mysql可能会出现no such file 的情况
在phpinfo()中找到 pdo mysqli mysql三个的socket路径 并进入mysql 执行STATUS 查看UNIX socket的值
进入php.ini 将do mysqli mysql三个的socket路径改成查找出来的UNIX socket的值
重启php-fpm
kill -USR2 `cat /var/run/php-fpm/php-fpm.pid`
重启nginx
/usr/local/nginx/sbin/nginx -s reload
至此centos 下lnmp安装已完成