做php开发的,想要进一步提升自己,手动搭建开发环境,我想是必须经历的一个坎。虽然说有很多第三方集成环境可供使用,但我想说的是在你没有自己搭建过一次环境的时候,你没有太多的资本去“偷懒”。虽然我自己也是个菜鸟,但我乐意分享我的成长历程和学习成果。所以今天我说说我自己搭建lnmp环境的整个流程,有表述不清的地方或者错误,希望大伙不吝指出。废话不多说了,开干。

一、主机环境:

虚拟机安装的centos 6.7 , i686

二、各应用版本:

php: 5.6.3

mysql: 5.6.12

nginx: 1.8.0


三、准备安装包:

为了节省大伙时间,我已经放置在微云盘: http://share.weiyun.com/f891e9c6547bd9abf03072e554626ee6(密码:9Z4G),包含了安装过程需要用到的所有安装包。

现在,我们做如下约定:

  1. <pre name="code" class="plain">  <strong><span style="font-size:18px;">/usr/local/src</span></strong>

    这是我们存放安装包的路径

  2. <pre name="code" class="plain"> <strong><span style="font-size:18px;">/usr/local</span></strong>

    这是各应用的安装路径

在安装包目录下解压压缩包:

        <pre name="code" class="plain">        <strong><span style="font-size:18px;">unzip   lnmp.zip</span></strong>

四、环境预设:

1、防火墙设置:

打开 iptables文件:

<pre name="code" class="plain"><span style="font-size:18px;"> <strong>vim   /etc/sysconfig/iptables</strong></span>

添加两行:

<span style="font-size:18px;">-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT</span>

第一行是为网络协议开放的端口,第二行为mysql数据库开放的端口。

编辑完要重启iptables:

<pre name="code" class="plain"><strong><span style="font-size:18px;">service iptables restart</span></strong>

2、关闭SELINUX:

<strong><span style="font-size:18px;">vim /etc/selinux/config</span></strong>
</pre><pre>

注释掉 SELINUX=enforcing 和 SELINUXTYPE=targeted,然后 在最底部添加 SELINUX=disabled

3、安装编译工具及依赖库文件:

直接用yum命令安装,如下:

<pre name="code" class="plain"><strong><span style="font-size:18px;">yum install -y apr* autoconf automake bison bzip2 bzip2* cloog-ppl compat* cpp curl curl-devel fontconfig fontconfig-devel freetype freetype* freetype-devel gcc gcc-c++ gtk+-devel gd gettext gettext-devel glibc kernel kernel-headers keyutils keyutils-libs-devel krb5-devel libcom_err-devel libpng libpng* libpng-devel libjpeg* libsepol-devel libselinux-devel libstdc++-devel libtool* libgomp libxml2 libxml2-devel libXpm* libX* libtiff libtiff* make mpfr ncurses* ntp openssl nasm nasm* openssl-devel patch pcre-devel perl php-common php-gd policycoreutils ppl telnet t1lib t1lib* wget zlib-devel</span></strong>


五、安装mysql

1、由于是采用cmake方式编译安装mysql,因此得先安装cmake:

<pre name="code" class="plain"><strong><span style="font-size:18px;">cd /usr/local/src</span></strong>
<strong><span style="font-size:18px;">tar -zxvf  cmake-3.0.2.tar.gz</span></strong>
<strong><span style="font-size:18px;">cd cmake-3.0.2
./configure && make && make install</span></strong>

2、cmake安装完成后即可编译安装mysql了,正式安装mysql之前,我们还有个小任务

<pre name="code" class="plain"><strong><span style="font-size:18px;">groupadd mysql   #添加mysql组
useradd -g mysql mysql -s /bin/false  #创建用户mysql并加入到mysql组,不允许mysql用户直接登录系统
mkdir -p /data/mysql    #创建MySQL数据库存放目录
chown -R mysql:mysql /data/mysql     #设置MySQL数据库存放目录权限
mkdir -p /usr/local/mysql     #创建MySQL安装目录</span></strong>

3、现在可以正式编译mysql了:

<pre name="code" class="plain"><strong><span style="font-size:18px;">tar -zxvf  mysql-5.6.21.tar.gzcd mysql-5.6.21cmake  .  -DCMAKE_INSTALL_PREFIX=/usr/local/mysql  -DMYSQL_DATADIR=/data/mysql  -DSYSCONFDIR=/etc  -DDEFAULT_CHARSET=utf8  -DDEFAULT_COLLATION=utf8_general_ci -DMYSQL_TCP_PORT=3306make && make install</span></strong>

