服务器LNMP环境搭建20160530

挂在外置硬盘 (参考链接:https://help.aliyun.com/knowledge_detail/6554784.html)

fdisk -l

mkfs.ext3 /dev/vdb

mkdir /data

 mount /dev/vdb /data

ls -l /data

df -h

 echo "/dev/vdb /data ext3 defaults 1 2" >> /etc/fstab


创建目录

cd /

mkdir data

cd data

mkdir download

mkdir software

mkdir web


安装依赖文件

yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers


wget http://blog.zyan.cc/soft/linux/nginx_php/libiconv/libiconv-1.13.1.tar.gz
wget http://blog.zyan.cc/soft/linux/nginx_php/mcrypt/libmcrypt-2.5.8.tar.gz
wget http://blog.zyan.cc/soft/linux/nginx_php/mcrypt/mcrypt-2.6.8.tar.gz
wget http://blog.zyan.cc/soft/linux/nginx_php/memcache/memcache-2.2.5.tgz
wget http://blog.zyan.cc/soft/linux/nginx_php/mhash/mhash-0.9.9.9.tar.gz
wget http://blog.zyan.cc/soft/linux/nginx_php/pcre/pcre-8.10.tar.gz
wget http://blog.zyan.cc/soft/linux/nginx_php/eaccelerator/eaccelerator-0.9.6.1.tar.bz2
wget http://blog.zyan.cc/soft/linux/nginx_php/pdo/PDO_MYSQL-1.0.2.tgz


tar zxvf libiconv-1.13.1.tar.gz
cd libiconv-1.13.1/
./configure --prefix=/usr/local
make
make install
cd ../

tar zxvf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8/
./configure
make
make install
/sbin/ldconfig
cd libltdl/
./configure --enable-ltdl-install
make
make install
cd ../../

tar zxvf mhash-0.9.9.9.tar.gz
cd mhash-0.9.9.9/
./configure
make
make install
cd ../

ln -s /usr/local/lib/libmcrypt.la /usr/lib/libmcrypt.la
ln -s /usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.so
ln -s /usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4
ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib/libmcrypt.so.4.4.8
ln -s /usr/local/lib/libmhash.a /usr/lib/libmhash.a
ln -s /usr/local/lib/libmhash.la /usr/lib/libmhash.la
ln -s /usr/local/lib/libmhash.so /usr/lib/libmhash.so
ln -s /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2
ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib/libmhash.so.2.0.1
ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config

tar zxvf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8/
/sbin/ldconfig
./configure
make
make install
cd ../


下载安装包

cd download

wget http://nginx.org/download/nginx-1.10.0.tar.gz

wget http://cn2.php.net/get/php-7.0.7.tar.gz/from/this/mirror


tar -zxvf nginx-1.10.0.tar.gz

tar -zxvf mirror

编译PHP

cd php-7.0.7/

./configure --prefix=/data/software/php --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-ldap --with-ldap-sasl --with-xmlrpc --enable-zip --enable-soap


报错

configure: error:Cannot find ldap librariesin/usr/lib.


解决方法
cp -frp /usr/lib64/libldap* /usr/lib/


重新编译

警告

configure: WARNING: unrecognized options: --enable-discard-path, --enable-safe-mode, --with-curlwrappers, --enable-fastcgi, --enable-force-cgi-redirect


原因

--enable-discard-path, --enable-safe-mode 在5.3后已经被取消

--enable-fastcgi 5.3开始默认开启

编译时可以 #./configure --help | grep “safe-mode” 查看一下,没有信息输出,表示已经不支持


./configure --prefix=/data/software/php --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-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-ldap --with-ldap-sasl --with-xmlrpc --enable-zip --enable-soap

make

报错:

undefined reference to `libiconv_open


編輯 Makefile :
EXTRA_LIBS = ..... -lcrypt
在最後加上 -liconv,例如:
EXTRA_LIBS = ..... -lcrypt -liconv


make


报错:

 undefined reference to symbol 'ber_strdup'

編輯 Makefile :
EXTRA_LIBS = ..... -lcrypt
在最後加上 -llber

make

make install


安装Nginx

tar zxvf pcre-8.10.tar.gz
cd pcre-8.10/
./configure
make && make install
cd ../


cd /data/download/nginx-1.10.0
./configure --user=apache --group=apache --prefix=/data/software/nginx --with-http_stub_status_module --with-http_ssl_module
make && make install
cd ../


创建日志目录

mkdir -p /data/software/log
chmod +w /data/software/log
chown -R www:www /data/software/log


从251服务器复制nginx配置文件

运行nginx -t 报错

报错行内容

image_filter resize $h $w;

原因

HttpImageFilterModule用来裁剪过大的图片到指定大小,是nginx自带模块,默认不会开启
开启HttpImageFilterModule需要在编译要带上参数 --with-http_image_filter_module

附带链接

http://www.open-open.com/lib/view/open1416193847945.html


重新编译安装Nginx

cd /data/download/nginx-1.10.0
./configure --user=apache --group=apache --prefix=/data/software/nginx --with-http_stub_status_module --with-http_ssl_module--with-http_image_filter_module

报错

./configure: error: the HTTP image filter module requires the GD library.
You can either do not enable the module or install the libraries.

安装GD库

 yum install php-gd*

yum install gd-devel


cd /data/download/nginx-1.10.0
./configure --user=apache --group=apache --prefix=/data/software/nginx --with-http_stub_status_module --with-http_ssl_module--with-http_image_filter_module
make && make install
cd ../

从251服务器复制nginx配置文件


运行nginx -t 报错

nginx: [emerg] unknown directive "image_filter_crop_offset"

原因:

没有安装ngx_http_image_filter_module

暂未处理


注释配置文件中的 image_filter_crop_offset 

运行NGINX


配置php

cd /data/software/php/etc/

cp php-fpm.conf.default php-fpm.conf

按照251服务器修改php-fpm.conf

cd php-fpm.d

cp www.conf.default www.conf

启动 php

/data/software/php/sbin/php-fpm -t //测试运行通过

/data/software/php/sbin/php-fpm (-c 可选择导入配置文件)


配置php命令

vi /etc/profile 在文件末尾加上如下两行代码

PATH=$PATH:/usr/local/webserver/php/bin:/usr/local/webserver/mysql/bin
export PATH

最后:执行 命令source /etc/profile或 执行点命令 ./profile使其修改生效,执行完可通过echo $PATH命令查看是否添加成功。


修复Nginx报错

nginx: [emerg] unknown directive "image_filter_crop_offset"

用外部ngx_http_image_filter_module.c模块替换原有模块文件编译

下载地址 :https://github.com/bobrik/nginx_image_filter

把下载的文件替换 /data/download/nginx-1.10.0/src/http/modules/ngx_http_image_filter_module.c


重新编译nginx

./configure --user=apache --group=apache --prefix=/data/software/nginx --with-http_stub_status_module --with-http_ssl_module--with-http_image_filter_module
make && make install

运行/data/software/nginx/sbin/nginx -t

无报错,启动NGINX

成功



20160602

php未支持pdo

参考资料:http://www.cnblogs.com/onlyfu/p/5051389.html

重新编译

./configure --prefix=/data/software/php --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-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-ldap --with-ldap-sasl --with-xmlrpc --enable-zip --enable-soap --enable-mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd

P.S. 带上了参数 --enable-mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd

php7相比5修改了对mysql的支持


編輯 Makefile :
EXTRA_LIBS = ..... -lcrypt
在最後加上 -liconv,例如:
EXTRA_LIBS = ..... -lcrypt -liconv

make

make install

重启php-fpm

P.S. /var/run/php-fpm/php-fpm.pid` 这个是php-fpm.conf中pid的地址

kill -USR2 `cat /var/run/php-fpm/php-fpm.pid`


安装memcache&mamcached

Memcache是该系统的项目名称,Memcached是该系统的主程序文件(字母d可以理解为daemon),以守护程序方式运行于服务器中,随时接受客户端的连接操作,使用共享内存存取数据。

1、编译Memcache (原生的Memcache 3.08版无法在PHP7下编译,故选用Github的pecl-memcache分支版本。)

https://github.com/websupport-sk/pecl-memcache/archive/php7.zip  # FTP上传
cd pecl-memcache
export PHP_PREFIX="/usr/local"
$PHP_PREFIX/php70/bin/phpize
./configure --with-php-config=$PHP_PREFIX/php70/bin/php-config
make && make install

2、修改php.ini文件,加载Memcache组件。

[memcache]
extension_dir = "/usr/local/php70/lib/php/extensions/no-debug-non-zts-20151012/"
extension = "memcache.so"

DirectAdmin中php.ini的文件位置:

/usr/local/lib/php.ini    # 默认的PHP版本。
/usr/local/php70/lib/php.ini    # 以FASTCGI模式运行PHP7。

3、重启Apache

service httpd restart

4、配置Memcached的步骤,首先安装Libevent事件触发管理器。

wget https://github.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gz
tar vxf libevent-2.0.21-stable.tar.gz
cd libevent-2.0.21-stable
./configure -prefix=/usr/local/libevent    # ./configure
make && make install
yum install libevent-devel  # Centos可以直接运行安装。

5、编译Memcached

wget http://memcached.org/files/memcached-1.4.25.tar.gz
tar vxf memcached-1.4.25.tar.gz
cd memcached-1.4.25
./configure -with-libevent=/usr/local/libevent   # ./configure
make && make install

6、启动Memcached

/usr/local/bin/memcached -d -m 128 -l 127.0.0.1 -p 11211 -u root   # (128为内存, 11211为端口,root为用户组)

开机/重启后生效,编辑 /etc/rc.d/rc.local 文件,添加以下内容。
/usr/local/bin/memcached -d -m 128 -l 127.0.0.1 -p 11211 -u root

7、查看是否生效。

ps aux|grep memcached

如提示以下信息,则已生效。

root 2219 0.0 2.4 71608 25396 ? Ssl 05:38 0:01 /usr/local/bin/memcached -d -m 32 -l 127.0.0.1 -p 11211 -u root
root 13583 0.0 0.0 4476 732 pts/0 S+ 07:47 0:00 grep memcached


------------------------------2016.08.08 搭建redis更新(转自 http://www.cnblogs.com/_popc/p/3684835.html)--------------------------------------------------
希望将redis安装到此目录 
        
        
1
/usr/local/redis

希望将安装包下载到此目录 

1
/usr/local/src

那么安装过程指令如下: 

1
2
3
4
5
6
7
$ mkdir /usr/local/redis  
$ cd /usr/local/src  
$ wget http: //redis.googlecode.com/files/redis-2.6.14.tar.gz  
$ tar xzf redis-2.6.14.tar.gz   
$ ln -s redis-2.6.14 redis #建立一个链接  
$ cd redis  
$ make PREFIX=/usr/local/redis install #安装到指定目录中

注意上面的最后一行,我们通过PREFIX指定了安装的目录。如果make失败,一般是你们系统中还未安装gcc,那么可以通过yum安装: 

1
yum install gcc

安装完成后,继续执行make. 

在安装redis成功后,你将可以在/usr/local/redis看到一个bin的目录,里面包括了以下文件: 

1
redis-benchmark  redis-check-aof  redis-check-dump  redis-cli  redis-server

第二部分:将redis做成一个服务 

1.复制脚本到/etc/rc.d/init.d目录  ps: /etc/rc.d/init.d/目录下的脚本就类似与windows中的注册表,在系统启动的时候某些指定脚本将被执行  按以上步骤安装Redis时,其服务脚本位于:

1
/usr/local/src/redis/utils/redis_init_script 

必须将其复制到/etc/rc.d/init.d的目录下: 

1
cp /usr/local/src/redis/utils/redis_init_script /etc/rc.d/init.d/redis

将redis_init_script复制到/etc/rc.d/init.d/,同时易名为redis。

如果这时添加注册服务:

1
chkconfig --add redis

将报以下错误:

1
redis服务不支持chkconfig

为此,我们需要更改redis脚本。 

2.更改redis脚本  打开使用vi打开脚本,查看脚本信息: 

1
vim /etc/rc.d/init.d/redis

看到的内容如下(下内容是更改好的信息): 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/bin/sh 
#chkconfig: 2345 80 90 
# Simple Redis init.d script conceived to work on Linux systems 
# as it does use of the /proc filesystem. 
   
REDISPORT=6379 
EXEC=/usr/local/redis/bin/redis-server 
CLIEXEC=/usr/local/redis/bin/redis-cli 
   
PIDFILE=/var/run/redis_${REDISPORT}.pid 
CONF= "/etc/redis/${REDISPORT}.conf" 
   
case "$1" in 
     start) 
         if [ -f $PIDFILE ] 
         then 
                 echo "$PIDFILE exists, process is already running or crashed" 
         else 
                 echo "Starting Redis server..." 
                 $EXEC $CONF & 
         fi 
         ;; 
     stop) 
         if [ ! -f $PIDFILE ] 
         then 
                 echo "$PIDFILE does not exist, process is not running" 
         else 
                 PID=$(cat $PIDFILE) 
                 echo "Stopping ..." 
                 $CLIEXEC -p $REDISPORT shutdown 
                 while [ -x /proc/${PID} ] 
                 do 
                     echo "Waiting for Redis to shutdown ..." 
                     sleep 1 
                 done 
                 echo "Redis stopped" 
         fi 
         ;; 
     *) 
         echo "Please use start or stop as first argument" 
         ;; 
