linux下nginx+php+mysql环境搭建

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++】

[html] view plaincopyprint?

  1. yum install gcc
  2. yum install gcc-c++
yum install gcc
yum install gcc-c++

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

[html] view plaincopyprint?

  1. #关闭防火墙
  2. service iptables stop
  3. vi /etc/sysconfig/iptables
  4. #添加
  5. -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
  6. -A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
  7. -A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
  8. #重启防火墙
  9. service iptables restart
#关闭防火墙
service iptables stop
vi /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】

[html] view plaincopyprint?

  1. tar -zxvf libxml2-2.6.30.tar.gz
  2. cd libxml2-2.6.30
  3. ./configure --prefix=/usr/local/libxml2/
  4. make
  5. make install
tar -zxvf libxml2-2.6.30.tar.gz
cd libxml2-2.6.30
./configure --prefix=/usr/local/libxml2/
make
make install

5>【安装libmcrypt】

[html] view plaincopyprint?

  1. tar -zxvf libmcrypt-2.5.8.tar.gz
  2. cd libmcrypt-2.5.8
  3. ./configure --prefix=/usr/local/libmcrypt/ --enable-ltdl-install
  4. make
  5. make install
tar -zxvf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8
./configure --prefix=/usr/local/libmcrypt/ --enable-ltdl-install
make
make install

6>【安装libxml2-devel】

[html] view plaincopyprint?

  1. yum install libxml2-devel
yum install libxml2-devel

7>【安装zlib】

[html] view plaincopyprint?

  1. tar -zxvf zlib-1.2.3.tar.gz
  2. cd zlib-1.2.3
  3. ./configure
  4. make
  5. make install
tar -zxvf zlib-1.2.3.tar.gz
cd zlib-1.2.3
./configure
make
make install

8>【安装libpng】

[html] view plaincopyprint?

  1. tar -zxvf libpng-1.2.31.tar.gz
  2. cd libpng-1.2.31
  3. ./configure --prefix=/usr/local/libpng/
  4. make
  5. make install
tar -zxvf libpng-1.2.31.tar.gz
cd libpng-1.2.31
./configure --prefix=/usr/local/libpng/
make
make install

9>【安装jpegsrc.v6b】

[html] view plaincopyprint?

  1. mkdir /usr/local/jpeg6
  2. mkdir /usr/local/jpeg6/bin
  3. mkdir /usr/local/jpeg6/lib
  4. mkdir /usr/local/jpeg6/include
  5. mkdir -p /usr/local/jpeg6/man/man1
  6. tar -zxvf jpegsrc.v6b.tar.gz
  7. cd jpeg-6b
  8. ./configure --prefix=/usr/local/jpeg6/ --enable-shared --enable-static
  9. make
  10. make install
mkdir /usr/local/jpeg6
mkdir /usr/local/jpeg6/bin
mkdir /usr/local/jpeg6/lib
mkdir /usr/local/jpeg6/include
mkdir -p /usr/local/jpeg6/man/man1

tar -zxvf jpegsrc.v6b.tar.gz
cd jpeg-6b
./configure --prefix=/usr/local/jpeg6/ --enable-shared --enable-static
make
make install

10>【安装freetype】

[html] view plaincopyprint?

  1. tar -zxvf freetype-2.3.5.tar.gz
  2. cd freetype-2.3.5
  3. ./configure --prefix=/usr/local/freetype/
  4. make
  5. make install
tar -zxvf freetype-2.3.5.tar.gz
cd freetype-2.3.5
./configure --prefix=/usr/local/freetype/
make
make install

11>【安装autoconf】

[html] view plaincopyprint?

  1. tar -zxvf autoconf-2.61.tar.gz
  2. cd autoconf-2.61
  3. ./configure
  4. make
  5. make install
tar -zxvf autoconf-2.61.tar.gz
cd autoconf-2.61
./configure
make
make install

12>【安装gd】

[html] view plaincopyprint?

  1. tar -zxvf gd-2.0.35.tar.gz
  2. cd gd-2.0.35
  3. ./configure --prefix=/usr/local/gd2/ --with-jpeg=/usr/local/jpeg6/ --with-freetype=/usr/local/freetype/
  4. make
  5. make install
tar -zxvf gd-2.0.35.tar.gz
cd gd-2.0.35
./configure --prefix=/usr/local/gd2/ --with-jpeg=/usr/local/jpeg6/ --with-freetype=/usr/local/freetype/
make
make install

