Install LNMP Environment:
The environment is CentOS7 minimized installation, the installation of development tools and other tools to choose a few (specifically remember)
nginx-1.8.1 mysql-5.7.11 php-5.5.33
Requirements:
MySQL and nginx data files, log files placed under/data
The installation directory also needs to be changed to/data/webserver
One, download the installation package and configure the installation dependent environment
Set firewall open port 80 3306
# firewall-cmd--z--add-port=80/tcp--permanent
# firewall-cmd--z--add-port=3306/tcp--permanent
# Firewall-cmd--reload
Configuring SELinux Settings
# Vi/etc/selinux/config
# This file controls the state of the SELinux on the system.
# selinux= can take one of these three values:
# Enforcing-selinux security policy is enforced.
# Permissive-selinux Prints warnings instead of enforcing.
# disabled-no SELinux policy is loaded.
Selinux=disabled
# selinuxtype= can take one of three the values:
# targeted-targeted processes is protected,
# Minimum-modification of targeted policy. Only selected processes is protected.
# Mls-multi level Security protection.
#SELINUXTYPE =targeted
Rebooting the system
To create the installation directory:
#mkdir-P/data/webserver/nginx
#mkdir/data/webserver/mysql
#mkdir/data/webserver/php
#mkdir/data/webserver/src (software download directory)
#mkdir/data/mysqldb (MySQL data storage directory)
Download MySQL
#wget http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.11.tar.gz
Download PHP
#wget http://cn2.php.net/distributions/php-5.5.33.tar.gz
Download Nginx
#wget http://nginx.org/download/nginx-1.8.1.tar.gz
Download CMake (MySQL compilation tool)
#wget http://www.cmake.org/files/v2.8/cmake-2.8.8.tar.gz
Download pcre (support nginx pseudo static)
#wget http://sourceforge.net/projects/pcre/files/pcre/8.35/pcre-8.35.tar.gz
Download Libmcrypt (phplibmcrypt module)
#wget http://nchc.dl.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz
Download boost (from MySQL 5.7.5 to start boost Library is required)
#wget http://downloads.sourceforge.net/project/boost/boost/1.59.0/boost_1_59_0.tar.gz
#yum-y install make apr* autoconf automake curl-devel gcc gcc-c++ zlib-devel OpenSSL openssl-devel pcre-devel gd kernel K Eyutils Patch perl kernel-headers compat* MPFR cpp glibc libgomp libstdc++-devel ppl cloog-ppl keyutils-libs-devel libcom_ Err-devel libsepol-devel libselinux-devel krb5-devel zlib-devel libxpm* freetype libjpeg* libpng* php-common php-gd ncurs es* libtool* libxml2 libxml2-devel patch Mhash NTP--skip-broken
Second, install MySQL
1. Unpack the installation package:
#cd/DATA/WEBSERVER/SRC
#ls *.tar.gz |xargs-n1 Tar zxf
2, installation CMake:
#cd/data/webserver/src/cmake-2.8.8
#./configure
#gmake && gmake Install
3. Install MySQL:
#cd/data/webserver/src/mysql-5.7.11
#cmake. -dcmake_install_prefix=/data/webserver/mysql-dmysql_datadir=/data/mysqldb-dsysc-dwith_boost=. /boost_1_59_0-ddownload_boost=1
#make && make Install
4. Configure MySQL
# Groupadd MySQL
# useradd-g mysql-s/sbin/nologin MySQL
#cp/data/webserver/mysql/support-files/my-default.cnf/etc/my.cnf #拷贝配置文件 (Note: the/etc directory has a my.cnf under the default, can be directly overwritten)
#/data/webserver/mysql/bin/mysqld--initialize--user=mysql--datadir=/data/mysqldb--basedir=/data/webserver/ mysql/--socket=/tmp/mysql.sock# Initialize MySQL server note will generate a string of MySQL password garbled such as:q>d,< (uj9*9j
Get password: A temporary password is generated for root@localhost:q>d,< (uj9*9j
#cp/data/webserver/mysql/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 =/data/webserver/mysql #MySQL程序安装路径
DataDir =/data/mysqldb #MySQl数据库存放目录
#/etc/init.d/mysqld Start #启动
#/data/webserver/mysql/bin/mysql-uroot-p #登陆mysql
>set Password=password (' zhulong123 '); #修改密码
#vi/etc/profile #把mysql服务加入系统环境变量: Add the following line at the end
Export path= $PATH:/data/webserver/mysql/bin
The following two lines link the MYSLQ library file to the default location of the system, so you can compile software like PHP without specifying the MySQL library file address.
#ln-S/data/webserver/mysql/lib/mysql/usr/lib/mysql
#ln-S/data/webserver/mysql/include/mysql/usr/include/mysql
Third, install Nginx
1, installation Pcre
#cd/data/webserver/src/pcre-8.35
#./configure--prefix=/data/webserver/pcre
#make && make Install
#systemctl Enable Ntpd.service
#systemctl Start NTPD
2. Installing Nginx
#groupadd www
#useradd-G www www-s/bin/false
#cd/data/webserver/src/nginx-1.8.1
#./configure--prefix=/data/webserver/nginx--without-http_memcached_module--error-log-path=/data/logs/nginx/ Error.log--http-log-path=/data/logs/nginx/error.log--pid-path=/data/logs/nginx--user=www--group=www--with-http _stub_status_module--with-openssl=/usr/--with-pcre=/data/webserver/src/pcre-8.35
#make && make Install
To modify a configuration file:
#vi/data/webserver/nginx/conf/nginx.conf
#修改nginx日志文件的目录
User www www;
Worker_processes 1;
Error_log/data/logs/nginx/error.log;
Error_log/data/logs/nginx/error.log notice;
Error_log/data/logs/nginx/error.log info;
Pid/var/run/nginx.pid;
Events {
Worker_connections 1024;
}
3, set Nginx self-boot, add the following script
#!/bin/bash
# nginx Startup script for the Nginx HTTP Server
# It is v.0.0.2 version.
# Chkconfig:-85 15
# 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=/data/webserver/nginx/sbin/nginx
Nginx_c/webserver/nginx/conf/nginx.conf
Nginx_pid=/var/run/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/data/logs/nginx/nginx.pid
}
# Reload Nginx service functions.
Reload () {
Echo-n $ "Reloading $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
Create a service file
# Vim/lib/systemd/system/nginx.service
[Unit]
Description=nginx
After=network.target
[Service]
Type=forking
Execstart=/www/lanmps/init.d/nginx start
Execreload=/www/lanmps/init.d/nginx restart
Execstop=/www/lanmps/init.d/nginx stop
Privatetmp=true
[Install]
Wantedby=multi-user.target
chmod 775/etc/rc.d/init.d/nginx
Chkconfig Nginx on
/etc/rc.d/init.d/nginx restart
Service Nginx Restart
Iv. Installation of PHP
1, installation Libmcrypt
#cd/data/webserver/src/libmcrypt-2.5.8
#./configure
#make
#nake Install
2. Install PHP
#cd/data/webserver/src/php-5.5.33
#./configure--prefix=/data/webserver/php--with-config-file-path=/data/webserver/php/etc--with-mysql=/data/ Webserver/mysql--with-mysqli=/data/webserver/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--with-pear--with-gettext--enable-session- -with-mcrypt--with-curl
#make && make Install
3. Configure PHP
#cp Php.ini-production/data/webserver/php/etc/php.ini #复制php的配置文件
#rm-rf/etc/php.ini
#ln-S/data/webserver/php/etc/php.ini/etc/php.ini
#cp/data/webserver/php/etc/php-fpm.conf.default/data/webserver/php/etc/php-fpm.conf #复制php configuration file for-fpm
#vi/data/webserver/php/etc/php-fpm.conf
user = www #设置php-fpm run account is www
Group = www #设置php-fpm run Group is www
PID = Run/php-fpm.pid #取消前面的分号
#cp/data/webserver/src/php-5.5.33/sapi/fpm/init.d.php-fpm/etc/rc.d/init.d/php-fpm# copy php-fpm to startup directory
#chmod +X/ETC/RC.D/INIT.D/PHP-FPM #添加执行权限
#chkconfig PHP-FPM on #设置开机启动
#vi/data/webserver/php/etc/php.ini #编辑配置文件
Modified to: Date.timezone = PRC #设置时区
4, Configuration Nginx support PHP
#vi/data/webserver/nginx/conf/nginx.conf #编辑配置文件, you 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
Index index.php index.html index.htm; #添加index. php
# Pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
Location ~ \.php$ {
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;
}
#取消FastCGI the comment for the server section location, and note the parameters of the Fastcgi_param row, instead
$document _root$fastcgi_script_name, or use an absolute path
/etc/init.d/nginx Restart #重启nginx
V. Testing
#cd/data/webserver/nginx/html/#进入nginx默认网站根目录
#rm-rf/data/webserver/nginx/html/* #删除默认测试页
#vi index.php #编辑
Chown www.www/data/webserver/nginx/html/-R #设置目录所有者
chmod 700/data/webserver/nginx/html/-R #设置目录权限
Shutdown-r now #重启系统
The above describes the CentOS7 under the nginx-181+mysql-5711+php-5533 environment LNMP source installation, including the aspects of the content, I hope that the PHP tutorial interested friends helpful.