搭建LNMP服务 CentOS7 php7.1.11 MySQL Nginx

搭建LNMP服务 CentOS7 php7.1.11 MySQL Nginx

双11,阿里云搞活动,三年1核1G ECS 才 720,而我之前买的服务器也要续费了,一年750多,果断迁移服务器
于是重新搭建 LNMP 服务

yum -y install gcc gcc-c++ openssl openssl-devel ncurses ncurses-devel libxml2 libxml2-devel curl curl-devel libjpeg libjpeg-devel libpng libpng-devel

安装 MySQL

首先先安装 CMake

# wget -c https://cmake.org/files/v3.10/cmake-3.10.0-rc4.tar.gz
# tar -zxvf cmake-3.10.0-rc4.tar.gz
# cd cmake_3.10.0-rc4
# ./bootstrap
# make && make install

安装MySQL

# groupadd mysql
# useradd -r -g mysql -s /bin/false mysql


# wget -c https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.20.tar.gz
# tar -zxvf mysql-5.7.20.tar.gz
# cd mysql-5.7.20

# cmake  \
     -DCMAKE_INSTALL_PREFIX=/usr/local/mysql  \
     -DMYSQL_DATADIR=/usr/local/mysql/data \
     -DMYSQL_TCP_PORT=3306 \
     -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.socket \
     -DDEFAULT_CHARSET=utf8 \
     -DDEFAULT_COLLATION=utf8_general_ci  \
     -DWITH_EMBEDDED_SERVER=true  \
     -DWITH_SSL=yes \
     -DWITH_EXTRA_CHARSETS=complex  \
     -DWITH_INNOBASE_STORAGE_ENGINE=1 \
     -DWITH_ARCHIVE_STORAGE_ENGINE=1 \
     -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
     -DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \
     -DWITH_PARTITION_STORAGE_ENGINE=1 \
     -DENABLE_DOWNLOADS=1 \
     -DWITH_BOOST=/usr/local/src/boost_1_59_0 \
     -DDOWNLOAD_BOOST =0

# make
# make install


# 初始化数据
# /usr/local/mysql/bin/mysqld --initialize --user=mysql --defaults-file=/usr/local/mysql/etc/my.cnf
#启动 mysql 服务
# /usr/local/mysql/support-files/mysql.server start
# 修改密码
# /usr/local/mysql/bin/mysqladmin -u root password 'root'

安装 MySQL遇到的问题
问题一:

CMake Error at cmake/boost.cmake:81 (MESSAGE):
  You can download it with -DDOWNLOAD_BOOST=1 -DWITH_BOOST=<directory>
  This CMake script will look for boost in <directory>.  If it is not there,
  it will download and unpack it (in that directory) for you.
  If you are inside a firewall, you may need to use an http proxy:
  export http_proxy=http://example.com:80
Call Stack (most recent call first):
  cmake/boost.cmake:238 (COULD_NOT_FIND_BOOST)
  CMakeLists.txt:491 (INCLUDE)

解决办法 下载 boost

# wget -c https://ncu.dl.sourceforge.net/project/boost/boost/1.59.0/boost_1_59_0.tar.gz
# tar -zxvf boost_1_59_0.tar.gz
解压后目录是 /usr/local/src/boost_1_59_0
编译的时候指定这个目录

问题二:

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)

解决办法

# yum install –y openssl openssl-devel ncurses ncurses-devel

注意如果执行还报错可以执行下面命令后在编译
# rm -rf CMakeCache.txt

问题三

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

解决办法
因为服务为 1G内存,这是服务器内存不足,需要添加 swap 分区

安装PHP

PHP到官网下载

#./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=/usr/local --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-discard-path --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-fastcgi --enable-fpm --enable-force-cgi-redirect --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap

#make
#make install

安装PHP遇到的问题
问题一:

checking libxml2 install dir... /usr
checking for xml2-config path...
configure: error: xml2-config not found. Please check your libxml2 installation.

解决办法

# yum -y install libxml2 libxml2-devel

问题二:

checking for cURL support... yes
checking for cURL in default path... not found
which: no dpkg-architecture in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin)
./configure: line 410: test: please: integer expression expected
configure: error: reinstall
./configure: line 299: return: please: numeric argument required
./configure: line 309: exit: please: numeric argument required

解决办法

# yum -y install curl curl-devel

问题三:

configure: error: jpeglib.h not found.

解决办法

# yum -y install libjpeg libjpeg-devel

问题四:

configure: error: png.h not found.

解决办法

# yum -y install libpng libpng-devel

问题五:

configure: error: freetype-config not found.

解决办法

# yum -y install freetype freetype-devel

问题六:

configure: error: Don't know how to define struct flock on this system, set --enable-opcache=no

解决办法

export LD_LIBRARY_PATH=/usr/local/mysql/lib:/lib/:/usr/lib/:/usr/local/lib:/usr/local/lib64

安装 Nginx

首先安装 pcre

# wget -c https://jaist.dl.sourceforge.net/project/pcre/pcre2/10.30/pcre2-10.30.tar.gz
# tar -zxvf pcre2-10.30.tar.gz
# cd pcre2-10.30
# ./configure
# make
# make install

安装 Nginx

# /usr/sbin/groupadd www
# /usr/sbin/useradd -g www www

# tar -zxvf nginx-1.12.2.tar.gz
# cd nginx-1.12.2
# ./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
# make 
# make install

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注