知识改变命运,行动创造未来。
1.安装部署Nginx
安装前准备
yum -y install pcre-devel zlib-devel openssl openssl-devel
添加nginx用户
useradd -s /sbin/nologin nginx -M
编译安装nginx
tar zxf nginx-$NVERSION.tar.gz -C /usr/src/./configure--user=nginx --group=nginx --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module make -j 4make install
配置nginx
cp/usr/local/nginx/conf/nginx.conf/usr/local/nginx/conf/nginx.conf.defaultln -s /usr/local/nginx/sbin/nginx /usr/sbin
配置nginx支持php
user nginx;worker_processes 8;
events { worker_connections 1024;}http { include mime.types; default_type application/octet-stream;sendfile on;keepalive_timeout 65;server { listen 80; server_name localhost;
location / { root html; index index.html index.htm; }
location ~ \.(php|php5)?$ { root /usr/local/nginx/html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; #fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; fastcgi_paramSCRIPT_FILENAME/usr/local/nginx/html$fastcgi_script_name; include fastcgi_params; }
error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } }}
2.安装部署MySQL
卸载旧版本mysql
rpm -e mysql --nodepsrpm -e mysql-server --nodeps
安装cmake和ncurses-devel工具
yum -y install cmake ncurses-devel
添加系统用户
useradd -s /sbin/nologin -M mysql
编译安装MySQL
tar zxf mysql-$MVERSION.tar.gz -C /usr/src/cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DSYSCONFDIR=/etc -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS=allmake -j 4make install
配置
chown -R mysql:mysql /usr/local/mysql/ #设置属主属组mv /etc/my.cnf /etc/my.cnf.old #更改原始配置文件cp support-files/my-medium.cnf /etc/my.cnf #生成新的配置文件/usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/#初始化数据库echo "PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile #设置环境变量. /etc/profile #生效配置变量cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld #生成服务脚本chmod +x /etc/init.d/mysqld #添加执行权限chkconfig --add mysqld
3.安装PHP
准备安装环境
yum -y install zlib-devel libxml2-devel libjpeg-turbo-devel freetype-devel libpng-devel gd-devel libcurl-devel
编译安装php
tar zxf php-$PVERSION.tar.gz -C /usr/src/./configure --prefix=/usr/local/php --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-fpm --enable-mbstring --with-gd --with-gettext --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --enable-short-tags --enable-static --with-fpm-user=nginx --with-fpm-group=nginx --enable-fpm --enable-ftp --enable-opcache=yesmake -j 4make install
配置php
cp/usr/src/php-$PVERSION/php.ini-production /usr/local/php/php.inicd /usr/local/php/etc/cp php-fpm.conf.default php-fpm.conf
4.启动服务
启动nginx
nginxfirewall-cmd --zone=public --add-port=80/tcp --permanentfirewall-cmd --reloadnetstat -anlpt | grep nginx
启动mysql
service mysqld startchkconfig mysqld onnetstat -anlpt | grep mysqld
启动php-fpm
/usr/local/php/sbin/php-fpm netstat -anlpt | grep php-fpm
5.测试LNMP
编辑测试页面
echo "<?php phpinfo(); ?> " > /usr/local/nginx/html/index.php
访问测试
感谢查阅,欢迎你给我留言,也欢迎分享更多的朋友一起阅读!