Home  >  Article  >  Backend Development  >  LNMP source code installation for nginx-181+mysql-5711+php-5533 environment under CentOS7

LNMP source code installation for nginx-181+mysql-5711+php-5533 environment under CentOS7

WBOY
WBOYOriginal
2016-07-30 13:29:291468browse

Install lnmp environment:
The environment is CentOS7 minimal installation. During installation, several development tools such as Development tools were selected (can’t remember the details)
nginx-1.8.1 mysql-5.7.11 php-5.5.33
Requirements:
The data files and log files of MYSQL and NGINX are placed under /data
The installation directory also needs to be changed to /data/webserver
1. Download the installation package and configure the installation dependency environment
Set the firewall open port 80 3306
# firewall-cmd -- z --add-port=80/tcp --permanent
# firewall-cmd --z --add-port=3306/tcp --permanent
# firewall-cmd --reload
Configure selinux settings
# vi /etc /selinux/config
# This file controls the state of 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 two values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
#SELINUXTYPE=targeted
Restart the system
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 (supports 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 (Boost library is required starting from MySQL 5.7.5)
#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 keyutils 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 ncurses* libtool* libxml2 libxml2-devel patch mhash ntp --skip-broken
2. Install mysql
1. Unzip the installation package:
#cd /data/webserver/src
#ls *.tar.gz |xargs -n1 tar zxf
2. Install 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 #Copy the configuration file (note: there is a my.cnf under the /etc directory by default, just overwrite it directly)
#/data/webserver/mysql/bin/mysqld --initialize --user=mysql --datadir=/data/mysqldb --basedir=/data/webserver/mysql/ --socket=/tmp/mysql.sock#Initialize the mysql server. Note that a string of garbled mysql passwords will be generated, 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 #Add Mysql to system startup
#chmod 755 /etc/init.d/mysqld #Add execution permissions
#chkconfig mysqld on #Add to boot
#vi /etc/rc. d/init.d/mysqld #Edit
basedir = /data/webserver/mysql #MySQL program installation path
datadir = /data/mysqldb #MySQl database storage directory
#/etc/init.d/mysqld start #Start
# /data/webserver/mysql/bin/mysql -uroot -p #Log in to mysql
>set password=password('zhulong123'); #Change password
#vi /etc/profile #Add the mysql service to the system environment variable: in Finally, add the following line
export PATH=$PATH:/data/webserver/mysql/bin 
The following two lines link the myslq library file to the default location of the system, so that you do not need to specify mysql when compiling software such as PHP. The library file address.  
#ln -s /data/webserver/mysql/lib/mysql /usr/lib/mysql  
#ln -s /data/webserver/mysql/include/mysql /usr/include/mysql    
三、安装nginx
1、安装PCRE
#cd /data/webserver/src/pcre-8.35
#./configure --prefix=/data/webserver/pcre 
#make  && make install
#systemctl enable  ntpd.service
#systemctl start ntpd
2、安装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
修改配置文件:
#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、设置nginx自启动,加入以下脚本
#!/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 is 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 "$1" 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
建立服务文件
# 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
四、安装php
1、安装libmcrypt
#cd /data/webserver/src/libmcrypt-2.5.8
#./configure
#make
#nake install
2、安装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、配置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-fpm的配置文件
#vi /data/webserver/php/etc/php-fpm.conf
user = www #设置php-fpm运行账号为www 
group = www #设置php-fpm运行组为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#拷贝php-fpm到启动目录
#chmod +x /etc/rc.d/init.d/php-fpm #添加执行权限
#chkconfig php-fpm on #设置开机启动
#vi /data/webserver/php/etc/php.ini #编辑配置文件
修改为:date.timezone = PRC #设置时区
4、配置nginx支持php 
#vi /data/webserver/nginx/conf/nginx.conf #编辑配置文件,需做如下修改
user www www; #首行user去掉注释,修改Nginx运行组为www,www;必须与/usr/local/php5/etc/php-fpm.conf中的user,group配置相同,否则php运行出错 
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 server部分location的注释,并要注意fastcgi_param行的参数,改为
$document_root$fastcgi_script_name,或者使用绝对路径
/etc/init.d/nginx restart #重启nginx 
五、测试
#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 #重启系统

以上就介绍了CentOS7下nginx-181+mysql-5711+php-5533环境的LNMP源码安装,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:34 PHP classesNext article:34 PHP classes