设为首页 收藏本站
查看: 1222|回复: 0

Ubuntu 搭建LNMP环境---及过程中所遇见的问题的相关解决方法

[复制链接]

尚未签到

发表于 2015-11-16 13:09:44 | 显示全部楼层 |阅读模式
  多久没弄PHP啦,这两天有点想法,项目的需要,又来弄弄看 DSC0000.gif
  首先得是开发环境的搭建啦》。。。



安装MYSQL:
  下载:sudo wget http://downloads.mysql.com/archives/mysql-5.0/mysql-5.0.45.tar.gz
  解压:flzhang@flzhang:~/Downloads/software$ tar zxvf mysql-5.0.45.tar.gz
  配置:
  进入源码目录:cd mysql-5.0.45
  键入:./configure --prefix=/usr/local/server/mysql/ --enable-assembler --with-extra-charsets=complex --enable-thread-safe-client --with-big-tables --with-embedded-server --enable-local-infile --with-plugins=innobase


  在我ubuntu12.0.4中出现了如下错误:
  checking for termcap functions library... configure: error: No curses/termcap library found

明显是缺少curses库,因此我们需要安装此库:
  root@flzhang:/home/flzhang/Downloads/mysql-5.0.45# sudo apt-get install libncurses5-dev
  库安装成功后,重新执行./configure --prefix=/usr/local/server/mysql/ --enable-assembler --with-extra-charsets=complex --enable-thread-safe-client --with-big-tables --with-embedded-server --enable-local-infile --with-plugins=innobase
  配置成功后如图所示:
DSC0001.jpg
  


  因在上面的配置中,我们将环境全部装在“/usr/local/server”下,所以需要先建立目录。输入“sudo mkdir /usr/local/server”回车创建目录。并将目录所属者设置成“xinxueqi.com”,执行命令“sudo chown -R flzhang:flzhang /usr/local/server
  接下来就是编译MySQL,在mysql-5.0.45目录下键入“sudo make && make install clean”:
  flzhang@flzhang:~/Downloads/mysql-5.0.45$ make && make install clean
  


  成功后如图示:
DSC0002.jpg


  


  


  成功后为了方便就是配置相关的命令了:
  首先进入到安装目录:flzhang@flzhang:~/Downloads/mysql-5.0.45$ cd /usr/local/server/mysql
  创建配置文件,键入“cp ./share/mysql/my-medium.cnf ./my.cnf”回车。

然后安装默认数据库文件,键入“./bin/mysql_install_db”回车。成功如下所示:
  

flzhang@flzhang:/usr/local/server/mysql$ ./bin/mysql_install_db
Installing MySQL system tables...
OK
Filling help tables...
OK
To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
/usr/local/server/mysql//bin/mysqladmin -u root password 'new-password'
/usr/local/server/mysql//bin/mysqladmin -u root -h flzhang password 'new-password'
See the manual for more instructions.
You can start the MySQL daemon with:
cd /usr/local/server/mysql/ ; /usr/local/server/mysql//bin/mysqld_safe &
You can test the MySQL daemon with mysql-test-run.pl
cd mysql-test ; perl mysql-test-run.pl
Please report any problems with the /usr/local/server/mysql//bin/mysqlbug script!
The latest information about MySQL is available on the web at
http://www.mysql.com
Support MySQL by buying support/licenses at http://shop.mysql.com
flzhang@flzhang:/usr/local/server/mysql$



对后我们设置服务启动脚本,执行“sudo cp ./share/mysql/mysql.server /etc/init.d/mysql”回车。

再执行“sudo chmod +x /etc/init.d/mysql”回车。

这样我们就可以使用“/etc/init.d/mysql start”及“/etc/init.d/mysql stop”运行和结束mysql服务了。  
  


  最后设置数据库root密码,这步要在数据库运行的情况下执行,首先“/etc/init.d/mysql start”启动数据库,然后再执行“./bin/mysqladmin -u root password zfl123”(zfl123是密码,根据实际情况自行设置)回车....
  这样,MYSQL就算是安装完成了。
  


  


  

