Build an nginx + php + mysql environment in linux

Source: Internet
Author: User
In linux, nginx + php + mysql environment setup ++ ++ operating system: [CentOS6.0] server: [nginx-1.1.8] PHP: [php-5.2.6] database: [mysql-5.1.59] ++ ++ prepare for software installation (download) 1 [n

In linux, nginx + php + mysql environment setup ++ ++ operating system: [CentOS6.0] server: [nginx-1.1.8] PHP: [php-5.2.6] database: [mysql-5.1.59] ++ ++ prepare for software installation (download) 1 [n

Build an nginx + php + mysql environment in linux

++ ++

Operating System: [CentOS6.0]

Server: [nginx-1.1.8]

PHP: [php-5.2.6]

Database: [mysql-5.1.59]

++ ++

Prepare to install software (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> export 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> [small SRC. 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? Name1_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> [install gcc, gcc-c ++]

[Html]View plaincopyprint?

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

 

2> [open ports 80, 3306, and 22]

[Html]View plaincopyprint?

  1. # Disable the Firewall
  2. Service iptables stop
  3. Vi/etc/sysconfig/iptables
  4. # Add
  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. # Restarting the Firewall
  9. Service iptables restart

 

3> [Create a lamp/src directory and upload the source code package] 4> [install 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

 

5> [install 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

 

6> [install libxml2-devel]

[Html]View plaincopyprint?

  1. Yum install libxml2-devel

 

7> [install 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

 

8> [install 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

 

9> [install composer SRC. v6b]

[Html]View plaincopyprint?

  1. Mkdir/usr/local/limit 6
  2. Mkdir/usr/local/partition 6/bin
  3. Mkdir/usr/local/IPv6/lib
  4. Mkdir/usr/local/users 6/include
  5. Mkdir-p/usr/local/users 6/man/man1
  6. Tar-zxvf restart src.v6b.tar.gz
  7. Cd jpeg-6b
  8. ./Configure -- prefix =/usr/local/configure 6/-- enable-shared -- enable-static
  9. Make
  10. Make install

 

10> [install 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

 

11> [install autoconf]

[Html]View plaincopyprint?

  1. Tar-zxvf autoconf-2.61.tar.gz
  2. Cd autoconf-2.61
  3. ./Configure
  4. Make
  5. Make install

 

12> [install 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/versions 6/-- with-freetype =/usr/local/freetype/
  4. Make
  5. 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

 

14> [install 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

 

15> [install nginx]

[Html]View plaincopyprint?

  1. Groupadd www
  2. Useradd-g 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

 

16> [install 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

 

17> [install mysql]

[Html]View plaincopyprint?

  1. Groupadd mysql
  2. Useradd-g 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. # Configuring mysql
  21. Cd/usr/local/mysql
  22. # Simple test
  23. Bin/mysqladmin version
  24. # View all mysql Parameters
  25. Bin/mysqladmin Variables
  26. # Directly log on to the server without a password
  27. Bin/mysql-uroot
  28. Delete from mysql. user WHERE Host = 'localhost' AND User = '';
  29. Flush privileges;
  30. # Set the root password to 123456
  31. Set password for 'root' @ 'localhost' = PASSWORD ('123 ');
  32. # Configure remote connection to 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 = '2017. 0.0.1 ';
  37. UPDATE user SET host = '%' WHERE user = 'root ';
  38. # Restart mysql
  39. Service mysqld restart

 

18> [install 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/defaults 6/-- 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. # Modifying php-fpm.conf
  9. 6/usr/local/php/etc/php-fpm.conf
  10. # Search for lines and remove comments
  11. Nobody
  12. Nobody
  13. # Start php
  14. /Usr/local/php/sbin/php-fpm start

 

19> [nginx configuration]

[Html]View plaincopyprint?

  1. Vi/usr/local/nginx/conf/nginx. conf
  2. # Locate the location/modify the path for parsing the PHP file under the server and change it:
  3. Location /{
  4. Root/var/www/html;
  5. Index index.html index.htm index. php;
  6. }
  7. # Root indicates that the virtual directory is set to/var/www/html, and the default resolution index. php is added.
  8. # Locate location ~ under server ~ /. Php $ modify the FastCGI configuration of the php interpreter:
  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. # Add nginx to auto-start
  17. Echo "/usr/local/nginx/sbin/nginx">/etc/rc. d/rc. local
  18. # Add php to auto-start
  19. Echo "/usr/local/php/sbin/php-fpm start">/etc/rc. d/rc. local

 

20> [nginx virtual host configuration]

Vi/usr/local/nginx/conf/nginx. conf # Add include/usr/local/nginx/conf/vhost/dev_localhost.config to the last line of http; # rewrite without 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. }

 

# 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. }

 

[Html]View plaincopyprint?

  1. # Restart nginx
  2. /Usr/local/nginx/sbin/nginx-s reload
  3. # Restart php
  4. /Usr/local/php/sbin/php-fpm restart

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.