esac 

和原配置文件相比: 

1.原文件是没有以下第2行的内容的,

1
#chkconfig: 2345 80 90 

2.原文件EXEC、CLIEXEC参数,也是有所更改。 

1
2
EXEC=/usr/local/redis/bin/redis-server   
CLIEXEC=/usr/local/redis/bin/redis-cli 

3.redis开启的命令,以后台运行的方式执行。

1
$EXEC $CONF & 

ps:注意后面的那个“&”,即是将服务转到后面运行的意思,否则启动服务时,Redis服务将 

占据在前台,占用了主用户界面,造成其它的命令执行不了。  4.将redis配置文件拷贝到/etc/redis/${REDISPORT}.conf 

1
2
mkdir /etc/redis    
cp /usr/local/src/redis/redis.conf /etc/redis/6379.conf

这样,redis服务脚本指定的CONF就存在了。默认情况下,Redis未启用认证,可以通过开启6379.conf的requirepass 指定一个验证密码。 

以上操作完成后,即可注册yedis服务:

1
chkconfig --add redis

3.启动redis服务 

1
service redis start 

第三,将Redis的命令所在目录添加到系统参数PATH中 

修改profile文件:

1
vi /etc/profile

在最后行追加: 

1
export PATH= "$PATH:/usr/local/redis/bin"