安装Nginx服务器:
  
  下载:nginx-1.4.0.tar.gz
  解压:flzhang@flzhang:~/Downloads$ tar zxvf nginx-1.4.0.tar.gz


  配置:flzhang@flzhang:~/Downloads/nginx-1.4.0$  ./configure --prefix=/usr/local/server/nginx --with-http_stub_status_module
  在我的当前环境下出现如下错误:
  

checking for PCRE library in /opt/local/ ... not found
./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.
flzhang@flzhang:~/Downloads/nginx-1.4.0$



解决方法:flzhang@flzhang:~/Downloads/nginx-1.4.0$ sudo apt-get install pcre-devel  
  再次执行 ./configure --prefix=/usr/local/server/nginx --with-http_stub_status_module 又出现下面错误:
  

./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.
flzhang@flzhang:~/Downloads/nginx-1.4.0$


解决方法:flzhang@flzhang:~/Downloads/nginx-1.4.0$ sudo apt-get install libpcre3-dev

再次执行 ./configure --prefix=/usr/local/server/nginx --with-http_stub_status_module 又出现下面错误:  
  

checking for OpenSSL md5 crypto library ... not found
./configure: error: the HTTP cache module requires md5 functions
from OpenSSL library.  You can either disable the module by using
--without-http-cache option, or install the OpenSSL library into the system,
or build the OpenSSL library statically from the source with nginx by using
--with-http_ssl_module --with-openssl=<path> options.
flzhang@flzhang:~/Downloadsnginx-1.4.0$
解决方法:flzhang@flzhang:~/Downloads/nginx-1.4.0$ sudo apt-get install libssl-dev libperl-dev
  
  再次执行 ./configure --prefix=/usr/local/server/nginx --with-http_stub_status_module  呵呵,最终还是成功了:成功如下所示:



checking for struct dirent.d_type ... found
Configuration summary
&#43; using system PCRE library
&#43; OpenSSL library is not used
&#43; md5: using system crypto library
&#43; sha1 library is not used
&#43; using system zlib library
nginx path prefix: &quot;/usr/local/server/nginx&quot;
nginx binary file: &quot;/usr/local/server/nginx/sbin/nginx&quot;
nginx configuration prefix: &quot;/usr/local/server/nginx/conf&quot;
nginx configuration file: &quot;/usr/local/server/nginx/conf/nginx.conf&quot;
nginx pid file: &quot;/usr/local/server/nginx/logs/nginx.pid&quot;
nginx error log file: &quot;/usr/local/server/nginx/logs/error.log&quot;
nginx http access log file: &quot;/usr/local/server/nginx/logs/access.log&quot;
nginx http client request body temporary files: &quot;client_body_temp&quot;
nginx http proxy temporary files: &quot;proxy_temp&quot;
nginx http fastcgi temporary files: &quot;fastcgi_temp&quot;
flzhang@flzhang:~/Downloads/nginx-1.4.0$


编译:flzhang@flzhang:~/Downloads/nginx-1.4.0$ make && make install  哈哈,一步就OK 啦!打印的信息如下:  
  

nginx.old'
cp objs/nginx '/usr/local/server/nginx/sbin/nginx'
test -d '/usr/local/server/nginx/conf' || mkdir -p '/usr/local/server/nginx/conf'
cp conf/koi-win '/usr/local/server/nginx/conf'
cp conf/koi-utf '/usr/local/server/nginx/conf'
cp conf/win-utf '/usr/local/server/nginx/conf'
test -f '/usr/local/server/nginx/conf/mime.types' || cp conf/mime.types '/usr/local/server/nginx/conf'
cp conf/mime.types '/usr/local/server/nginx/conf/mime.types.default'
test -f '/usr/local/server/nginx/conf/fastcgi_params' || cp conf/fastcgi_params '/usr/local/server/nginx/conf'
cp conf/fastcgi_params '/usr/local/server/nginx/conf/fastcgi_params.default'
test -f '/usr/local/server/nginx/conf/fastcgi.conf' || cp conf/fastcgi.conf '/usr/local/server/nginx/conf'
cp conf/fastcgi.conf '/usr/local/server/nginx/conf/fastcgi.conf.default'
test -f '/usr/local/server/nginx/conf/uwsgi_params' || cp conf/uwsgi_params '/usr/local/server/nginx/conf'
cp conf/uwsgi_params '/usr/local/server/nginx/conf/uwsgi_params.default'
test -f '/usr/local/server/nginx/conf/scgi_params' || cp conf/scgi_params '/usr/local/server/nginx/conf'
cp conf/scgi_params '/usr/local/server/nginx/conf/scgi_params.default'
test -f '/usr/local/server/nginx/conf/nginx.conf' || cp conf/nginx.conf '/usr/local/server/nginx/conf/nginx.conf'
cp conf/nginx.conf '/usr/local/server/nginx/conf/nginx.conf.default'
test -d '/usr/local/server/nginx/logs' || mkdir -p '/usr/local/server/nginx/logs'
test -d '/usr/local/server/nginx/logs' || mkdir -p '/usr/local/server/nginx/logs'
test -d '/usr/local/server/nginx/html' || cp -R html '/usr/local/server/nginx'
test -d '/usr/local/server/nginx/logs' || mkdir -p '/usr/local/server/nginx/logs'
make[1]: Leaving directory `/home/flzhang/Downloads/nginx-1.4.0'
flzhang@flzhang:~/Downloads/nginx-1.4.0$


成功后新建nginx脚本,用来管理nginx服务:  
  

#!/bin/bash
#
# chkconfig: - 85 15
# description: Nginx is a World Wide Web server.
# processname: nginx
nginx=/usr/local/server/nginx/sbin/nginx
conf=/usr/local/server/nginx/conf/nginx.conf
case $1 in
start)
echo -n &quot;Starting Nginx&quot;
$nginx -c $conf
echo &quot; done&quot;
;;
stop)
echo -n &quot;Stopping Nginx&quot;
killall -9 nginx
echo &quot; done&quot;
;;
test)
$nginx -t -c $conf
;;
reload)
echo -n &quot;Reloading Nginx&quot;
ps auxww | grep nginx | grep master | awk '{print $2}' | xargs kill -HUP
echo &quot; done&quot;
;;
restart)
$0 stop
$0 start
;;
show)
ps -aux|grep nginx
;;
*)
echo -n &quot;Usage: $0 {start|restart|reload|stop|test|show}&quot;
;;
esac                                                                                                                                                  
~                                                                                                                                                     
:se nonumber


将其放置/etc/init.d/nginx 然后修改其权限,我们就可以用/etc/init.c/nginx start / stop 来开启或关闭nginx了。  
  PS : 修改端口:conf下的nginx.conf文件中的listen:80  将80改为你所需要的端口就OK 了......
  



安装PHP:
  下载:wget http://cn2.php.net/distributions/php-5.3.8.tar.gz
  解压:tar zxvf php-5.3.8.tar.gz
  配置: ./configure --prefix=/usr/local/server/php --with-config-file-path=/usr/local/server/php --enable-mbstring --enable-ftp --with-gd --with-jpeg-dir=/usr --with-png-dir=/usr --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-pear --enable-sockets --with-freetype-dir=/usr --enable-gd-native-ttf --with-zlib --with-libxml-dir=/usr --with-xmlrpc --enable-zip --enable-fpm --enable-fpm --enable-xml --enable-sockets --with-gd --with-zlib --with-iconv --enable-zip --with-freetype-dir=/usr/lib/ --enable-soap --enable-pcntl --enable-cli
  途中出现如下错误:
  

checking libxml2 install dir... /usr
checking for xml2-config path...
configure: error: xml2-config not found. Please check your libxml2 installation.
flzhang@flzhang:~/Downloads/php-5.3.8$


解决方法:flzhang@flzhang:~/Downloads/php-5.3.8$ sudo apt-get install libxml2-dev  
  重新执行:./configure --prefix=/usr/local/server/php --with-config-file-path=/usr/local/server/php --enable-mbstring --enable-ftp --with-gd --with-jpeg-dir=/usr --with-png-dir=/usr --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-pear --enable-sockets --with-freetype-dir=/usr --enable-gd-native-ttf --with-zlib --with-libxml-dir=/usr --with-xmlrpc --enable-zip --enable-fpm --enable-fpm --enable-xml --enable-sockets --with-gd --with-zlib --with-iconv --enable-zip --with-freetype-dir=/usr/lib/ --enable-soap --enable-pcntl --enable-cli
  成功如下所示:
  

creating sapi/cli/php.1
creating sapi/fpm/php-fpm.conf
creating sapi/fpm/init.d.php-fpm
creating sapi/fpm/php-fpm.8
creating main/php_config.h
creating main/internal_functions.c
creating main/internal_functions_cli.c
&#43;--------------------------------------------------------------------&#43;
| License:                                                           |
| This software is subject to the PHP License, available in this     |
| distribution in the file LICENSE.  By continuing this installation |
| process, you are bound by the terms of this license agreement.     |
| If you do not agree with the terms of this license, you must abort |
| the installation process at this point.                            |
&#43;--------------------------------------------------------------------&#43;
Thank you for using PHP.
flzhang@flzhang:~/Downloads/php-5.3.8$



  
  安装:

flzhang@flzhang:~/Downloads/php-5.3.8$ make && make install
直接OK :
  
  

Installing helper programs:       /usr/local/server/php/bin/
program: phpize
program: php-config
Installing man pages:             /usr/local/server/php/man/man1/
page: phpize.1
page: php-config.1
Installing PEAR environment:      /usr/local/server/php/lib/php/
[PEAR] Archive_Tar    - installed: 1.3.7
[PEAR] Console_Getopt - installed: 1.3.0
[PEAR] Structures_Graph- installed: 1.0.4
[PEAR] XML_Util       - installed: 1.2.1
[PEAR] PEAR           - installed: 1.9.4
Wrote PEAR system config file at: /usr/local/server/php/etc/pear.conf
You may want to add: /usr/local/server/php/lib/php to your php.ini include_path
/home/flzhang/Downloads/php-5.3.8/build/shtool install -c ext/phar/phar.phar /usr/local/server/php/bin
ln -s -f /usr/local/server/php/bin/phar.phar /usr/local/server/php/bin/phar
Installing PDO headers:          /usr/local/server/php/include/php/ext/pdo/
flzhang@flzhang:~/Downloads/php-5.3.8$

  
  

配置nginx支持PHP:
  
  首先建立存放网页文件的目录,执行“mkdri /usr/local/server/www”。  然后进入到该目录中,“cd /usr/local/server/www”。
  建立一index.php
  

<?php
phpinfo();



  

修改nginx.conf:如下所示:  

flzhang@flzhang:/usr/local/server/nginx$ git diff conf/nginx.conf
diff --git a/conf/nginx.conf b/conf/nginx.conf
index f73cd49..4f8c9fd 100644
--- a/conf/nginx.conf
&#43;&#43;&#43; b/conf/nginx.conf
@@ -40,10 &#43;40,13 @@ http {
#access_log  logs/host.access.log  main;
-        location / {
-            root   html;
-            index  index.html index.htm;
-        }
&#43;#        location / {
&#43;#            root   html;
&#43;#            index  index.html index.htm;
&#43;#        }
&#43;#
&#43;        root /usr/local/server/www;
&#43;       index index.html index.htm index.php
#error_page  404              /404.html;
@@ -62,13 &#43;65,12 @@ http {
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
-        #location ~ \.php$ {
-        #    root           html;
-        #    fastcgi_pass   127.0.0.1:9000;
-        #    fastcgi_index  index.php;
-        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
-        #    include        fastcgi_params;
-        #}
&#43;        location ~ \.php$ {
&#43;            fastcgi_pass   127.0.0.1:9000;
&#43;            fastcgi_index  index.php;
&#43;            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
&#43;            include        fastcgi_params;
:




  
  


  重启nginx,执行“sudo /etc/init.d/nginx reload”回车,并开启PHP。打开浏览器,输入“http://127.0.0.1:8080”,如下图所示:


DSC0003.jpg


  


  


  好了,至此,关于LNMP的搭建已算完成了..................................


  



版权声明:本文为博主原创文章,未经博主允许不得转载。

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-139935-1-1.html 上篇帖子: [Linux学习]安装LNMP/LAMP一键安装包 下篇帖子: 转:全新安装Mac OSX 开发者环境 同时使用homebrew搭建 (LNMP开发环境)
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表