CentOS 6.5 production environment compiled and installed LNMP

Source: Internet
Author: User
Tags fpm ftp gettext install php openssl php file iptables mysql database
First, environment preparation 1, operating system installation: CentOS 6.5 64-bit minimal installation. 2. Configure IP, DNS, Gateway, hostname 3, configure firewall, open 80, 3306 port vim/etc/sysconfig/iptables-a rh-firewall-1-input-m State--state new-m tcp-p t CP--dport 80-j Accept #允许80端口通过防火墙-A rh-firewall-1-input-m State--state new-m tcp-p TCP--dport 3306-j accept #允许3
306 port through the firewall special prompt: If these two rules added to the last line of firewall configuration, causing the firewall to fail to start, the correct should be added to the default 22 port. /etc/init.d/iptables Restart #最后重启防火墙使配置生效 4, close SELinux vi/etc/selinux/configurations #SELINUX =enforcing #注释掉 # selinuxtype=targeted #注释掉 selinux=disabled #增加: wq! #保存退出 Setenforce 0 #使配置立即生效 Two, the system contract hard disk partition: 50G (/boot 200m/swap 8192M/) +100g (/opt) software source code package location:/OPT/LOCAL/SRC source Package Compilation installation Location:/opt /local/software name database data file storage path/opt/local/mysql/var, package download 1, download nginx (currently stable version): http://nginx.org/download/nginx-1.4.4.tar.gz 2 , download pcre (support nginx pseudo static): ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.34.tar.gz 3, download mysql:http://
cdn.mysql.com/downloads/mysql-5.5/mysql-5.5.35.tar.gz 4, download php:http://cn2.php.net/distributions/php-5.5.7.tar.gz 5. Download CMake (MySQL compilation tool): http://www.cmake.org/files/v2.8/cmake-2.8.12.1.tar.gz 6, download Libmcrypt (phplibmcrypt module): http://nchc.dl.sourceforge.net/project/ mcrypt/libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz 7, download GD Library installation package (PHP page image Verification Code support): https://phpsqq.googlecode.com/files/ Gd-2.0.36rc1.tar.gz upload the above package to/OPT/LOCAL/SRC Directory IV, install the compilation tools and library files using the CentOS Yum command one-click Install Yum install-y make apr* autoconf automake C URL curl-devel gcc gcc-c++ gtk+-devel zlib-devel OpenSSL openssl-devel pcre-devel gd kernel keyutils patch Perl Kernel-hea DERs compat* cpp glibc libgomp libstdc++-devel keyutils-libs-devel libsepol-devel libselinux-devel krb5-devel libXpm* fre EType freetype-devel freetype* fontconfig fontconfig-devel libjpeg* libpng* php-common php-gd gettext gettext-devel ncurs es* libtool* libxml2 libxml2-devel patch policycoreutils Bison V, Software Installation Chapter 1, installation CMake cd/opt/local/src tar zxvf cmake-2.8.8.ta 
r.gz CD cmake-2.8.8./configure--prefix=/opt/local/cmake make #编译 make install #安装 vim/etc/profile add cmake to execute file path in Path path Export path= $PATH:/opt/local/cmake/bin source/etc/pRofile make configuration effective immediately 2, install Pcre cd/opt/local/src mkdir/usr/local/pcre #创建安装目录 tar zxvf pcre-8.34.tar.gz cd pcre-8.34./configure  --prefix=/opt/local/pcre #配置 make && make install 3, install Libmcrypt cd/opt/local/src tar zxvf libmcrypt-2.5.8.tar.gz #解压 CD libmcrypt-2.5.8 #进入目录./configure #配置 make #编译 make install #安装 4, install GD library CD/OPT/LOCAL/SRC tar zxvf gd-2.0.36rc1.ta r.gz CD gd-2.0.36rc1./configure--enable-m4_pattern_allow-prefix=/opt/local/gd--with-jpeg=/usr/lib--with-png=/usr /lib--with-xpm=/usr/lib--with-freetype=/usr/lib--with-fontconfig=/usr/lib #配置 make #编译 make install #安装 5, install MySQL Grou Padd 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/opt/data/mysql/v Ar #创建MySQL数据库存放目录 chown-r mysql:mysql/opt/data/mysql/var #设置MySQL数据库目录权限 cd/opt/local/src tar zxvf mysql-5.5.35.tar.g Z #解压 CD mysql-5.5.35 cmake. -dcmake_install_prefix=/opt/local/mysql-dmysql_datadir=/opt/data/mysql/var-dsysconfdir=/etc #配置 make #编译 make
Install #安装Cd/opt/local/mysql CP./SUPPORT-FILES/MY-HUGE.CNF/ETC/MY.CNF #拷贝配置文件 (Note: If the/etc directory has a my.cnf under the default, you can directly overwrite it) vi/etc/ My.cnf #编辑配置文件, add datadir =/opt/data/mysql/var #添加MySQL数据库路径 in the [mysqld] section./scripts/mysql_install_db--user=mysql # Generate the MySQL system database CP./SUPPORT-FILES/MYSQL.SERVER/ETC/RC.D/INIT.D/MYSQLD #把Mysql加入系统启动 chmod 755/etc/init.d/mysqld # Add execution Permissions chkconfig mysqld on #加入开机启动 vi/etc/rc.d/init.d/mysqld #编辑 basedir =/opt/local/mysql #MySQL程序安装路径 DataDir =/opt/l Ocal/mysql/var #MySQl数据库存放目录 service mysqld start #启动 vi/etc/profile #把mysql服务加入系统环境变量: Add the following line at the end of the export path= $PATH:/ Opt/local/cmake/bin:/opt/local/mysql/bin source/etc/profile #使配置立即生效 mkdir/var/lib/mysql #创建目录 ln-s/tmp/mysql.sock/ Var/lib/mysql/mysql.sock #添加软链接 mysql_secure_installation #设置Mysql密码, press Y to enter the password 2 times if prompted/opt/local/mysql/bin/
mysqladmin-u root-p Password "123456" #或者直接修改密码 to this, MySQL installation is complete.
6, installation nginx cd/opt/local/src groupadd www #添加www组 useradd-g www www-s/bin/false #创建nginx运行账户www并加入到www组, www users are not allowed to log in directly to the system Tar ZXVF nginx-1.4.4.tar.gz CD nginx-1.4.4./configure--prefix=/opt/local/nginx--without-http_memcached_module--user=www --group=www--with-http_stub_status_module--with-openssl=/usr/--with-pcre=/opt/local/src/pcre-8.31 Note:-- with-pcre=/opt/local/src/pcre-8.34 points to the source package decompression path, not the installation path, otherwise will be error make makes Install/opt/local/nginx/sbin/nginx #
Start Nginx setup nginx to start 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:-Description:nginx is a high-performance Web and proxy server.
# It has a lot of features, but it's not for everyone. # Processname:nginx # pidfile:/var/run/nginx.pid # config:/usr/local/nginx/conf/nginx.conf nginxd=/opt/local/nginx/ Sbin/nginx nginx_config=/opt/local/nginx/conf/nginx.conf nginx_pid=/opt/local/nginx/logs/nginx.pid RETVAL=0 prog= "
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];then echo "Nginx already running ...." Exit 1 Fi echo-n $ "Starting $prog:" Daemon $nginxd
-C ${nginx_config} retval=$?
echo [$RETVAL = 0] && touch/var/lock/subsys/nginx return $RETVAL} # Stop Nginx daemons functions.
Stop () {echo-n $ "stopping $prog:" Killproc $nginxd retval=$? echo [$RETVAL = 0] && rm-f/var/lock/subsys/nginx/usr/local/nginx/logs/nginx.pid} reload () {Echo-n $ "reload
ing $prog: "#kill-hup ' cat ${nginx_pid} ' Killproc $nginxd-hup retval=$?
echo} # See how we were called.
Case "$" in start) start;
stop) stop;;
reload) reload;;
restart) stop start;;
Status) status $prog retval=$?;; *) echo $ "Usage: $prog {start|stop|restart|reload|status|help}" Exit 1 Esac exit $RETVAL =============================== ========================: wq! #保存退出 chmod 775/etc/rc.d/init.d/nginx #赋予文件执行权限 chkconfig nginx on #设置开机启动/etc/rc.d/init.d/nginx restart #重新启动Nginx service Nginx rest Art ======================================================= 7, install PHP cd/opt/local/src tar-zvxf php-5.5.7.tar.gz CD php-5.5.7./configure--prefix=/opt/local/php5--with-config-file-path=/opt/local/php5/etc--with-mysql=/opt/ Local/mysql--with-mysql-sock=/tmp/mysql.sock--with-gd--with-iconv--with-zlib--enable-xml--enable-bcmath-- Enable-shmop--enable-sysvsem--enable-inline-optimization--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--with-jpeg-dir-- With-freetype-dir make #编译 make install #安装 cp Php.ini-production/opt/local/php5/etc/php.ini #复制php配置文件到安装目录 rm-rf/etc /php.ini #删除系统自带配置文件 ln-s/opt/local/php5/etc/php.ini/etc/php.ini #添加软链接 cp/opt/local/php5/etc/php-fpm.conf.default/opt/local/php5/etc/php-fpm.conf #拷贝模板文件为php-fpm configuration file vi/opt/local/php5/etc/php-fpm.conf #编辑 user = www #设置php-fpm run account is www group = www #设置php-fpm run Group for www pid = run/php-fpm.pid #取消前面的分号 set php-fpm boot start CP/OPT/LOCAL/SR C/PHP-5.5.7/SAPI/FPM/INIT.D.PHP-FPM/ETC/RC.D/INIT.D/PHP-FPM #拷贝php-fpm to startup directory chmod +X/ETC/RC.D/INIT.D/PHP-FPM #  Add Execute Permissions chkconfig php-fpm on #设置开机启动 vi/opt/local/php5/etc/php.ini #编辑配置文件 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 # List the functions php can disable, if some programs need to use this function, you can delete, cancel disable find:;d Ate.timezone = modified to: Date.timezone = PRC #设置时区 found: expose_php = on modified to: Expose_ php = off #禁止显示php版本的信息 found: Short_open_tag = Off modified to: Short_open_tag = On #支持php短标签 Eight, configuring Nginx support PHP vi/opt/local/nginx/conf/ nginx.conf Modify the/opt/local/nginx/conf/nginx.conf configuration file, you need to make the following changes user www www;
#首行user去掉注释, modify the Nginx run Group for www www, must be the same as the User,group configuration in/opt/local/php/etc/php-fpm.conf, or PHP will run error user www www;
Worker_processes 1; events {worker_connections;} http {include mime.types; Default_type application/octet-stream; sendfile on; Keepali
Ve_timeout 65; server {Listen, server_name localhost, location/{root HTML, index index.php index.html index.htm;} location ~ \.ph p$ {root html; fastcgi_pass 127.0.0.1:9000; Fastcgi_index index.php; fastcgi_parAm Script_filename $document _root$fastcgi_script_name;
Include Fastcgi_params; }}}/etc/init.d/nginx restart #重启nginx VI, test article cd/opt/local/nginx/html/#进入nginx默认网站根目录 rm-rf/opt/local/nginx/html/* #删 In addition to the default test page VI index.php #新建index. php file Phpinfo ();?>: wq! #保存退出 chown www.www/opt/local/nginx/html/-R #设置目录所有者 chmod 700/opt/local/nginx/html/-R #设置目录权限 Seven, other instructions server-related Operations Command Servic E nginx Restart #重启nginx service mysqld restart #重启mysql/usr/local/php/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 nginx default Site Directory is:/ opt/local/nginx/html/permission settings: Chown www.www/opt/local/nginx/html/-R MySQL database directory is:/opt/local/mysql/var permission settings: chown
Mysql.mysql-r/opt/local/mysql/var Eight, security optimization sherwin@rocnic~ $ssh root@172.16.134.141 root@172.16.134.141 ' s password: Last Login:sat Jan 12:11:57 from 172.16.134.1-bash:warning:setlocale:lc_ctype:cannot change locale (UTF-8): No such file or directory [Root@dev~]# locale Locale:cannot set LC_CTYPE to default locale:no such file or directory Locale:cannot set Lc_all to Defaul T locale:no such file or directory Lang=en_us. UTF-8 lc_ctype=utf-8 lc_numeric= "en_US. UTF-8 "Lc_time=" en_US. UTF-8 "Lc_collate=&qu
Related Article

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.