LNMP 源码编译安装和常见错误整理

Lnmp 即:Linux 、Nginx 、Mysql 、PHP

Lnmp 是一套 Web 环境,Linux 作为底层操作系统,Nginx 提供 web 服务,Mysql 提供数据库服务,PHP 负责解析 PHP 代码。

强烈建议宿主机内存大于、等于 1G ,否则建议还是安装低版本的 Mysql 跟 PHP !!!

一、Nginx

稳定版下载地址:http://nginx.org/download/nginx-1.8.0.tar.gz 

shell > yum -y install gcc gcc-c++ make wget zlib-devel pcre-devel openssl-devel

shell > wget http://nginx.org/download/nginx-1.8.0.tar.gz

shell > tar zxf nginx-1.8.0.tar.gz
shell > cd nginx-1.8.0
shell > ./configure --prefix=/usr/local/nginx ; make ; make install # --prefix
参数指定 Nginx 安装路径

shell > /usr/local/nginx/sbin/nginx # 启动 Nginx
shell > netstat -anpt | grep nginx # 确认是否启动
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 7520/nginx

shell > curl -I http://127.0.0.1 # 访问成功
HTTP/1.1 200 OK
Server: nginx/1.8.0
Date: Fri, 07 Aug 2019 12:08:14 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Fri, 07 Aug 2019 12:04:38 GMT
Connection: keep-alive
ETag: "55c49ed6-264"
Accept-Ranges: bytes

shell > iptables -I INPUT -p tcp --dport 80 -j ACCEPT
shell > service iptables save

 

## 至此 Nginx 就可以外网通过浏览器访问了

二、MySQL安装 

1、安装底层支持包

shell > yum -y install gcc gcc-c++ wget make cmake ncurses-devel bison

2、创建用户、组

shell > useradd -r mysql

3、下载、安装 Mysql
ftp://mirror.switch.ch/mirror/mysql/Downloads/MySQL-5.6/ ## 下载地址

ftp://mirror.switch.ch/mirror/mysql/Downloads/MySQL-5.6/mysql-5.6.25.tar.gz

shell > cd /usr/local/src
shell > tar zxf mysql-5.6.25.tar.gz
shell > cd mysql-5.6.25
shell > cmake .
shell > make ; make install
## Cmake
参数参考地址:http://dev.mysql.com/doc/refman/5.6/en/source-configuration-options.html

-DCMAKE_INSTALL_PREFIX=dir_name        ## Mysql 安装位置( 默认位置 )
-DMYSQL_DATADIR=dir_name                ## Mysql 数据库存放位置
-DMYSQL_TCP_PORT=port                  ## Mysql 监听端口
-DDEFAULT_CHARSET=utf8                  ## Mysql 数据库默认字符集
-DSYSCONFDIR=dir_name                  ## Mysql 配置文件存放位置
-DMYSQL_UNIX_ADDR=/tmp/mysql_v5.sock    ## SOCK 文件存放位置

## 等等... 还有好多,不一一列举了。cmake . 表示使用默认设置,可以看参考地址中的 default 选项

 

shell > cd /usr/local/
shell > chown -R root:mysql mysql/
shell > chown -R mysql mysql/data/

shell > cp mysql/support-files/mysql.server /etc/init.d/mysqld
shell > cp mysql/support-files/my-default.cnf /etc/my.cnf

shell > ./mysql/scripts/mysql_install_db --user=mysql --datadir=/usr/local/mysql/data/ --basedir=/usr/local/mysql/

shell > cd
shell > echo "PATH=$PATH:/usr/local/mysql/bin/" >> /etc/profile
shell > source /etc/profile

 

4、启动 Mysql

shell > service mysqld start

shell > netstat -lnpt | grep 3306
tcp 0 0 :::3306 :::* LISTEN 16206/mysqld

## 可以看到已经启动成功

## 下面这是我上次在阿里云主机上部署 Mysql ,启动时报的错:


Starting MySQL...The server quit without updating PID file [FAILED]cal/mysql/data/Mysql.com.pid).
##
无法启动,日志中报错大致意思为内存不足( 需要大于/等于 1G )~~ 这次没有问题..

## 后来我找了一个 Mysql 5.5 版本中提供的小内存的配置文件,就可以启动了!

5、安装完成,测试

 

shell > mysql  ## 第一次登陆直接输入 mysql 命令即可登陆( 我记得 5.6 默认会有 root 密码的,存放在 root 用户下一个隐藏文件中,这次没有~~ )

shell > mysqladmin -uroot -p password 888888 ## 888888 为设置的新密码,下面直接回车
Enter password:
Warning: Using a password on the command line interface can be insecure. ## 修改密码,输出一个警告信息,提示密码放在命令行不安全~~

shell > mysql -uroot -p888888  ## 再次登陆 Mysql

mysql> update mysql.user set password=password('123456') where user='root';
Query OK, 4 rows affected (0.05 sec)
Rows matched: 4 Changed: 4 Warnings: 0

mysql> flush privileges;
Query OK, 0 rows affected (0.02 sec)


## 第二种修改密码的方式

mysql> grant all on *.* to root@'%' identified by '666'; ## 授权 root 用户可以从任意地址登陆,密码为 666
Query OK, 0 rows affected (0.04 sec)

shell > mysql -uroot -h 192.168.8.10 -p666

## grant 这种操作不需要执行 flush 操作,不过建议还是 flush 一下比较好~~
## 忘记 root 密码时的解决步骤

 

shell > /etc/init.d/mysqld stop

shell > /usr/local/mysql/bin/mysqld_safe --skip-grant-table & ## 跳过授权表启动 Mysql