13>【pcre-8.10】

[html] view plaincopyprint?

  1. tar -zxvf pcre-8.10.tar.gz
  2. cd pcre-8.10
  3. ./configure
  4. make
  5. make install
tar -zxvf pcre-8.10.tar.gz
cd pcre-8.10
./configure
make
make install

14>【安装openssl】

[html] view plaincopyprint?

  1. tar -zxvf openssl-1.0.0e.tar.gz
  2. cd openssl-1.0.0e
  3. ./config --prefix=/usr/local/openssl
  4. make
  5. make install
tar -zxvf openssl-1.0.0e.tar.gz
cd openssl-1.0.0e
./config --prefix=/usr/local/openssl
make
make install

15>【安装nginx】

[html] view plaincopyprint?

  1. groupadd www
  2. useradd -g www www
  3. tar -zxvf nginx-1.1.8.tar.gz
  4. cd nginx-1.1.8
  5. ./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
  6. make
  7. make install
groupadd www
useradd -g www www
tar -zxvf nginx-1.1.8.tar.gz
cd 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
make
make install

16>【安装ncurses】

[html] view plaincopyprint?

  1. tar -zxvf ncurses-5.6.tar.gz
  2. cd ncurses-5.6
  3. ./configure --with-shared --without-debug --without-ada --enable-overwrite
  4. make
  5. make install
tar -zxvf ncurses-5.6.tar.gz
cd ncurses-5.6
./configure --with-shared --without-debug --without-ada --enable-overwrite
make
make install

17>【安装mysql】

[html] view plaincopyprint?

  1. groupadd mysql
  2. useradd -g mysql mysql
  3. tar -zxvf mysql-5.1.59.tar.gz
  4. cd mysql-5.1.59
  5. ./configure --prefix=/usr/local/mysql/ --with-extra-charsets=all
  6. make
  7. make install
  8. cp support-files/my-medium.cnf /etc/my.cnf
  9. /usr/local/mysql/bin/mysql_install_db --user=mysql
  10. chown -R root /usr/local/mysql
  11. chown -R mysql /usr/local/mysql/var
  12. chgrp -R mysql /usr/local/mysql
  13. /usr/local/mysql/bin/mysqld_safe  --user=mysql &
  14. cp /lamp/src/mysql-5.1.59/support-files/mysql.server /etc/rc.d/init.d/mysqld
  15. chown root.root /etc/rc.d/init.d/mysqld
  16. chmod 755 /etc/rc.d/init.d/mysqld
  17. chkconfig --add mysqld
  18. chkconfig --list mysqld
  19. chkconfig --levels 245 mysqld off
  20. #配置mysql
  21. cd /usr/local/mysql
  22. #简单的测试
  23. bin/mysqladmin version
  24. #查看所有mysql参数
  25. bin/mysqladmin Variables
  26. #没有密码可以直接登录本机服务器
  27. bin/mysql -uroot
  28. DELETE FROM mysql.user WHERE Host=‘localhost‘ AND User=‘‘;
  29. FLUSH PRIVILEGES;
  30. #设置root密码为123456
  31. SET PASSWORD FOR ‘root‘@‘localhost‘ = PASSWORD(‘123456‘);
  32. #配置可远程连接mysql
  33. use mysql
  34. SELECT user,password,host FROM user;
  35. DELETE FROM user WHERE host=‘localhsot.localdomain‘
  36. DELETE FROM user WHERE host=‘127.0.0.1‘;
  37. UPDATE user SET host=‘%‘ WHERE user=‘root‘;
  38. #重启mysql
  39. service mysqld restart
groupadd mysql
useradd -g mysql mysql
tar -zxvf mysql-5.1.59.tar.gz
cd mysql-5.1.59
./configure --prefix=/usr/local/mysql/ --with-extra-charsets=all
make
make install

cp support-files/my-medium.cnf /etc/my.cnf
/usr/local/mysql/bin/mysql_install_db --user=mysql
chown -R root /usr/local/mysql
chown -R mysql /usr/local/mysql/var
chgrp -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/mysqld
chown root.root /etc/rc.d/init.d/mysqld
chmod 755 /etc/rc.d/init.d/mysqld
chkconfig --add mysqld
chkconfig --list mysqld
chkconfig --levels 245 mysqld off

#配置mysql
cd /usr/local/mysql
#简单的测试
bin/mysqladmin version
#查看所有mysql参数
bin/mysqladmin Variables
#没有密码可以直接登录本机服务器
bin/mysql -uroot
DELETE FROM mysql.user WHERE Host=‘localhost‘ AND User=‘‘;
FLUSH PRIVILEGES;
#设置root密码为123456
SET PASSWORD FOR ‘root‘@‘localhost‘ = PASSWORD(‘123456‘);
#配置可远程连接mysql
use mysql
SELECT 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‘;
#重启mysql
service mysqld restart

18>【安装php】

[html] view plaincopyprint?

  1. tar -zxvf php-5.2.6.tar.gz
  2. gzip -cd php-5.2.6-fpm-0.5.8.diff.gz | patch -d php-5.2.6 -p1
  3. cd php-5.2.6
  4. ./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-fpm
  5. make
  6. make install
  7. cp php.ini-dist /usr/local/php/etc/php.ini
  8. #修改php-fpm.conf
  9. vi /usr/local/php/etc/php-fpm.conf
  10. #查找63,66行将注释去掉
  11. <value name="user">nobody</value>
  12. <value name="group">nobody</value>
  13. #启动php
  14. /usr/local/php/sbin/php-fpm start
tar -zxvf php-5.2.6.tar.gz
gzip -cd php-5.2.6-fpm-0.5.8.diff.gz | patch -d php-5.2.6 -p1

cd 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-fpm
make
make install
cp php.ini-dist /usr/local/php/etc/php.ini
#修改php-fpm.conf
vi /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配置】

[html] view plaincopyprint?

  1. vi /usr/local/nginx/conf/nginx.conf
  2. #在server下找到location / 修改解析PHP文件存放的路径, 修改为:
  3. location / {
  4. root   /var/www/html;
  5. index  index.html index.htm index.php;
  6. }
  7. #root表示虚拟目录设置为/var/www/html,增加默认解析index.php
  8. #在server下找到location ~ /.php$ 修改php解释器FastCGI配置,修改为:
  9. location ~ \.php$ {
  10. root           /var/www/html;
  11. fastcgi_pass   127.0.0.1:9000;
  12. fastcgi_index  index.php;
  13. fastcgi_param  SCRIPT_FILENAME  /var/www/html$fastcgi_script_name;
  14. include        fastcgi_params;
  15. }
  16. #将nginx添加到自启动中
  17. echo "/usr/local/nginx/sbin/nginx" >> /etc/rc.d/rc.local
  18. #将php添加到自启动中
  19. echo "/usr/local/php/sbin/php-fpm start" >> /etc/rc.d/rc.local
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重写

[html] view plaincopyprint?

  1. server {
  2. listen 80 default;
  3. server_name dev.localhost;
  4. access_log logs/dev.access.log;
  5. root /var/www/html/dev;
  6. server_name_in_redirect off;
  7. location / {
  8. index index.html index.php;
  9. }
  10. location ~ \.php$ {
  11. fastcgi_pass   127.0.0.1:9000;
  12. fastcgi_index  index.php;
  13. fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
  14. include        fastcgi_params;
  15. }
  16. }
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)

[html] view plaincopyprint?

  1. server {
  2. listen 80;
  3. server_name dev.localhost;
  4. access_log logs/dev.access.log;
  5. root   /var/www/html/dev/code/html;
  6. location / {
  7. index index.html index.php;
  8. if (-e $request_filename ) {
  9. break;
  10. }
  11. if ( $request_filename ~* \.(js|ico|gif|jpg|jpeg|xml|swf|txt|png|css|html|htm)$ ) {
  12. return 404;
  13. }
  14. rewrite .* index.php;
  15. }
  16. location ~ .*\.php$ {
  17. include fastcgi_params;
  18. fastcgi_param  SCRIPT_FILENAME    $document_root/index.php;
  19. #fastcgi_param REQUEST_URI $document_uri?$query_string;
  20. fastcgi_read_timeout 120;
  21. fastcgi_pass  127.0.0.1:9000;
  22. fastcgi_index index.php;
  23. }
  24. }
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;
	}
}

[html] view plaincopyprint?

  1. #重启nginx
  2. /usr/local/nginx/sbin/nginx -s reload
  3. #重启php
  4. /usr/local/php/sbin/php-fpm restart
时间: 2024-10-02 10:10:39

linux下nginx+php+mysql环境搭建的相关文章

Linux下Nginx+PHP+Mysql环境搭建过程(图文)

一.使用yum命令,安装所需的程序库        1.命令内容                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

linux下nginx+php+mysql 自助环境搭建

++++++++++++++++++++++++++++++++++++++++++++++linux下nginx+php+mysql环境搭建++++++++++++++++++++++++++++++++++++++++++++++操作系统 : [CentOS6.0]服务器 : [nginx-1.1.8]PHP : [php-5.2.6]数据库 : [mysql-5.1.59]++++++++++++++++++++++++++++++++++++++++++++++准备安装软件(downlo

linux 下cocos2dx-3.3.1环境搭建

1.安装依赖 依赖包含: libx11-dev libxmu-dev libglu1-mesa-dev libgl2ps-dev libxi-dev g++ libzip-dev libpng12-dev libcurl4-gnutls-dev libfontconfig1-dev libsqlite3-dev libglew*-dev libssl-dev 假设你的系统是Ubuntu/Debian,能够通过运行build文件夹下的install-deps-linux.sh脚本来安装依赖,也可自

Linux下的ssh实验环境搭建与管理

Linux下的ssh实验环境搭建与管理 实验环境 服务端:xuegod-63   IP:192.168.1.63 客户端:xuegod-64   IP:192.168.1.64 客户端普通用户:ceshi  密码:123456 安装好扫描软件rpm -ivh /mnt/Packages/nmap-5.21-4.el6.x86_64.rpm 实验目标 1:SSHD服务介绍 2:SSHD服务安装配置 3:两Linux服务器之间数据拷贝 4:SSHD服务作用: 实验步骤 1:搭建环境 1):网桥模式

《Python入门》Linux 下 Python Web开发环境搭建笔记

之前写过 Windows 7下Python Web开发环境搭建笔记,今天写一下在Linux系统下搭建Python Web的开发测试环境. 我使用的系统是:ubuntu 14.04 server,根据个人经验,CentOS 6.5 下也适用. 关于Python的版本 进入Python的网站,鼠标移到导航条上的下载,我们会发现提供两下主版本的下载链接! 这两个之间存在什么差别呢? 个人理解,2.7.x的版本为更加稳定的版本,而3.x的版本则是比较前卫的版本,包含了很多新功能新特性之类的: 但如果想要

linux下的Android开发环境搭建(2)

一.JDK的安装配置 在个人主文件夹下新建文件夹software,在software下新建java文件夹,用于存放各种android开发程序,本人用户名叫aaa,所以完整目录就是/home/aaa/ software/java 然后把jdk-7-linux-x64.gz复制到/home/aaa/software/java/目录下面,右键解压缩,会出现jdk-7-linux-x64文件,再次右键解压缩,出现jdk1.7.0文件夹,如图1-1: 图1-1 接下来配置开发环境,使用命令sudo ged

WINDOW下php+Apache+mysql环境搭建

工具/原料 php-5.5.10-Win32-VC11-x64.zip 下载地址: http://windows.php.net/download/ httpd-2.4.7-win64-VC11.zip 下载地址: http://www.apachelounge.com/download/ mysql-5.6.16-winx64.zip 下载地址: http://dev.mysql.com/downloads/mysql/ 方法/步骤 一.安装配置Apache2.4.7(httpd-2.4.7-

总结linux下 nginx,MySQL,PHP的安装过程

nginx的安装过程 1.先找到nginx的官网进去复制最新版本的下载地址在虚拟机上进行下载 wget http://nginx.org/download/nginx-1.16.0.tar.gz 2.把nginx压缩包解压到/usr/local/nginx/ tar -zxcf nginx-1.16.0.tar.gz -C /usr/local/nginx/ 3.下载他所需要的包 yum -y install gcc gcc-c++ autoconf automake make openssl

linux下XAMP集成开发环境搭建流程总结

一.安装xampp: 1.用wget下载安装包; 2.为安装包添加执行权限; 3.直接安装到/opt/; 4.添加开机启动:ln -s /opt/lampp/lampp  /usr/bin/ 二.防火墙http80端口与3306端口开启; 方法一.setup->选择firewall->http.mysql前打上*号; 方法二.进入/etc/sysconfig/iptables增加相应命令; 方法三.直接用iptables相关命令修改; 三.apache配置:/opt/lampp/bin/htt