Nginx 特性
4、反向代理可以根据url将请求转向于不同用途的集群,比如图片请求,转向图片服务器集群;视频请求,转身视频服务器集群。
nginx是一款轻量级的web服务器/反向代理服务器/电子邮件代理服务器,安装非常简单,配置文件也很简洁(还支持 perl 语法)。Nginx 支持平滑加载新配置,还能够在不间断服务的情况下进行软件版本升级。
nginx优点:
- 轻量级服务器,相比较apache占用的资源更加少。
- 高并发。
- 配置文件的语法等简单易懂
- 社区活跃。
- 支持epoll模型。使得nginx可以支持高并发。
- 利用nginx可以对ip限速,可以限制连接数
大纲:
- 安装nginx
- 启动nginx
- 配置虚拟主机
- 安装mysql二进制版
- 安装php
- 测试lnmp环境
nginx
1、安装nginx
wget http:
//nginx
.org
/download/nginx-1
.12.0.
tar
.gz
tar
zxvf nginx-1.12.0.
tar
.gz
cd
nginx-1.12.0/
yum
install
gcc gcc-c++ zilb.x86_64 zlib-devel.x86_64 pcre-devel.x86_64 pcre.x86_64
openssl.x86_64 openssl-devel.x86_64-y(一行)
useradd
-M -s
/sbin/nologin
nginx
.
/configure
--help
.
/configure
--prefix=
/application/nginx1
.12.0 --user=nginx --group=nginx --with-pcre
--with-http_ssl_module --with-http_stub_status_module(一行)
.
/configure
--prefix=
/usr/local/nginx
--user=nginx --group=nginx --with-pcre
--with-http_ssl_module --with-http_stub_status_moduleecho
$?
make
echo
$?
make
install
echo
$?
ln
-s
/application/nginx1
.12.0/
/application/nginx #nginx的安装目录
cd
/application/nginx
nginx目录结构 | |
conf | 配置文件 |
html | 默认站点 |
logs | 日志文件 |
sbin | 命令 |
总结:
1 选择软件一定不能选择最新的,否则出问题不容易解决,因为第一个吃螃蟹。
2 一定要自己创建用户,否则nginx会给默认用户。
3 编译的参数根据自己的实际情况出发。
4 编译、make、make install要养成echo $?的习惯防止出错。
5 做一个软链接优化路径。
2、启动nginx
/application/nginx/sbin/nginx
-t
/application/nginx/sbin/nginx
lsof
-i :80
curl localhost
总结:
- nginx的检查语法操作是一样的,只是命令名字换了
- nginx启动后面不需要任何参数
- 本地做个访问测试如果能成功则说明网站已经在工作了,在如果外网访问不进来就是其他问题了,比如防火墙iptables、selinux等的问题
3、配置虚拟主机
如果熟悉了Apache的虚拟主机那么Nginx的虚拟主机也很容易理解,而且配置还比Apache简单很多。
虚拟主机:
- 基于域名的虚拟主机
- 基于IP的虚拟主机
- 基于端口的虚拟主机
mkdir
/application/nginx/conf/extra
-p
##把我们的虚拟主机文件放在这个扩展目录中,可以在管理网站的时候更加方便
vim
/application/nginx/conf/nginx
.conf
##将主配置文件修改为以下内容
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application
/octet-stream
;
sendfile on;
keepalive_timeout 65;
include extra
/blog
.conf;
include extra
/easy
.conf;
include extra
/bad
.conf;
}
vim
/application/nginx/conf/extra/blog
.conf
##将虚拟主机blog配置文件配置为以下内容,不存在则创建
server {
listen 80;
server_name www.blog.linuxidc.com;
location / {
root html
/blog
;
index index.html index.htm;
}
}
vim
/application/nginx/conf/extra/easy
.conf
##将虚拟主机easy配置为以下内容,不存在则创建
server {
listen 80;
server_name www.easy.linuxidc.com;
location / {
root html
/easy
;
index index.html index.htm;
}
}
vim
/application/nginx/conf/extra/bad
.conf
##将虚拟主机bad配置文件修改为以下内容,不存在则创建
server {
listen 80;
server_name www.bad.linuxidc.com;
location / {
root html
/bad
;
index index.html index.htm;
}
}
cd
/application/nginx/html/
for
name
in
blog bad easy;
do
mkdir
$name;
echo
"$name.linuxidc.com"
>
$name
/index
.html;
done
##利用for循环创建目录,并向index.html中写入内容
tree ./
bad
│ └── index.html
├── blog
│ └── index.html
├── easy
│ └── index.html
vim
/etc/hosts
127.0.0.1 localhost www.blog.linuxidc.com www.easy.linuxidc.com www.bad.linuxidc.com
##修改本地hosts文件,为了配合我们的基于域名的虚拟主机
/application/nginx/sbin/nginx
-s reload
##重启nginx服务器
curl www.
blog.linuxidc.com
curl www.
bad.linuxidc.com
curl www.
easy.linuxidc.com
提示:使用curl访问域名时返回如上信息即基于域名的虚拟主机搭建成功。
扩展:
* 域名重定向
- 为什么需要域名重定向,第一是为了防止恶意绑定,最简单的道理就是,域名是别人买的,别人想把域名指向公网中的任意一台主机我们也没有办法。但是用了域名重定向后,可以在使用恶意域名访问我们的服务器后,会在地址栏重定向为我们指定的域名,并访问指定的站点。(理解一个原理,在一个未知域名访问我们的主机时其实是以IP的形式访问,也就是说我们重定向的其实是IP地址)
- 还有就是多域名指向同意服务器,提高访问量。
------------------------------------------------------------------
vim
/application/nginx/conf/extra/rewrite
.conf
##编译rewirte.conf文件不存在则创建,内容如下
server {
listen 80;
server_name www.rewrite.linuxidc.org;
rewrite ^/(.*) http:
//www
.easy.linuxidc.com/$1 permanent;
#^/表示
#
#永久有效
}
----OK------------------------------------------------------------
------------------------------------------------------------------
vim
/application/nginx/conf/nginx
.conf
##修改nginx的主配置文件,注意include的顺序这个很重要否则域名重定向就没用了
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application
/octet-stream
;
sendfile on;
keepalive_timeout 65;
include extra
/rewrite
.conf;
include extra
/blog
.conf;
include extra
/easy
.conf;
include extra
/bad
.conf;
}
----OK------------------------------------------------------------
/application/nginx/sbin/nginx
-t
/application/nginx/sbin/nginx
-s reload
vim
/etc/hosts
127.0.0.1 localhost www.blog.linuxidc.com www.easy.linuxidc.com www.bad.linuxidc.com
www.rewrite.linuxidc.org
curl -I www.rewrite.linuxidc.org
HTTP
/1
.1 301 Moved Permanently
Server: nginx
/1
.12.0
Date: Sun, 16 Apr 2017 14:19:58 GMT
Content-Type: text
/html
Content-Length: 185
Connection: keep-alive
Location: http:
//www
.easy.linuxidc.com/
隐藏nginx版本号:
vim
/application/nginx/conf/nginx
.conf
##修改为以下内容
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application
/octet-stream
;
sendfile on;
keepalive_timeout 65;
server{
listen 8080;
server_name www.linuxidc.win;
rewrite ^/(.*) http:
//www
.blog.linuxidc.com/$1 permanent;
}
include extra
/easy
.conf;
include extra
/bad
.conf;
include extra
/blog
.conf;
server_tokens off; #隐藏nginx版本号的设置
}
vim extra
/blog
.conf
server {
listen 80;
server_name www.blog.linuxidc.com;
access_log logs
/blog
.access.log main; #生成日志的地方
location / {
root html
/blog
;
index index.html index.htm;
}
}
log日志文件在 /application/nginx/logs 目录下
vim
/application/nginx/logs/backlog
.sh
##写一个自动备份的脚本
#!/bin/sh
for
name
in
rewrite bad blog easy;
do
/bin/mv
/application/nginx/logs/
${name}.access.log
/applog/nginx/access/
$(
date
+%F)_${name}.log
if
[ $? -
eq
0 ]
then
echo
"$(date +%F) ${name}"
>>
/applog/nginx/access/successfully
.txt
else
echo
"$(date +%F) ${name}"
>>
/applog/nginx/access/error
.txt
fi
done
/bin/find
/applog/nginx/access/
-mtime +7 -
exec
rm
-rf {} \;
---脚本完成------OK------------------------------------------------------------
mkdir
-p
/applog/nginx/access/
chmod
+x
/application/nginx/logs/backlog
.sh
crontab
-e
30 1 * * *
/application/nginx/logs/backlog
.sh
##晚上访问量少,适合做备份等工作 凌晨 1:30执行
- 基于域名的虚拟主机普遍常用到,基于IP和端口的一般在公司内部使用
- 在修改配置文件之前一定要做好备份,一边修改和对比
- 创建扩张目录,存放虚拟主机的配置,因为在企业里由于需要配合大量的业务,所以配置内容也会随之增加,如果全部都是在nginx.conf里的话会使得整个文件非常的臃肿。
- nginx的配置文件每句结尾一定要加上;(分号)
- Apache服务器在站点目录下没有index.html时,可以访问并查看整个网站的目录结构,可以通过修改httpd.conf中的“Options Indexes FollowSymLinks”---> "Options -Indexes FollowSymLinks"。nginx安全新则相对高点,如果没有index.html文件直接报错一般是403.
- Apache服务器的默认站点目录是DocumentRoot。Nginx是root html。
- 服务器一定要隐藏版本号,否则容易被攻击。
vim /etc/init.d/nginx 将下面的代码复制进去保存!
- #!/bin/bash
- # nginx Startup script for the Nginx HTTP Server
- #
- # chkconfig: - 85 15
- # description: Nginx is a high-performance web and proxy server.
- # It has a lot of features, but it's not for everyone.
- # processname: nginx
- # pidfile: /var/run/nginx.pid
- # config: /usr/local/nginx/conf/nginx.conf
- nginxd=/usr/local/nginx/sbin/nginx
- nginx_config=/usr/local/nginx/conf/nginx.conf
- nginx_pid=/usr/local/nginx/nginx.pid
- RETVAL=0
- prog="nginx"
- # Source function library.
- . /etc/rc.d/init.d/functions
- # Source networking configuration.
- . /etc/sysconfig/network
- # Check that networking is up.
- [ ${NETWORKING} = "no" ] && exit 0
- [ -x $nginxd ] || exit 0
- # Start nginx daemons functions.
- start() {
- if [ -e $nginx_pid ];then
- echo "nginx already running...."
- exit 1
- fi
- echo -n $"Starting $prog: "
- daemon $nginxd -c ${nginx_config}
- RETVAL=$?
- echo
- [ $RETVAL = 0 ] && touch /var/lock/subsys/nginx
- return $RETVAL
- }
- # Stop nginx daemons functions.
- stop() {
- echo -n $"Stopping $prog: "
- killproc $nginxd
- RETVAL=$?
- echo
- [ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /var/run/nginx.pid
- }
- # reload nginx service functions.
- reload() {
- echo -n $"Reloading $prog: "
- $nginxd -s reload
- #if your nginx version is below 0.8, please use this command: "kill -HUP `cat ${nginx_pid}`"
- RETVAL=$?
- echo
- }
- # See how we were called.
- case "$1" in
- start)
- start
- ;;
- stop)
- stop
- ;;
- reload)
- reload
- ;;
- restart)
- stop
- start
- ;;
- status)
- status $prog
- RETVAL=$?
- ;;
- *)
- echo $"Usage: $prog {start|stop|restart|reload|status|help}"
- exit 1
- esac
- exit $RETVAL
chmod +x /etc/init.d/nginx
设置开机启动
chkconfig nginx on
++++++++++++++++++++++nginx服务安装完成++++++++++++++++++++++++
Mysql
4、安装二进制mysql
mysql分类:
社区版
商业版
集群
wget --no-check-certificate https://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.39-linux-glibc2.12-x86_64.tar.gztar
zxvf
mysql-5.6.39-linux-glibc2.12-x86_64.tar.gz
cp
-avr mysql-5.6.39-linux-glibc2.12-x86_64/
/application/
cd
/application/
mv
mysql-5.6.39-
linux2.6-x86_64/ mysql-5.5.32/
ln -s mysql-5
.6.39
/ mysql
useradd
-M -s
/sbin/nologin
mysql
cd
mysql
mkdir
/application/mysql/data
-p
chown
-R mysql:mysql
/application/mysql-5
.6.39/
-----------------------------------------------------------------
.
/scripts/mysql_install_db
--basedir=
/application/mysql/
--datadir=
/application/mysql/data/
--user=mysql
##初始化数据库
mysql_install_db根据版本的不同可能存放的路径也不一样
--basedir是mysql的安装路缙
--datadir是数据文件存放路径
--user是用户名
成功的标准是
echo
$?没有错误+两个OK
##想要开机自动启动,就把mysql.server放到正确的位置即/etc/init.d/mysqld
/application/mysql//bin/mysqladmin
-u root password
'new-password'
/application/mysql//bin/mysqladmin
-u root -h linuxidc password
'new-password'
\
cp
support-files
/my-medium
.cnf
/etc/my
.cnf
\
cp
support-files
/mysql
.server
/etc/init
.d
/mysqld
不知道原来的myql的root的密码;
首先,你必须要有操作系统的root权限了。要是连系统的root权限都没有的话,先考虑root系统再走下面的步骤。 类似于安全模式登录系统。
需要先停止mysql服务,这里分两种情况,一种可以用service mysqld stop,
另外一种是/etc/init.d/mysqld stop
当提示mysql已停止后进行下一步操作 Shutting down MySQL. SUCCESS!
在终端命令行输入
mysqld_safe --skip-grant-tables & 【登录mysql系统】
输入mysql登录mysql系统
mysql> use mysql;
mysql> UPDATE user SET password=password("新密码") WHERE user='root'; 【密码注意大小写】
mysql> flush privileges;
mysql> exit;
重新启动mysql服务
这样新的root密码就设置成功了
a) 针对自己的硬件平台选用合适的编译器来优化编译后的二进制代码;
b) 根据不同的软件平台环境调整相关的编译参数;
c) 针对我们特定应用场景选择需要什么组件不需要什么组件;
d) 根据我们的所需要存储的数据内容选择只安装我们需要的字符集;
e) 同一台主机上面可以安装多个MySQL;
f) 等等其他一些可以根据特定应用场景所作的各种调整。
在源码安装给我们带来更大灵活性的同时,同样也给我们带来了可能引入的隐患:
a) 对编译参数的不够了解造成编译参数使用不当可能使编译出来的二进制代码不够稳定;
b) 对自己的应用环境把握失误而使用的优化参数可能反而使系统性能更差;
c) 还有一个并不能称之为隐患的小问题就是源码编译安装将使安装部署过程更为复杂,所花费的
时间更长;
需要下载以下的依赖包,并且编译:
libiconv(libiconv-1.14.tar.gz)
libmcrypt-2.5.8.tar.gz,加密库
mcrypt-2.6.8.tar.gz
mhash-0.9.9.9.tar.gz
wget http://cn2.php.net/get/php-5.6.34.tar.gz/from/this/mirror
yum install libxml2-devel.x86_64 libxml2.x86_64 openssl-devel.x86_64 libcurl-devel.x86_64 libjpeg-turbo.x86_64 libjpeg-turbo-devel.x86_64 png* libpng-devel.x86_64 freetype.x86_64 freetype-devel.x86_64 libxslt-devel.x86_64 libxslt.x86_64 zlib libxml libjpeg freetype libpng gd curl libiconv zlib-devel libxml2-devellibjpeg-devel freetype-devel libpng-devel gd-devel curl-devel -y
编译安装libiconv1.14:
==============================================
tar
zxvf libiconv-1.14.
tar
.gz
cd
libiconv-1.14/
.
/configure
--prefix=
/usr/local/libiconv
make
make
install
===============================================
编译安装mhash-0.9.9.9:
=================================================
wget --no-check-certificate https://sourceforge.net/projects/mhash/files/latest/download?source=files
tar
zxvf mhash-0.9.9.9.
tar
.gz
cd
mhash-0.9.9.9/
.
/configure
make
&&
make
install
================================================
编译安装libmcrypt
==================================================
tar
zxvf
libmcrypt-2.5.7.tar.gz
cd
libmcrypt-2.5.7/
.
/configure
make
&&
make
install
cp
/usr/local/lib/
*
/usr/local/lib64/
-av
ln
-s
/usr/local/lib64/libmcrypt
.la
/usr/lib64/libmcrypt
.la
ln
-s
/usr/local/lib64/libmcrypt
.so
/usr/lib64/libmcrypt
.so
ln
-s
/usr/local/lib64/libmcrypt
.so.4
/usr/lib64/libmcrypt
.so.4
ln
-s
/usr/local/lib64/libmcrypt
.so.4.4.8
/usr/lib64/libmcrypt
.so.4.4.8
ln
-s
/usr/local/lib64/libmhash
.a
/usr/lib64/libmhash
.a
ln
-s
/usr/local/lib64/libmhash
.la
/usr/lib64/libmhash
.la
ln
-s
/usr/local/lib64/libmhash
.so
/usr/lib64/libmhash
.so
ln
-s
/usr/local/lib64/libmhash
.so.2
/usr/lib64/libmhash
.so.2
ln
-s
/usr/local/lib64/libmhash
.so.2.0.1
/usr/lib64/libmhash
.so.2.0.1
ln
-s
/usr/local/bin/libmcrypt-config
/usr/bin/libmcrypt-config
##提示我搭好的环境中我并没有在/usr/local/lib64/下找到文件,文件都在/usr/local/lib,
可以把
/usr/local/lib/
下的文件复制到
/usr/local/lib64/
下
=================================================
##安装libxslt*
编译安装mcrypt-2.6.8:
================================================
tar
zxvf mcrypt-2.6.8.
tar
.gz
cd
mcrypt-2.6.8/
.
/configure
LD_LIBRAPY_PATH=
/usr/local/lib
##原因未知,这个我是百度搜出来的
make
&&
make
install
================================================
=================================================
解压下的php文件下执行
vim 1.txt
.
/configure
\
--prefix=
/application/php5
.6.30 \
--with-mysql=
/application/mysql
\
--
enable
-mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-iconv-
dir
=
/usr/local/libiconv
\
--with-freetype-
dir
\
--with-jpeg-
dir
\
--with-png-
dir
\
--with-zlib \
--with-libxml-
dir
=
/usr
\
--
enable
-xml \
--disable-rpath \
--
enable
-safe-mode \
--
enable
-bcmath \
--
enable
-shmop \
--
enable
-sysvsem \
--
enable
-inline-optimization \
--with-curl \
--with-curlwrappers \
--
enable
-mbregex \
--
enable
-fpm \
--
enable
-mbstring \
--with-mcrypt \
--with-gd \
--
enable
-gd-native-ttf \
--with-openssl \
--with-mhash \
--
enable
-pcntl \
--
enable
-sockets \
--with-xmlrpc \
--
enable
-zip \
--
enable
-soap \
--
enable
-short-tags \
--
enable
-zend-multibyte \
--
enable
-static \
--with-xsl \
--with-fpm-user=nginx \
--with-fpm-group=nginx \
--
enable
-
ftp
\
--
enable
-embedded-mysqli \
--with-mysqli \
--with-pdo-mysql=
/application/mysql
cat
1.txt |
bash
echo
$?
make
echo
$?
make
install
echo
$?
ln
-s
/application/php5
.6.30/
/application/php
cp
php.ini-production
/application/php/lib/php
.ini
##提醒:如果是做开发的话就把php.ini-development复制过去
我编译PHP遇到的错误:
+++++++++++++++++++++++++++++++++++++++++++++++++++++++
错误:configure: error: Don't know how to define struct flock on this system, set --enable-opcache=no
解决:
ln -s /application/mysql/lib/libmysqlclient.so /usr/lib64/
ln -s /application/mysql/lib/libmysqlclient.so.18 /usr/lib64/
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
问题:checking whether to enable embeddedMySQLi support... yes
checking for mysql_set_server_optionin -lmysqlclient... no
configure: error: wrong mysql libraryversion or lib not found. Check config.log for more information.
解决:--with-mysqli后面不加路径
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
问题:Don't know how to define struct flockon this system, set --enable-opcache=no
解决:
以下红色路径看具体mysql安装路径而定
32位系统:
ln -s /usr/local/MySQL/lib/libmysqlclient.so /usr/lib/
ln -s /usr/local/mysql/lib/libmysqlclient.so.18/usr/lib/libmysqlclient.so.18
64位系统:
ln -s /usr/local/MySQL/lib/libmysqlclient.so /usr/lib64/libmysqlclient.so
ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib64/libmysqlclient.so.18
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
问题:configure: error: Please reinstallreadline - I cannot find readline.h
解决:yum install readline-devel.x86_64 -y
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
问题:make: *** [sapi/cli/php] Error 1
解决:
网上统一的解决方式: makeZEND_EXTRA_LIBS='-liconv'
ln -s /usr/local/lib/libiconv.so.2/usr/lib64/
我自己的解决方式:重新编译安装libiconv(注意编译的的参数--with-iconv-dir的路径)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
由于nginx调用PHP是通过一个fcgi的程序,所以,这个程序也是有配置文件的
由于nginx调用PHP是通过一个fcgi的程序,所以,这个程序也是有配置文件的。
cd
/application/php/etc/
cp
php-fpm.conf.default php-fpm.conf
egrep
-
v
"^$|;"
php-fpm.conf
------------------------------------------------------------------------
[global]
pid =
/app/logs/php-fpm
.pid
error_log =
/app/logs/php-fpm
.log
log_level = error
rlimit_files = 32768
events.mechanism = epoll
[www]
user = nginx
group = nginx
listen = 127.0.0.1:9000
listen.owner = nginx
listen.group = nginx
pm = dynamic
pm.max_children = 1024
pm.start_servers = 16
pm.min_spare_servers = 5
pm.max_spare_servers = 20
pm.max_requests = 2048
slowlog =
/app/logs/
$pool.log.slow
request_slowlog_timeout = 10
--------------------------------------------------------------------------
..
/sbin/php-fpm
-t
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
错误:ERROR: Unable to create or
open
slowlog(
/applog/logs/www
.log.slow): No such
file
or directory (2)
解决:
mkdir
/applog/logs/
-p
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
..
/sbin/php-fpm
lsof
-i :9000
================================================
我编译PHP遇到的错误:
+++++++++++++++++++++++++++++++++++++++++++++++++++++++
错误:configure: error: Don't know how to define struct flock on this system, set --enable-opcache=no
解决:
ln -s /application/mysql/lib/libmysqlclient.so /usr/lib64/
ln -s /application/mysql/lib/libmysqlclient.so.18 /usr/lib64/
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
问题:checking whether to enable embeddedMySQLi support... yes
checking for mysql_set_server_optionin -lmysqlclient... no
configure: error: wrong mysql libraryversion or lib not found. Check config.log for more information.
解决:--with-mysqli后面不加路径
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
问题:Don't know how to define struct flockon this system, set --enable-opcache=no
解决:
以下红色路径看具体mysql安装路径而定
32位系统:
ln -s /usr/local/MySQL/lib/libmysqlclient.so /usr/lib/
ln -s /usr/local/mysql/lib/libmysqlclient.so.18/usr/lib/libmysqlclient.so.18
64位系统:
ln -s /usr/local/MySQL/lib/libmysqlclient.so /usr/lib64/libmysqlclient.so
ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib64/libmysqlclient.so.18
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
问题:configure: error: Please reinstallreadline - I cannot find readline.h
解决:yum install readline-devel.x86_64 -y
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
问题:make: *** [sapi/cli/php] Error 1
解决:
网上统一的解决方式: makeZEND_EXTRA_LIBS='-liconv'
ln -s /usr/local/lib/libiconv.so.2/usr/lib64/
我自己的解决方式:重新编译安装libiconv(注意编译的的参数--with-iconv-dir的路径)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
=================测试LNMP环境==========================
cd /application/nginx/
--------------------------------------------------
vim html/blog/index.php
<?php
phpinfo();
?>
--------------------------------------------------
vim conf/extra/blog.conf
server {
listen 80;
server_name www.blog.linuxidc.com;
access_log logs/blog.access.log main;
location / {
root html/blog;
index index.php index.html index.htm;
}
location ~ \.php$ {
root html/blog;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi_params;
include fastcgi.conf;
}
}
-----------------------------------------------------------------------------
./sbin/nginx -t
./sbin/nginx -s reload
curl www.blog.linuxidc.com
错误集:
- 如果使用curl 访问时出现502 错误,网上一大堆解决方法,就是没有说道防火墙的。所以PHP服务是自己占用一个端口的,所以需要我们手动开启。iptables -I INPUT -p tcp --dport 9000 -j ACCEPT
- 错误404和403一般是站点目录和配置文件有错误,或者服务器没起来等问题。
隐藏PHP版本:
vim /application/php/lib/php.ini
expose_php = On
搭建一个自己的开源网站:
opensns、phpcms、wiki等。
步骤:
- 下载开源软件包
- #如http://kaiyuan.linuxidc.com/
- 创建数据库
- #create database wiki;
- 创建数据库中的用户用于管理这个网站的数据
- #grant all on wiki.* towiki@’localhost’ identified by ‘wiki’;
- #flush privileges;
- #quit
- 解压开源网站到指定的站点目录
- #修改权限chown -Rnginx:nginx 目录
- 用浏览器访问
- 安装站点
总结:
LNMP搭建对于新手来说是比较困难但是要细心,前后要有呼应,理解。
遇到困难先看错误,别急着百度,因为搜出来的大部分都是复制粘贴的。
记录下来每次的错误方便下次解决。
遇到困难,做了好久的,先放松放松,去散步什么的回来说不定就会了。
二进制的mysql不推荐新手完,因为他只是预设了一些参数。
网上搜了很多,终于知道测试PHP和mysql连同的代码了:
<?php
//$link_id=mysql_connect('主机名','用户','密码');
$link_id=mysql_connect('localhost','root','RedHat')or mysql_error();
if($link_id){
echo"mysql successful";
}else{
echomysql_error();
}
?>
##以上可能有错误,但是还请原谅因为我也是新手,刚刚开始学习linux,请多多指教。