Centos7 下安装新的LNMP 开发环境

sanlanlan 2018-9-12 标签: 浏览:397 评论:0

1、检查并安装组件,这是公用需要的(不装会报错,根据到时候报错来安装也行)


yum -y install gcc automake autoconf libtool make gcc-c++ glibc


2、安装库 (不要全部装,有需要的再装)
yum -y install libxslt-devel \
libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel \
glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel \
ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel \
krb5-devel libidn libidn-devel

3、安装libmcrypt (用yum安装)

4、安装PHP

下载地址:
http://cn2.php.net/get/php-7.2.6.tar.gz/from/this/mirror
 
http://www.php.net/releases/

http://php.net/downloads.php

源码包地址:
http://cn2.php.net/distributions/php-7.2.6.tar.gz


//下载包,解压,切换到目录(根据报错信息修改):

./configure --prefix=/usr/local/php  --enable-fpm --with-mcrypt=/usr/local/libmcrypt --with-redis=/usr/local/redis\
--enable-mbstring --with-curl --disable-debug  --disable-rpath \
--enable-inline-optimization --with-bz2  --with-zlib --enable-sockets \
--enable-sysvsem --enable-sysvshm --enable-pcntl --enable-mbregex \
--with-mhash --enable-zip --with-pcre-regex --with-mysql --with-mysqli --with-pdo-mysql \
--with-gd --with-jpeg-dir --with-freetype-dir --with-openssl --with-pear 


//然后
make && make install

配置php-fpm
cd /usr/local/php/etc
cp php-fpm.conf.default php-fpm.conf


//php7 版本新加了 www.conf 这个文件,对  php-fpm.conf 的扩展补充,
/usr/local/php/etc/php-fpm.d
cp www.conf.default www.conf


//php 启动
php-fpm -D
killall php-fpm



5、安装Nginx
(注意对应版本)
http://netix.dl.sourceforge.net/project/pcre/pcre/8.38/pcre-8.38.tar.gz
https://www.openssl.org/source/openssl-1.0.2h.tar.gz
http://zlib.net/zlib-1.2.8.tar.gz

下载并解压pcre-8.37.tar.gz:
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.37.tar.gz
tar zxvf pcre-8.37.tar.gz

下载并解压zlib-1.2.8.tar.gz:
wget http://zlib.net/zlib-1.2.8.tar.gz
tar zxvf zlib-1.2.8.tar.gz

下载并解压openssl-1.0.2d.tar.gz:
wget http://www.openssl.org/source/openssl-1.0.2d.tar.gz
tar zxvf openssl-1.0.2d.tar.gz

下载并解压nginx-1.8.0.tar.gz:
wget http://nginx.org/download/nginx-1.8.0.tar.gz
tar zxvf nginx-1.8.0.tar.gz


http://nginx.org/download/nginx-1.15.3.tar.gz
http://www.openssl.org/source/openssl-1.0.2d.tar.gz

./configure --prefix=/usr/local/nginx \
--with-http_ssl_module \
--with-pcre=/root/soft/pcre-8.42 \
--with-zlib=/root/soft/zlib-1.2.11 \
--with-openssl=/root/soft/openssl-1.0.2h


//然后
make && make install


//nginx 启动
nginx -s reload|reopen|stop|quit


//error
[root@xx ~]# nginx -s reload
nginx: [emerg] open() "/usr/local/nginx/-help" failed (2: No such file or directory)


//两个错误是一样的,都是因为nginx.pid 文件

/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf //使用nginx -c的参数指定nginx.conf文件的位置




6、安装MySQL(用cmake编译安装)

https://downloads.mysql.com/archives/community/
http://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.25.tar.gz
http://cdn.mysql.com/archives/mysql-5.6/mysql-5.6.25.tar.gz
https://dev.mysql.com/doc/refman/5.7/en/installing.html

先安装cmake:
yum -y install cmake
添加名为「mysql」的用户和组:
groupadd mysql
useradd -r -g mysql mysql

【下载包,解压,切到对应目录】

//=========================== begin new
cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DMYSQL_TCP_PORT=3306 \
-DMYSQL_UNIX_ADDR=/usr/local/mysql/run/mysql.sock \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_BOOST=/usr/local/boost \
-DENABLE_DOWNLOADS=1 \  //必须 寻找依赖(copy 的时候,注意这边的空格)
-DWITH_SSL=bundled //必须 解决ssl 问题




cmake 完了之后,记得
make && make install 这个才是安装

