为了账号安全,请及时绑定邮箱和手机立即绑定

linux下nginx+php+mysql环境搭建

标签:
PHP

mysqlnginxphplinuxserverinclude

++++++++++++++++++++++++++++++++++++++++++++++
linux下nginx+php+mysql环境搭建
++++++++++++++++++++++++++++++++++++++++++++++
操作系统    : [CentOS6.0]
服务器     : [nginx-1.1.8]
PHP      : [php-5.2.6]
数据库     : [mysql-5.1.59]
++++++++++++++++++++++++++++++++++++++++++++++
准备安装软件(download)
 1>[nginx-1.1.8]
      http://nginx.org/download/nginx-1.1.8.tar.gz
 2>[php-5.2.6]
      http://museum.php.net/php5/php-5.2.6.tar.gz
 3>[php-5.2.6-fpm-0.5.8.diff.gz]
      http://php-fpm.org/downloads/php-5.2.6-fpm-0.5.8.diff.gz
 4>[mysql-5.1.59]
      http://downloads.mysql.com/archives/mysql-5.1/mysql-5.1.59.tar.gz
 5>[libxml2-2.6.30]
      http://download.chinaunix.net/down.php?id=28491&ResourceID=6095&site=1
 6>[libmcrypt-2.5.8]
      http://sourceforge.net/projects/mcrypt/files/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz/download
 7>[zlib-1.2.3]
      http://sourceforge.net/projects/libpng/files/zlib/1.2.3/zlib-1.2.3.tar.gz/download
 8>[libpng-1.2.31]
      http://files.directadmin.com/services/custombuild/libpng-1.2.31.tar.gz
 9>[jpegsrc.v6b]
      http://download.chinaunix.net/down.php?id=10021&ResourceID=5095&site=1
10>[freetype-2.3.5]
       http://nongnu.askapache.com/freetype/freetype-2.3.5.tar.gz
11>[autoconf-2.61]
       http://ftp.gnu.org/gnu/autoconf/autoconf-2.61.tar.gz
12>[gd-2.0.35]
       http://code.google.com/p/google-desktop-for-linux-mirror/downloads/detail?name=gd-2.0.35.tar.gz&can=2&q=
13>[ncurses-5.6]
       http://ftp.gnu.org/gnu/ncurses/ncurses-5.6.tar.gz
14>[pcre-8.10]
       http://sourceforge.net/projects/pcre/files/pcre/8.10/pcre-8.10.tar.gz/download
15>[openssl-1.0.0e]
       http://www.openssl.org/source/openssl-1.0.0e.tar.gz
+++++++++++++++++++++++++++++++++++++++++++++
1>【安装gcc, gcc-c++】

yum install gccyum install gcc-c++

2>【开放80、3306、22端口】

#关闭防火墙service iptables stopvi /etc/sysconfig/iptables#添加-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-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT#重启防火墙service iptables restart

3>【建立lamp/src目录, 将源码包上传】
4>【安装libxml2】

tar -zxvf libxml2-2.6.30.tar.gzcd libxml2-2.6.30./configure --prefix=/usr/local/libxml2/make make install

5>【安装libmcrypt】

tar -zxvf libmcrypt-2.5.8.tar.gzcd libmcrypt-2.5.8./configure --prefix=/usr/local/libmcrypt/ --enable-ltdl-installmakemake install

6>【安装libxml2-devel】

yum install libxml2-devel

7>【安装zlib】

tar -zxvf zlib-1.2.3.tar.gzcd zlib-1.2.3./configuremakemake install

8>【安装libpng】

tar -zxvf libpng-1.2.31.tar.gzcd libpng-1.2.31./configure --prefix=/usr/local/libpng/makemake install

9>【安装jpegsrc.v6b】

mkdir /usr/local/jpeg6mkdir /usr/local/jpeg6/binmkdir /usr/local/jpeg6/libmkdir /usr/local/jpeg6/includemkdir -p /usr/local/jpeg6/man/man1tar -zxvf jpegsrc.v6b.tar.gzcd jpeg-6b./configure --prefix=/usr/local/jpeg6/ --enable-shared --enable-staticmakemake install

10>【安装freetype】

tar -zxvf freetype-2.3.5.tar.gzcd freetype-2.3.5./configure --prefix=/usr/local/freetype/makemake install

11>【安装autoconf】

tar -zxvf autoconf-2.61.tar.gzcd autoconf-2.61./configuremakemake install

12>【安装gd】

tar -zxvf gd-2.0.35.tar.gzcd gd-2.0.35./configure --prefix=/usr/local/gd2/ --with-jpeg=/usr/local/jpeg6/ --with-freetype=/usr/local/freetype/makemake install

13>【pcre-8.10】

tar -zxvf pcre-8.10.tar.gzcd pcre-8.10./configuremakemake install

14>【安装openssl】

tar -zxvf openssl-1.0.0e.tar.gzcd openssl-1.0.0e./config --prefix=/usr/local/opensslmakemake install

15>【安装nginx】

groupadd wwwuseradd -g www wwwtar -zxvf nginx-1.1.8.tar.gzcd nginx-1.1.8./configure --user=www --group=www --prefix=/usr/local/nginx --with-openssl=/lamp/src/openssl-1.0.0e --with-http_stub_status_module --with-http_ssl_module makemake install

16>【安装ncurses】