shell > mysql ## 又可以欢快的无密码登陆数据库了~~

mysql> update mysql.user set password=password('123456') where user='root';

mysql> flush privileges;

Query OK, 0 rows affected (0.04 sec)
  

三、PHP

下载地址:http://cn2.php.net/distributions/php-5.6.11.tar.gz

shell > yum -y install epel-release
shell > yum -y install gd-devel libtool libjpeg-devel libpng-devel freetype-devel libxml2-devel zlib-devel bzip2-devel libcurl-devel libxslt-devel openssl-devel glibc-devel glib2-devel libmcrypt-devel

shell > wget http://cn2.php.net/distributions/php-5.6.11.tar.gz

shell > tar zxf php-5.6.11.tar.gz
shell > cd php-5.6.11
shell > ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php \
--with-mysql=/usr/local/mysql/ --with-mysqli=/usr/local/mysql/bin/mysql_config \
--with-gd --with-xsl --with-bz2 --with-zlib --with-curl --with-pear --without-iconv --with-mcrypt \
--with-gettext --with-openssl --with-libxml-dir --with-png-dir --with-jpeg-dir --with-freetype-dir \
--with-libdir=lib64 --enable-ftp --enable-fpm --enable-exif --enable-soap --enable-bcmath --enable-calendar \
--enable-sockets --enable-mbstring --enable-gd-native-ttf --disable-rpath --disable-debug

 

# 这堆参数怎么说呢: 你也不必太在意,能解决大多数需求,有几个需要解释一下
# --prefix= 指定安装路径
# --with-config-file-path 指定 php.ini 存放位置
# --with-mysql 指定 Mysql 安装路径
# --enable-fpm Nginx 连接 php 全靠这个东西,如果没有它,你的 Nginx 就不能解析 php

 

shell > make ; make install

shell > cp /usr/local/src/php-5.6.11/php.ini-production /usr/local/php/php.ini

shell > cp /usr/local/src/php-5.6.11/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
shell > chmod a+x /etc/init.d/php-fpm

shell > cat /usr/local/php/etc/php-fpm.conf.default > /usr/local/php/etc/php-fpm.conf

shell > chkconfig --add php-fpm # 加入开机启动
shell > chkconfig --level 35 php-fpm on

shell > service php-fpm start # 启动 php-fpm
shell > netstat -anpt | grep php-fpm
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 71992/php-fpm

四、让 Nginx 支持 PHP

shell > vim /usr/local/nginx/conf/nginx.conf # 修改配置文件,使其可以解析 PHP

server {
listen 80;
server_name localhost;

location / {
root html;
index index.php index.html index.htm; #
加入 index.php
}

error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}

location ~ \.php$ { # 整段注释去掉
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name; # 修改为自己的根目录
include fastcgi_params;
}
}

# 当然,这只是让 Nginx 支持 PHP 而已,实际工作中可以还有更多的配置

## 创建测试页面 ( echo "<?php phpinfo(); ?>" > /usr/local/nginx/html/info.php ) , 重启 Nginx 、php-fpm 放问测试!( 好久前测试记得需要 iptables -I INPUT -i io -j ACCEPT )

五、报错汇总:( 记录一些常见的错误及解决方法 )

1、没有安装 gcc 导致报错 ( yum -y install gcc )

checking for OS
+ Linux 2.6.32-504.el6.x86_64 x86_64
checking for C compiler ... not found

./configure: error: C compiler cc is not found

2、没有安装 pcre-devel 导致报错 ( yum -y install pcre-devel )

./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=<path> option.

3、没有安装 zlib-devel 导致报错 ( yum -y install zlib-devel )

./configure: error: the HTTP gzip module requires the zlib library.
You can either disable the module by using --without-http_gzip_module
option, or install the zlib library into the system, or build the zlib library
statically from the source with nginx by using --with-zlib=<path> option.

# 上面是关于 Nginx 的报错

4、没有安装 gcc-c++ 导致报错 ( yum -y install 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.

# 上面是关于 Mysql 的报错

5、没有安装 libxml2-devel 导致报错 ( yum -y install libxml2-devel )

configure: error: xml2-config not found. Please check your libxml2 installation.

6、没有安装 bzip2-devel 导致报错 ( yum -y install bzip2-devel )

configure: error: Please reinstall the BZip2 distribution

7、没有安装 libcurl-devel 导致报错 ( yum -y install libcurl-devel )

configure: error: Please reinstall the libcurl distribution -
easy.h should be in <curl-dir>/include/curl/

8、没有安装 libjpeg-devel 导致报错 ( yum -y install libjpeg-devel )

configure: error: jpeglib.h not found.

9、没有安装 libpng-devel 导致报错 ( yum -y install libpng-devel )

configure: error: png.h not found.

10、没有安装 freetype-devel 导致报错 ( yum -y install freetype-devel )

configure: error: freetype-config not found.

11、没有安装 libmcrypt-devel 导致报错 ( yum -y install epel-release ; yum -y install libmcrypt-devel )

configure: error: mcrypt.h not found. Please reinstall libmcrypt.

12、找不到 libmysqlclient.so.18 导致报错 ( ln -s /usr/local/mysql/lib /usr/local/mysql/lib64 )

configure: error: Cannot find libmysqlclient under /usr/local/mysql/.
Note that the MySQL client library is not bundled anymore!

13、跟上一个错误有连带性,我猜的 ( ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib64/ )

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

14、没有安装 libxslt-devel 导致报错 ( yum -y install libxslt-devel )

configure: error: xslt-config not found. Please reinstall the libxslt >= 1.1.0 distribution

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

深海天哥

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值