==================
https://blog.csdn.net/qq_23033339/article/details/80872136
make 安装完之后
1.cd /usr/local/mysql/  //进到目录

2. chown -R mysql:mysql /usr/local/mysql   //设置权限
添加配置文件

vi /etc/my.cnf

初始化mysql

/usr/local/mysql/bin/mysqld \
--initialize-insecure \
--user=mysql \
--basedir=/usr/local/mysql \
--datadir=/usr/local/mysql/data

--pid-file=/usr/local/mysql/run/mysql.pid 

一些有的参数可以不用加
/usr/local/mysql/bin/mysqld --initialize-insecure 

3.启动mysql
mysqld_safe --defaults-file=/etc/my.cnf &

4. /usr/local/mysql/bin/mysql mysql -uroot   //进入数据库 ,去修改密码

5.
5.7.25 没有 password 字段,用 authentication_string 代替了,使用还是和  password 一样


ps -ef | grep mysql


//mysql.user table
update user set authentication_string =password('123456') where user ='root';


//刷一下权限 
flush privileges;




安装mysql 过程中 出现的一些报错,解决方案参考网上:

5.7.25 版本的坑

1.cmake 安装mysql 报错说明缺少编译所需要的环境:gcc gcc-c++

CMake Error: your CXX compiler: "CMAKE_CXX_COMPILER-NOTFOUND" was not found.   Please set CMAKE_CXX_COMPILER to a valid compiler path or name.


2.boost 库
5.7 版本需要这个boost 库,所以需要先安装这个库

CMake Error at cmake/boost.cmake:81 (MESSAGE):   You can download it with -DDOWNLOAD_BOOST=1 -DWITH_BOOST=<directory>

1.在/usr/local下创建一个名为boost的文件夹
    mkdir -p /usr/local/boost
2.进入这个新创建的文件夹然后下载boost
    wget http://www.sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz
3.解压
    tar -xvzf boost_1_59_0.tar.gz
4.配上参数
cmake \
-DWITH_BOOST=/usr/local/boost \  


3. yum install openssl-devel openssl
//如果还是会报错,应该是安装了openssl  但却加载不上去
//一种方式:-DWITH_SSL=bundled 使用了这种    https://jira.mariadb.org/browse/MDEV-16014
//另一种 找到openssl 路径 加上参数
//-DOPENSSL_ROOT_DIR=/usr/local/opt/openssl \
//-DOPENSSL_LIBRARIES=/usr/local/opt/openssl/lib


CMake Error at cmake/ssl.cmake:247 (MESSAGE):
  Cannot find appropriate system libraries for SSL.  Make sure you've
  specified a supported SSL version.  Consult the documentation for WITH_SSL
  alternatives
Call Stack (most recent call first):
  CMakeLists.txt:517 (MYSQL_CHECK_SSL)



4.删除CMakeCache.txt
通过find命令找到所有CMakeCache.txt文档的位置
#find / -name CMakeCache.txt


CMake Error at cmake/readline.cmake:64 (MESSAGE):
  Curses library not found.  Please install appropriate package,

      remove CMakeCache.txt and rerun cmake.On Debian/Ubuntu, package name is libncurses5-dev, on Redhat and derivates it is ncurses-devel.
Call Stack (most recent call first):
  cmake/readline.cmake:107 (FIND_CURSES)
  cmake/readline.cmake:197 (MYSQL_USE_BUNDLED_EDITLINE)
  CMakeLists.txt:519 (MYSQL_CHECK_EDITLINE)




5. yum -y install bison

CMake Warning at cmake/bison.cmake:20 (MESSAGE):
  Bison executable not found in PATH
Call Stack (most recent call first):
  libmysqld/CMakeLists.txt:187 (INCLUDE)


ps:

cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DMYSQL_TCP_PORT=3306 \
-DMYSQL_UNIX_ADDR=/usr/local/mysql/run/mysql.sock \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_BOOST=/usr/local/boost \
-DENABLE_DOWNLOADS=1 \
-DWITH_SSL=bundled


//-DENABLE_DOWNLOADS=1 to automatically download and build required components from source.

camke 执行完之后, 执行make && make install

、、、、、、、、、、、、、、、、、、、、、
6.执行make && make install 时报错

[ 29%] Building CXX object sql/CMakeFiles/sql.dir/item_geofunc.cc.o
c++: internal compiler error: Killed (program cc1plus)
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://bugzilla.redhat.com/bugzilla> for instructions.
make[2]: *** [sql/CMakeFiles/sql.dir/item_geofunc.cc.o] Error 4
make[1]: *** [sql/CMakeFiles/sql.dir/all] Error 2
make: *** [all] Error 2