4、编译完成后我们就用进入mysql的安装目录:

<pre name="code" class="plain"><strong><span style="font-size:18px;">cd  /usr/local/mysql</span></strong>

生成mysql数据库系统:

<pre name="code" class="plain"><strong><span style="font-size:18px;">./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql</span></strong>

5、下面就要修改配置文件了:

<pre name="code" class="html">
<strong><span style="font-size:18px;">cp /usr/local/mysql/support-files/mysql.server  /etc/rc.d/init.d/mysqld</span></strong>
<strong><span style="font-size:18px;">
vim /etc/rc.d/init.d/mysqld</span></strong>
<pre name="code" class="plain">

找到大概46、47行的位置,修改如下:

<strong><span style="font-size:18px;">basedir=/usr/local/mysql
datadir=/data/mysql</span></strong>

保存退出。

6、试着启动mysql:

<pre name="code" class="plain"><strong><span style="font-size:18px;">service mysqld start</span></strong>

可以看到 "Starting  MySQL. SUCCESS !"说明启动成功。

我们通常习惯将其放置系统变量,因此打开/etc/profile 文件,在倒数第三行左右,修改如下:

<strong><span style="font-size:18px;">export PATH=$PATH:/usr/local/mysql/bin</span></strong>

然后刷新/etc/profile文件:

<pre name="code" class="plain"><strong><span style="font-size:18px;">source /etc/profile</span></strong>

7、mysql安装完成后是默认没有设置root的密码的,因此安全起见,我们设置root账户密码:

<pre name="code" class="plain"><strong><span style="font-size:18px;">mysql_secure_installation</span></strong>

输入命令后按照提示走,相信你可以的。

设置完后,我们测试root密码是否生成了:

<pre name="code" class="plain"><strong><span style="font-size:18px;">mysql -uroot -p</span></strong>

根据提示输入刚刚设置的root新密码,

如果看到上面这个界面,那么恭喜你,说明你完成了mysql的安装。

六、安装nginx

1、安装nginx所需的依赖包pcre、openssl、zlib:

<pre name="code" class="plain"><strong><span style="font-size:18px;">tar -zxvf pcre-8.36.tar.gz
cd  pcre-8.36
./configure && make && make install</span></strong>

安装openssl和zlib和安装pcre的方法是一样的,这里不多赘述。

在按装完openssl后,需要多做件事: 打开/etc/profile,在之前添加的

<strong><span style="font-size:18px;">export PATH=$PATH:/usr/local/mysql/bin</span></strong>

后面添加下面这行:

<strong><span style="font-size:18px;">export PATH=$PATH:/usr/local/openssl/bin
</span></strong>

保存后,让其生效:

<pre name="code" class="plain"><pre name="code" class="plain"><strong><span style="font-size:18px;">source /etc/profile</span></strong>

2、编译安装nginx:

 <pre name="code" class="plain"><strong><span style="font-size:18px;">tar -zxvf nginx-1.8.0.tar.gz
cd  nginx-1.8.0
./configure --prefix=/usr/local/nginx --without-http_memcached_module --user=nobody  --group=nobody  --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-openssl=/usr/local/src/openssl-1.0.1j --with-zlib=/usr/local/src/zlib-1.2.8 --with-pcre=/usr/local/src/pcre-8.36</strong>
make && make install</span></strong>

编译安装完成后,启动:

<pre name="code" class="plain"><pre name="code" class="plain"><strong><span style="font-size:18px;">/usr/local/nginx/sbin/nginx</span></strong>

然后将在/etc/rc.d/init.d/下新增文件nginx,内容如下

<strong><span style="font-size:18px;">#!/bin/sh
#
# nginx - this script starts and stops the nginx daemin
#
# chkconfig:   - 85 15
# description:  Nginx is an HTTP(S) server, HTTP(S) reverse \
#               proxy and IMAP/POP3 proxy server
# processname: nginx
# config:      /usr/local/nginx/conf/nginx.conf
# pidfile:     /usr/local/nginx/logs/nginx.pid# Source function library.
. /etc/rc.d/init.d/functions# Source networking configuration.
. /etc/sysconfig/network# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0nginx="/usr/local/nginx/sbin/nginx"
prog=$(basename $nginx)NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"lockfile=/var/lock/subsys/nginxstart() {[ -x $nginx ] || exit 5[ -f $NGINX_CONF_FILE ] || exit 6echo -n $"Starting $prog: "ulimit -SHn 65535daemon $nginx -c $NGINX_CONF_FILEretval=$?echo[ $retval -eq 0 ] && touch $lockfilereturn $retval
}stop() {echo -n $"Stopping $prog: "killproc $prog -QUITretval=$?echo[ $retval -eq 0 ] && rm -f $lockfilereturn $retval
}restart() {configtest || return $?stopstart
}reload() {configtest || return $?echo -n $"Reloading $prog: "killproc $nginx -HUPRETVAL=$?echo
}force_reload() {restart
}configtest() {$nginx -t -c $NGINX_CONF_FILE
}rh_status() {status $prog
}rh_status_q() {rh_status >/dev/null 2>&1
}case "$1" instart)rh_status_q && exit 0$1;;stop)rh_status_q || exit 0$1;;restart|configtest)$1;;reload)rh_status_q || exit 7$1;;force-reload)force_reload;;status)rh_status;;condrestart|try-restart)rh_status_q || exit 0;;*)echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"exit 2
esac</span></strong>


赋予其执行权限:

<pre name="code" class="plain"><strong><span style="font-size:18px;">chmod 775 /etc/rc.d/init.d/nginx</span></strong>

设置开机启动:

<pre name="code" class="plain"><strong><span style="font-size:18px;">chkconfig --add nginx
chkconfig nginx on </span></strong>

再重启nginx:

<pre name="code" class="plain"><strong><span style="font-size:18px;">service nginx restart</span></strong>

3、测试nginx是否安装成功:

在浏览器网址输入框输入:  localhost ,你会看到很鸡冻的画面。

==================================================我的鸡汤========================================================

天哪,废了好大劲才把mysql安装完成,这全部弄完不累死才怪。。。

千万别这么想啊,最难过的时候,也是离成功最近的时候。所以一定要挺住,干吧得

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

七、安装php

1、先安装php的相关扩展库yasm、libmcrypt、libvpx、tiff、libpng、freetype、jpeg

这些命令都是: ./configure && make && make install

安装 libgd 有些区别:

<pre name="code" class="plain"><strong><span style="font-size:18px;">./configure --prefix=/usr/local/libgd --enable-shared --with-jpeg=/usr/local/jpeg --with-png=/usr/local/libpng --with-freetype=/usr/local/freetype --with-fontconfig=/usr/local/freetype --with-xpm=/usr/ --with-tiff=/usr/local/tiff --with-vpx=/usr/local/libvpx
make && make install</span></strong>

安装 t1lib 这里有个坑,虽小但估计害死了一批人,记得不是make而是make without_doc:

<pre name="code" class="plain"><strong><span style="font-size:18px;">./configure --prefix=/usr/local/t1lib --enable-shared
make without_doc && make install</span></strong>

2、编译安装php

<pre name="code" class="plain"><strong><span style="font-size:18px;">tar -zvxf php-5.6.3.tar.gzcd php-5.6.3./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-mysql-sock=/tmp/mysql.sock --with-pdo-mysql=/usr/local/mysql --with-gd --with-png-dir=/usr/local/libpng --with-jpeg-dir=/usr/local/jpeg --with-freetype-dir=/usr/local/freetype --with-xpm-dir=/usr/ --with-vpx-dir=/usr/local/libvpx/ --with-zlib-dir=/usr/local/zlib --with-t1lib=/usr/local/t1lib --with-iconv --enable-libxml --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --enable-opcache --enable-mbregex --enable-fpm --enable-mbstring --enable-ftp --enable-gd-native-ttf --with-openssl --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --enable-session --with-mcrypt --with-curl --enable-ctypemake && make test &&  make install</span></strong>

3、配置php

复制php配置文件到安装目录:

<pre name="code" class="plain"><strong><span style="font-size:18px;">cp  php.ini-production  /usr/local/php/etc/php.ini</span></strong>

将配置文件链到etc下:

<pre name="code" class="plain"><strong><span style="font-size:18px;">ln -s /usr/local/php/etc/php.ini /etc/php.ini</span></strong>

php.ini里的具体配置这里不多说。

4、由于我们使用php-fpm管理php的,因此php-fpm也需要配置

<pre name="code" class="plain"><strong><span style="font-size:18px;">cp /usr/local/php/etc/php-fpm.conf.default   /usr/local/php/etc/php-fpm.conf
vim  /usr/local/php/etc/php-fpm.conf</span></strong>
修改对应的地方(地25行左右):

<strong><span style="font-size:18px;">pid = run/php-fpm.pid #取消前面的分号</span></strong>

接下来设置php-fpm开机启动:

<pre name="code" class="plain"><strong><span style="font-size:18px;">cp /usr/local/src/php-5.6.3/sapi/fpm/init.d.php-fpm   /etc/rc.d/init.d/php-fpm
chmod +x /etc/rc.d/init.d/php-fpm
chkconfig php-fpm on </span></strong>

5、配置nginx支持php

所有服务都安装完了,但这时候nginx和php还不是同路人呢,得给他们牵条线,双方才能合作呢。

<pre name="code" class="plain"><strong><span style="font-size:18px;">vim /usr/local/nginx/conf/fcgi.conf</span></strong>

内容如下:

<pre name="code" class="plain"><strong><span style="font-size:18px;">fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
fastcgi_param  SERVER_SOFTWARE    nginx;fastcgi_param  QUERY_STRING       $query_string;
fastcgi_param  REQUEST_METHOD     $request_method;
fastcgi_param  CONTENT_TYPE       $content_type;
fastcgi_param  CONTENT_LENGTH     $content_length;fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
fastcgi_param  REQUEST_URI        $request_uri;
fastcgi_param  DOCUMENT_URI       $document_uri;
fastcgi_param  DOCUMENT_ROOT      $document_root;
fastcgi_param  SERVER_PROTOCOL    $server_protocol;fastcgi_param  REMOTE_ADDR        $remote_addr;
fastcgi_param  REMOTE_PORT        $remote_port;
fastcgi_param  SERVER_ADDR        $server_addr;
fastcgi_param  SERVER_PORT        $server_port;
fastcgi_param  SERVER_NAME        $server_name;# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param  REDIRECT_STATUS    200;
</span></strong>

修改nginx配置文件

<pre name="code" class="plain"><strong><span style="font-size:18px;">vim /usr/local/nginx/conf/nginx.conf</span></strong>

内容修改如下:

<pre name="code" class="plain"><strong><span style="font-size:18px;">user  nobody nobody;
worker_processes  4;#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;#pid        logs/nginx.pid;events {worker_connections  1024;
}http {include       mime.types;default_type  application/octet-stream;#log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '#                  '$status $body_bytes_sent "$http_referer" '#                  '"$http_user_agent" "$http_x_forwarded_for"';#access_log  logs/access.log  main;sendfile        on;#tcp_nopush     on;#keepalive_timeout  0;keepalive_timeout  65;#gzip  on;server {listen       80;server_name  localhost;#charset koi8-r;#access_log  logs/host.access.log  main;location / {root   /data/www;index  index.php index.html index.htm;}#error_page  404              /404.html;# redirect server error pages to the static page /50x.html##error_page   500 502 503 504  /50x.html;#location = /50x.html {#    root   html;#}# proxy the PHP scripts to Apache listening on 127.0.0.1:80##location ~ \.php$ {#    proxy_pass   http://127.0.0.1;#}# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000#location ~ \.php$ {root           /data/www;fastcgi_pass   127.0.0.1:9000;fastcgi_index  index.php;include        fcgi.conf;   #此处就是引用刚刚新增的文件}# deny access to .htaccess files, if Apache's document root# concurs with nginx's one##location ~ /\.ht {#    deny  all;#}location /tongji {stub_status on;access_log off;auth_basic "Nginx status";auth_basic_user_file /usr/local/nginx/.htpasswd;}}</span></strong>

6、测试php和nginx是否合作愉快:

在/data/www/目录下新增index.php:

写入php测试代码:

<pre name="code" class="php"><strong><span style="font-size:18px;"><?php
<span style="white-space:pre"> </span>phpinfo();
?></span></strong>

打开浏览器,输入localhost,如果你看到phpinfo函数打印出的相关信息,说明你成功了。好感动啊啊啊。。。。。

七、总结

此教程属于为新手准备的饭菜,按照此教程配置的lnmp环境只是达到了让其工作的层面,离部署代码正式上线是还有很大的差距,因此,希望各位参考为主,不应该将此配置成功用于正式环境。介于我粗劣的描述能力,不喜勿喷。


手动配置lnmp环境相关推荐

  1. RedHat6.2 x86手动配置LNMP环境

    为什么80%的码农都做不了架构师?>>>    因为公司要求用RedHat配,顺便让我练习一下Linux里面的操作什么的. 折腾来折腾去终于搞好了,其实也没那么难嘛.但是也要记录一下 ...

  2. 腾讯云服务器CVM(CentOS 7、Tencent Linux)手动搭建LNMP环境(linux+Nginx+Mariadb+PHP)

    手动搭建云服务器运行环境就是喜欢折腾,如果觉得麻烦的网友可以使用LNMP镜像直接启动CVM实例,以便快速建站. 腾讯云服务器CVM(CentOS 7.Tencent Linux)手动搭建LNMP环境( ...

  3. wamp安装和配置_手动配置Wordpress环境真香,让我毫不犹豫卸载LAMP和WAMP环境

    作为一名Java开发者,我平时也喜欢学习除Java以外的其他技术,例如PHP(有人说PHP是最好的编程语言,我无心考究).对于任何一个开发者,在学习一门新的编程语言过程中,首先都会面对配置开发环境这样 ...

  4. Kali配置LNMP环境并搭建pikachu环境

    文章目录 Kali配置LNMP环境并搭建pikachu环境 安装Nginx 安装PHP7.4和PHP扩展 配置Nginx和PHP-FPM 测试 安装mariadb 安装PHP Mysql扩展用来连接数 ...

  5. CentOS手动安装配置LNMP环境

    实测 CentOS 7.*和 8版本的系统能正常配置. 首先安装nginx和php ,安装默认版本的nginx,php默认安装7 yum install nginx php 然后输入 y 确定安装 启 ...

  6. ubuntu16 下 源码配置Lnmp环境

    最近把系统升级到 ubuntu16长期支持版 ,重新部署了lnmp环境 约定几个目录  源码目录  /usr/local/src mysql     /usr/local/mysql php  /us ...

  7. c++篇 cad.grx 入门,手动配置编译环境

    安装vs2010+sp1补丁; 安装浩辰2018(64位版本); 下载浩辰Grx开发的SDK,注意对应版本年份., 解压到E盘目录下, E:\grxsdk 在他们的官方用户群下载,搜sdk, 找到gr ...

  8. 如何手动配置python环境变量-简单方便-光速配置

    第一步: 安装完后如果没有在安装python的时候选择自动配置变量的选项,那在Windows cmd环境下运行python是不行的 它会提示你不是内部执行指令 第二步: 如果上面没有自动配置上那就得手 ...

  9. php vhost配置,lnmp环境vhost配置

    lnmp环境下的nginx站点,首先在/usr/local/nginx/conf/nginx.conf中开启vhost: include vhost/*.conf; 开启后,在'/usr/local/ ...

最新文章

  1. Spark Streaming使用Kafka保证数据零丢失
  2. Maven配置将war包部署到Tomcat(tomcat7-maven-plugin)
  3. word如何发布博客到博客园
  4. sql union 语句 case语句
  5. E1. Rubik‘s Cube Coloring (easy version) 贪心,满二叉树(1300)
  6. html坐标定位图解,HTML5地理定位实例
  7. 转 Celery 使用
  8. 信息学奥赛一本通 1315:【例4.5】集合的划分
  9. LINUX SHELL获得CPU核心(线程)个数
  10. 地图学相关知识(四)
  11. 基于JavaWeb的小区物业管理系统的设计与实现
  12. 不到两年的前端小白2017个人年终总结:今年的年终总结是为了更好的自己
  13. 关于opencv读取图片,无法正常显示
  14. ubuntu 18.04 使用intel核显画面撕裂解决办法
  15. 图像对抗学习笔记:复现DPatch
  16. JAVA生成二维码(一)
  17. 《超效率手册》读书笔记
  18. TUANDUIZUOYE
  19. 【渝粤教育】电大中专电商运营实操 (21)作业 题库
  20. 云服务器+windows iis系统+微信App平台程序+vb.net后台服务开发流程

热门文章

  1. Linux系统启动任务的写法
  2. 深入探讨PHP中的内存管理问题
  3. 利用WebClient和WebRequest类获得网页源代码C#
  4. C++11中std::unique_lock的使用
  5. 【视频】视频方面大神博客总结
  6. blf文件用什么软件打开_如何用皕杰流程创建一个blf演示流程文件?
  7. jquery click 第一次没用_【通知】同济大学研究生会20202021学年第一次主席联席会...
  8. qt信号发送间隔短而槽耗时多_Qt信号槽问题汇总 - osc_9q1dp3jk的个人空间 - OSCHINA - 中文开源技术交流社区...
  9. vim替换字符串带斜杠_Vim、gvim操作替换
  10. diy高性能存储服务器,diy存储服务器