tar -zxvf ncurses-5.6.tar.gzcd ncurses-5.6./configure --with-shared --without-debug --without-ada --enable-overwritemakemake install

17>【安装mysql】

groupadd mysqluseradd -g mysql mysqltar -zxvf mysql-5.1.59.tar.gzcd mysql-5.1.59./configure --prefix=/usr/local/mysql/ --with-extra-charsets=allmakemake installcp support-files/my-medium.cnf /etc/my.cnf/usr/local/mysql/bin/mysql_install_db --user=mysqlchown -R root /usr/local/mysqlchown -R mysql /usr/local/mysql/varchgrp -R mysql /usr/local/mysql/usr/local/mysql/bin/mysqld_safe  --user=mysql &cp /lamp/src/mysql-5.1.59/support-files/mysql.server /etc/rc.d/init.d/mysqldchown root.root /etc/rc.d/init.d/mysqldchmod 755 /etc/rc.d/init.d/mysqldchkconfig --add mysqldchkconfig --list mysqldchkconfig --levels 245 mysqld off#配置mysqlcd /usr/local/mysql#简单的测试bin/mysqladmin version#查看所有mysql参数bin/mysqladmin Variables#没有密码可以直接登录本机服务器bin/mysql -urootDELETE FROM mysql.user WHERE Host='localhost' AND User='';FLUSH PRIVILEGES;#设置root密码为123456SET PASSWORD FOR 'root'@'localhost' = PASSWORD('123456');#配置可远程连接mysqluse mysqlSELECT user,password,host FROM user;DELETE FROM user WHERE host='localhsot.localdomain'DELETE FROM user WHERE host='127.0.0.1';UPDATE user SET host='%' WHERE user='root';#重启mysqlservice mysqld restart

18>【安装php】

tar -zxvf php-5.2.6.tar.gzgzip -cd php-5.2.6-fpm-0.5.8.diff.gz | patch -d php-5.2.6 -p1cd php-5.2.6./configure --prefix=/usr/local/php/ --with-config-file-path=/usr/local/php/etc/ --with-mysql=/usr/local/mysql/ --with-libxml-dir=/usr/local/libxml2/ --with-jpeg-dir=/usr/local/jpeg6/ --with-freetype-dir=/usr/local/freetype/ --with-gd=/usr/local/gd2/ --with-mcrypt=/usr/local/libmcrypt/ --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-soap --enable-mbstring=all --enable-sockets --enable-fastcgi --enable-fpmmakemake installcp php.ini-dist /usr/local/php/etc/php.ini#修改php-fpm.confvi /usr/local/php/etc/php-fpm.conf#查找63,66行将注释去掉<value name="user">nobody</value><value name="group">nobody</value>#启动php/usr/local/php/sbin/php-fpm start

19>【nginx配置】

vi /usr/local/nginx/conf/nginx.conf#在server下找到location / 修改解析PHP文件存放的路径, 修改为:location / {        root   /var/www/html;        index  index.html index.htm index.php;}#root表示虚拟目录设置为/var/www/html,增加默认解析index.php#在server下找到location ~ /.php$ 修改php解释器FastCGI配置,修改为:location ~ \.php$ {            root           /var/www/html;            fastcgi_pass   127.0.0.1:9000;            fastcgi_index  index.php;            fastcgi_param  SCRIPT_FILENAME  /var/www/html$fastcgi_script_name;            include        fastcgi_params;}#将nginx添加到自启动中echo "/usr/local/nginx/sbin/nginx" >> /etc/rc.d/rc.local#将php添加到自启动中echo "/usr/local/php/sbin/php-fpm start" >> /etc/rc.d/rc.local

20>【nginx虚拟主机配置】

vi /usr/local/nginx/conf/nginx.conf
#在http最后一行加入
include    /usr/local/nginx/conf/vhost/dev_localhost.config;
#不带url重写

server {  	listen 80 default;  	server_name dev.localhost;  	access_log logs/dev.access.log;  	root /var/www/html/dev;  	server_name_in_redirect off;  	location / {  		index index.html index.php;	}  	location ~ \.php$ {		fastcgi_pass   127.0.0.1:9000;		fastcgi_index  index.php;		fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;		include        fastcgi_params;	}}

#带url重写(zend framework)

server {	listen 80;	server_name dev.localhost;	access_log logs/dev.access.log;  			root   /var/www/html/dev/code/html;	location / {		index index.html index.php;		if (-e $request_filename ) {			break;		}					if ( $request_filename ~* \.(js|ico|gif|jpg|jpeg|xml|swf|txt|png|css|html|htm)$ ) {			return 404;		}					rewrite .* index.php;	}	location ~ .*\.php$ {		include fastcgi_params;		fastcgi_param  SCRIPT_FILENAME    $document_root/index.php;		#fastcgi_param REQUEST_URI $document_uri?$query_string;		fastcgi_read_timeout 120;		fastcgi_pass  127.0.0.1:9000;		fastcgi_index index.php;	}}


#重启nginx/usr/local/nginx/sbin/nginx -s reload#重启php/usr/local/php/sbin/php-fpm restart


点击查看更多内容
1人点赞

若觉得本文不错,就分享一下吧!

评论

作者其他优质文章

正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦
今天注册有机会得

100积分直接送

付费专栏免费学

大额优惠券免费领

立即参与 放弃机会
意见反馈 帮助中心 APP下载
官方微信

举报

0/150
提交
取消