原因:内存不足

ps:出错后重新运行配置,可以删除CMakeCache.txt文件 (看需要执行)
$ make clean 
$ rm -f CMakeCache.txt 

创建2G的交换分区

$dd if=/dev/zero of=/swapfile bs=1k count=2048000 --获取要增加的2G的SWAP文件块

$mkswap /swapfile     -- 创建SWAP文件

$swapon /swapfile     -- 激活SWAP文件

$swapon -s            -- 查看SWAP信息是否正确


编译完后, 如果不想要交换分区了, 可以删除:

$swapoff /swapfile

$rm -fr /swapfile

===================  无法下载 boost_1_59_0 包 带来问题,和解决方法



安装 mysql 报如下的错误:


-- MySQL 5.7.24
-- Packaging as: mysql-5.7.24-osx10.14-x86_64
-- Downloading boost_1_59_0.tar.gz to /usr/local/Cellar/boost@1.59
-- Download failed, error: 7;"Couldn't connect to server"
CMake Error at cmake/boost.cmake:194 (MESSAGE):
  You can try downloading
  http://sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz
  manually using curl/wget or a similar tool
Call Stack (most recent call first):
  CMakeLists.txt:507 (INCLUDE)


-- Configuring incomplete, errors occurred!
See also "/usr/local/testMysql/mysql-5.7.24/CMakeFiles/CMakeOutput.log".


是因为 没有下载boost ,可能因为墙的关系,"Couldn't connect to server",导致卡在这边

解决办法自己新建一个目录来安放boost。然后自己手动下载包,放进去(必须要1.59 版本,因为cmake 写死了版本,不要解压)

boost.cmake 文件写死了,wget boost 的连接地址,可以自己试着替换另一个不用墙的地址,
但是因为版本问题,还是需要手动下载,然后放进去。(具体自己进去看源码)
SET(BOOST_DOWNLOAD_URL
#  "http://sourceforge.net/projects/boost/files/boost/1.59.0/${BOOST_TARBALL}"
   https://dl.bintray.com/boostorg/release/1.68.0/source/boost_1_68_0.tar.gz
 )


 自己解决步骤:
 1. 修改 boost.cmake 文件的BOOST_DOWNLOAD_URL(可以不需要这个步骤,可以自己进去看这个文件的源码)
 SET(BOOST_DOWNLOAD_URL
#  "http://sourceforge.net/projects/boost/files/boost/1.59.0/${BOOST_TARBALL}"
   https://dl.bintray.com/boostorg/release/1.68.0/source/boost_1_68_0.tar.gz
 )
 2.自己手动建立一个空目录,用来放boost.
 mkdir -p /usr/local/boost

 3.把手动下载好的 boost_1_59_0.tar.gz copy 进去 /usr/local/boost, 不解压,不换文件名

 4.mysql camke 时候,参数加上
 -DWITH_BOOST=/usr/local/boost \

 ps:如有报错,重新 camke 的时候,记得删除 CMakeCache.txt 文件


===================


ps:
cmake 完了之后,记得
make && make install 这个才是安装


安装PHP 扩展的话,进去源码包(即下载下来的php包)的目录,找到,ext 目录,去安装对应扩展。



启动:mysql 

1.bin/mysqld_safe 启动报 没有 /var/log/mariadb/mariadb.log for user= mysql  需要新加

$ mkdir /var/log/mariadb
$ touch /var/log/mariadb/mariadb.log
$ chown -R mysql:mysql /var/log/mariadb

2./usr/local/mysql/support-files/mysql.server start 可以用这种方式启动


连接:
Can't connect to local MySQL server through socket '/usr/local/mysql/run/mysql.sock' (2)


 ps aux | grep mysql 看到
--socket=/var/lib/mysql/mysql.sock

修改/etc/my.cnf

[mysqld]
datadir=/var/lib/mysql
#socket=/var/lib/mysql/mysql.sock
socket=/var/lib/mysql/mysql.sock

重启MySQL 服务



//启动 mysql 报错
mysql 5.7 The server quit without updating PID file [faild] 

//修改 my.cnf 的pid 文件配置,放到 mysql 目录下。


部分参考:http://blog.51cto.com/xiao987334176/1783509

本文相关标签: php mysql nginx

发表评论: