Build linux+nginx+mysql+php Environment

Source: Internet
Author: User
Tags fpm openssl iptables

Tag: Cal State stop TCP sys strong min related useradd

Description:Operating system: CentOS 5.6 32-bit prepare the article:First, configure the IP, DNS, gateway, to ensure the use of remote connection tools to connect the server II, configure the firewall, open 80 port, 3306 Port vi/etc/sysconfig/iptables-a input-m State--state new-m tcp-p t CP--dport 80-j Accept #允许80端口通过防火墙-A input-m State--state new-m tcp-p TCP--dport 3306-j accept #允许3306端口通过防火墙特别提示: Many netizens add these two rules to the last line of the firewall configuration, causing the firewall to fail to start, the correct one should be added to the default port 22 after the rule is added after the firewall rule as follows: ###################################### #################### Firewall configuration written by system-config-firewall# Manual customization of the This file was not re Commended.*filter:input Accept [0:0]:forward Accept [0:0]:output Accept [0:0]-a input-m State--state Established,relate D -j ACCEPT-A INPUT -p icmp -j ACCEPT-A INPUT -i lo -j ACCEPT-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACC Ept-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 330 6-j accept-a input-j REJECT--reject-with icmp-host-prohibited-a forward-j REJECT--reject-with Icmp-host-prohibitedCOM mit#########################################################/etc/init.d/iptables Restart #最后重启防火墙使配置生效三, close selinuxvi/etc/selinux/config#selinux= Enforcing #注释掉 #selinuxtype=targeted #注释掉SELINUX =disabled #增加: Wq save, close shutdown-r now #重启系统四, System contract software source code package storage location:/usr/local /SRC Source Package Compilation installation location:/usr/local/software name five, Package nginx-1.2.2.tar.gz,mysql-5.5.25a.tar.gz,php-5.3.5.tar.gz,libmcrypt-2.5.8.tar.gz Installation: Installing Mysqlgroupadd MySQL   #添加mysql组useradd-G MySQL mysql-s/bin/false  #创建用户mysql并加入到mysql组, does not allow MySQL users to log in directly to the system Mkdir-p/data/mysql   #创建MySQL数据库存放目录chown-R mysql:mysql/data/mysql  #设置MySQL数据库目录权限mkdir-P/usr/local/mysql # Create the MySQL installation directory Cd/usr/local/srctar zxvf mysql-5.5.25a.tar.gz  #解压cd mysql-5.5.25acmake. -dcmake_install_prefix=/usr/local/mysql-dmysql_datadir=/data/mysql-dsysconfdir=/etc# Configuring make  #编译make INSTALL   #安装cd/USR/LOCAL/MYSQLCP ./support-files/my-huge.cnf/etc/my.cnf  #拷贝配置文件 (Note: if/ ETC directory below the default has a my.cnf, directly overwrite can) vi/etc/my.cnf  #编辑配置文件, add the following line in the [mysqld] section datadir =/data/mysql  #添加MySQL数据库路径: wq!  #保存Exit./scripts/mysql_install_db--user=mysql  #生成mysql系统数据库cp./support-files/mysql.server/etc/rc.d/init.d/ mysqld  #把Mysql加入系统启动chmod 755/etc/init.d/mysqld  #增加执行权限chkconfig mysqld on  #加入开机启动vi/etc/rc.d/ init.d/mysqld  #编辑basedir =/usr/local/mysql  #MySQL程序安装路径datadir =/data/mysql  #MySQl数据库存放目录service Mysqld start  #启动vi/etc/profile  #把mysql服务加入系统环境变量: Add the following line at the end of the export path= $PATH:/usr/local/mysql/bin:wq!   #保存退出下面这两行把myslq的库文件链接到系统默认的位置 so you don't have to specify the MySQL library file address when compiling software like PHP. Ln-s/usr/local/mysql/lib/mysql/usr/lib/mysqlln-s/usr/local/mysql/include/mysql/usr/include/mysqlshutdown-r now& nbsp, #需要重启系统, wait for the system to restart after the operation of the terminal command line mysql_secure_installation  #设置Mysql密码根据提示按Y enter and then 2 times the password continue to press Y to enter, Until setup is complete or directly modifies the password/usr/local/mysql/bin/mysqladmin-u root-p password "123456" #修改密码service mysqld restart  #重启到此, MySQL installation is complete! Installing pcrecd/usr/local/srcmkdir/usr/local/pcre  #创建安装目录tar zxvf pcre-8.31.tar.gzcd pcre-8.31./configure--prefix=/ usr/local/pcre  #配置makEmake install  Installation Nginxcd/usr/local/srcgroupadd www  #添加www组useradd-G www www-s/bin/false # Create Nginx run account www and join the WWW group, do not allow WWW users to log in directly to the system tar ZXVF nginx-1.2.2.tar.gzcd nginx-1.2.2
./configure--prefix=/usr/local/nginx--without-http_memcached_module--user=www--group=www--with-http_stub_ Status_module--with-openssl=/usr/--with-pcre=/usr/local/src/pcre-8.31
Note:--with-pcre=/usr/local/src/pcre-8.31 points to the source package decompression path, not the installation path, otherwise it will be an errorMakemake install/usr/local/nginx/sbin/nginx  #启动nginx设置nginx开启启动vi/etc/rc.d/init.d/nginx  #编辑启动文件添加下面内容 =======================================================#!/bin/bash# nginx Startup script for the Nginx HTTP server# it is v.0.0.2 version.# chkconfig:-15# Description:nginx is a high-performance web and proxy server.# It had a lot of f Eatures, but it's not for everyone.# processname:nginx# pidfile:/var/run/nginx.pid# config:/usr/local/nginx/conf/nginx . Confnginxd=/usr/local/nginx/sbin/nginxnginx_config=/usr/local/nginx/conf/nginx.confnginx_pid=/usr/local/nginx /logs/nginx.pidretval=0prog= "Nginx" # Source function library. /etc/rc.d/init.d/functions# Source Networking configuration: /etc/sysconfig/network# Check that networking are up. [${networking} = "No"] && exit 0[-x $nginxd] | | Exit 0# Start Nginx daemons Functions.start () {If [-e $nginx _pid];thenecho "Nginx already running ...." Exit 1fiecho-n $ " Starting $prog: "Daemon $nginxd-C ${nginx_config}retval=$?echo[$RETVAL = 0] && touch/var/lock/subsys/nginxreturn $RETVAL}# Stop nginx daemons functions.stop () {echo-n $ "Stopping $prog:" Killproc $nginxdRETVAL =$?echo[$RETVAL = 0] && rm-f/var/lock/subsys/nginx/usr/local/nginx/ Logs/nginx.pid}reload () {echo-n $ "reloading $prog:" #kill-hup ' cat ${nginx_pid} ' killproc $nginxd-hupretval=$?echo}# Se E How we were Called.case "$" instart) start; stop) stop;; reload) reload;; restart) Stopstart;; Status) status $progRETVAL =$?;; *) echo $ "Usage: $prog {start|stop|restart|reload|status|help}" exit 1esacexit $RETVAL  :wq!  #保存退出chmod 775/ etc/rc.d/init.d/nginx  #赋予文件执行权限chkconfig nginx on  #设置开机启动/etc/rc.d/init.d/nginx restart  #重启service Nginx restart======================================================= Installation Libmcryptcd/usr/local/srctar ZXVF libmcrypt-2.5.8.tar.gz  #解压cd libmcrypt-2.5.8  #进入目录 ./configure  #配置make   #编译make install # Installation =======================================================  Installation phPCD/USR/LOCAL/SRCTAR-ZVXF php-5.3.5.tar.gzcd php-5.3.5mkdir-p/usr/local/php5  #建立php安装目录
./configure--prefix=/usr/local/php5--with-config-file-path=/ Usr/local/php5/etc--with-mysql=/usr/local/mysql--with-mysqli=/usr/local/mysql/bin/mysql_config-- With-mysql-sock=/tmp/mysql.sock--with-gd--with-iconv--with-zlib--enable-xml--enable-bcmath--enable-shmop-- Enable-sysvsem--enable-inline-optimization--with-curlwrappers--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 #配置 
make  #编译make install  #安装cp php.ini-production/usr/local/php5/etc/php.ini  #复制php配置文件到安装目录rm-rf/etc /php.ini  #删除系统自带配置文件ln-S/usr/local/php5/etc/php.ini/etc/php.ini  #添加软链接cp/usr/local/php5/etc/ The php-fpm.conf.default/usr/local/php5/etc/php-fpm.conf# copy template file is a php-fpm configuration file vi/usr/local/php5/etc/php-fpm.conf   #编辑user = www  #设置php-fpm Run account is Wwwgroup = www  #设置php-fpm Run Group is wwwpid = run/php-fpm.pid  #取消前面的分号设置 PHP-FPM boot cp/usr/local/src/php-5.3.5/sapi/fpm/init.d.php-fpm/etc/rc.d/init.d/php-fpm# copy php-fpm to boot directory chmod +x/ etc/rc.d/init.d/php-fpm  #添加执行权限chkconfig php-fpm on  #设置开机启动vi/usr/local/php5/etc/php.ini # Edit config file found: disable_functions = modified to:
disable_functions = Passthru,exec,system,chroot,scandir,chgrp, Chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink, Popepassthru,stream_socket_server,escapeshellcmd,dll,popen,disk_free_space,checkdnsrr,checkdnsrr,getservbyname , GETSERVBYPORT,DISK_TOTAL_SPACE,POSIX_CTERMID,POSIX_GET_LAST_ERROR,POSIX_GETCWD, Posix_getegid,posix_geteuid, Posix_getgid, Posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_ Getpid, Posix_getppid,posix_getpwnam,posix_getpwuid, Posix_getrlimit, Posix_getsid,posix_getuid,posix_isatty, Posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid, Posix_setpgid,posix_setsid,posix_setuid,posix _strerror,posix_times,posix_ttyname,posix_uname 
======================================================= configuration Nginx Support phpvi/usr/local/nginx/conf/nginx.conf #编辑配置文件, Need to make the following changes user www www; #首行user去掉注释, modify the Nginx run group to www www; must be the same as the User,group configuration in/usr/local/php5/etc/php-fpm.conf, or PHP will run in error


Location/{
root/usr/local/nginx/html;
Index index. PHP index.html index.htm;
}

Location ~ \.php$ {
Try_files $uri = 404;
Fastcgi_pass 127.0.0.1:9000;
Fastcgi_index index.php;
Fastcgi_param script_filename/usr/local/nginx/html/$fastcgi _script_name;
Include Fastcgi_params;
}

#取消FastCGI the comment for the server section location, and note the parameters of the Fastcgi_param row, change to $document_root$fastcgi_script_name, or use an absolute path/etc/init.d/ Nginx Restart #重启nginx Test Articlecd/usr/local/nginx/html/#进入nginx默认网站根目录rm-rf/usr/local/nginx/html/* #删除默认测试页vi index.php #编辑 <?phpphpinfo ();? >:wq! #保存退出chown www.www/usr/local/nginx/html/-R #设置目录所有者chmod 700/usr/local/nginx/html/-R #设置目录权限shutdown-R now #重启系统在浏览器 Open the server IP address, you will see the following interface, configure successful server-related Operations Command service nginx restart #重启nginxservice mysqld restart #重启mysql/usr/local/php5/sbin/ PHP-FPM #启动php-fpm/etc/rc.d/init.d/php-fpm Restart #重启php-fpm/etc/rc.d/init.d/php-fpm stop #停止php-fpm/etc/rc.d/ INIT.D/PHP-FPM Start #启动php-fpm############################################################################# Note: Nginx Default Site Directory is:/usr/local/nginx/html/permission settings: chown www:www/usr/local/nginx/html/-rmysql Database directory is:/data/ MySQL permissions settings: Chown mysql.mysql-r/data/mysql turn: http://www.cnblogs.com/jsIT/articles/3420512.html

Build linux+nginx+mysql+php Environment

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.