然后马上应用这个文件: 

1
. /etc/profile  

这样就可以直接调用redis-cli的命令了,如下所示: 

1
2
3
4
5
6
$ redis-cli   
redis 127.0.0.1:6379> auth superman   
OK   
redis 127.0.0.1:6379> ping   
PONG   
redis 127.0.0.1:6379>

至此,redis 就成功安装了。 

总结下:在linux系统中安装redis,或多或少都能碰到一些问题。在此次安装中3个大部分,  1.下载,安装,这里使用到wget命令,make命令,我不太懂make命令的使用,而且一直担心make命令如何安装到指定目录下, 此次终于明白了。  2.如何将一个程序添加到服务,当然也对/etc/rc.d/init.d这个文件有所了解。  3.如何将一个程序的一些命令添加到系统参数中,直接输入命令就能达到对某个程序的操作。  其实就是指定好环境变量。  下篇简单使用jedis来对redis进行存取。


------------------------------------------------------------------------安装phpredis扩展(转自 http://www.yiichina.com/tutorial/550)---------------------------------------------------

tar zxvf redis-2.2.7.tgz
cd redis-2.2.7
/data/software/php/bin/phpize
./configure

报错:configure: error: Cannot find php-config. Please use --with-php-config=PATH
解决方法 sudo ./configure --with-php-config=/data/software/php/bin/php-config 

make
报错:redis.c:7547: error: ‘smart_str’ has no member named ‘c’
原因:php7 不用这个拓展包

解决方案转自(http://www.cnblogs.com/GaZeon/p/5422078.html)
重新下载
wget https://codeload.github.com/phpredis/phpredis/zip/php7

unzip php7

cd phpredis-php7

/data/software/php/bin/phpize

./configure --with-php-config=/data/software/php/bin/php-config

make && make install

将extension=redis.so加入到php.ini

重启php-fpm





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
LNMP环境指的是Linux+Nginx+MySQL+PHP的搭建。以下是LNMP环境搭建的详细步骤: 1. 安装Linux系统 首先需要选择一款适合自己的Linux系统,例如Ubuntu、CentOS等,并进行安装。 2. 安装Nginx Nginx是一款高性能的Web服务器和反向代理服务器,可以使用以下命令进行安装: ``` sudo apt-get update sudo apt-get install nginx ``` 安装完成后,启动Nginx服务: ``` sudo systemctl start nginx ``` 3. 安装MySQL MySQL是一款流行的关系型数据库,可以使用以下命令进行安装: ``` sudo apt-get install mysql-server ``` 安装完成后,启动MySQL服务: ``` sudo systemctl start mysql ``` 4. 安装PHP PHP是一种常用的服务器端脚本语言,可以使用以下命令进行安装: ``` sudo apt-get install php-fpm php-mysql ``` 安装完成后,启动PHP服务: ``` sudo systemctl start php-fpm ``` 5. 配置Nginx 在Nginx中配置PHP支持的网站,可以使用以下命令创建一个配置文件: ``` sudo nano /etc/nginx/sites-available/example.com ``` 在配置文件中添加以下内容: ``` server { listen 80; server_name example.com; root /var/www/example.com; index index.php index.html index.htm; location / { try_files $uri $uri/ /index.php?$query_string; } location ~ \.php$ { include fastcgi_params; fastcgi_pass unix:/var/run/php/php7.4-fpm.sock; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_path_info; } } ``` 其中,example.com是你的域名,/var/www/example.com是你的网站根目录。 创建完成后,使用以下命令激活配置文件: ``` sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/ ``` 重启Nginx服务使配置生效: ``` sudo systemctl restart nginx ``` 6. 测试 在浏览器中访问你的网站,例如http://example.com,如果一切正常,你应该能够看到你的网站。 至此,LNMP环境搭建完成。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值