Linux 配置LNMP服务器 并配置虚拟主机
来源:互联网 发布:网络字母缩写 编辑:程序博客网 时间:2024/04/29 15:55
一、停止甚至删除系统上现有的web服务器软件
为了防止出现意外情况,建议先卸载现有的所有web服务器资源,如apache、mysql、php
yum remove httpd
二、安装开发包和库文件
yum -y install ntp make openssl openssl-devel pcre pcre-devel libpng libpng-devel libjpeg-6b libjpeg-devel-6b freetype freetype-devel gd gd-devel zlib zlib-devel gcc gcc-c++ libXpm libXpm-devel ncurses ncurses-devel libmcrypt libmcrypt-devel libxml2 libxml2-devel imake autoconf automake screen sysstat compat-libstdc++-33 curl curl-devel
三、安装nginx
因官方已经支持yum安装,所以采用yum安装(一是因为快,二是因为我懒,最重要的是编译安装好麻烦)
1、添加官方的nginx资源库,我是centos,其它系统去:http://nginx.org/packages/自己找
rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
2、此时可以查看nginx包信息
yum info nginx
3、安装nginx
yum install nginx
如不出现错误,则安装成功,出错了就自己解决呗(一般不会出错的,请相信我)。
配置nginx支持php,修改default.conf配置文件(我装的是nginx1.8.0版本。还有,现在还没装php呢,先配置好而已)
vi /etc/nginx/conf.d/default.conf
修改为以下内容,将以下内容前面的“#”去掉,然后改一下fastcgi_param后面的目录即可,改为default.conf的web目录地址:/usr/share/nginx/html,或者是其它的其它目录也可以,但是一定要是root(默认)的目录
location ~ \.php$ { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name;#这里写web服务器的目录地址 include fastcgi_params; }
整个default.conf配置文件如下,本文只是让php运行,其它的配置没做任何修改
server { listen 80; server_name localhost; #charset koi8-r; #access_log /var/log/nginx/log/host.access.log main; index index.php index.html index.htm; location / { root /usr/share/nginx/html; #index index.html index.htm; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ { # proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # #把下面的location的所有“#”全部删除 location ~ \.php$ { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name; include fastcgi_params; } # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /\.ht { # deny all; #}}
然后启动并设置为开机启动
systemctl start nginx #启动nginx服务systemctl enable nginx #设置nginx为开机启动
四、安装mariadb
因为centos7已用mariadb替换mysql,所以安装的是mariadb(反正mysql和mariadb没啥区别)
yum install mariadb mariadb-server
如不出错,则安装成功
然后启动并设置为开机启动
systemctl start mariadb.servicesystemctl enable mariadb.service
然后配置mariadb
mysql_secure_installation
除了让你输入新密码和确认新密码,其它一路回车即可,博主英文不好。
五、安装php
因为nginx是用FastCGI模式运行php,php-fpm是一个FastCGI管理器,所以安装的时候要选择php-fpm模块
yum install php lighttpd-fastcgi php-cli php-mysql php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-mcrypt php-mssql php-snmp php-soap php-tidy php-common php-devel php-fpm
安装完成后启动php-fpm,并且设置未开机启动,因为我这里是centos7,所以我就用7的命令操作了
systemctl start php-fpm #启动php-fpmsystemctl enable php-fpm #设置为开机启动
六、最重要当然是测试一下了
默认nginx的web路径是/usr/share/nginx/html,可以改,可以不改
在web目录下建一个php文件
vi /usr/share/nginx/html/index.php
将以下内容写入文件
<?php phpinfo();?>
如果出现激动人心的phpinfo信息,则证明lnmp配置成功,恭喜恭喜,如果出现错误,就慢慢改呗。
七、配置虚拟主机
这一步其实最简单了
把上面的default.conf复制一份(其实不复制也行,重新在default.conf最下面写一个server,不过我喜欢将不同的东西彻彻底底的分开),改改server_name和root的地址,还有和他俩相关的选项即可:
server { listen 80; server_name localtest.com; #把这里的域名改一下即可 #charset koi8-r; #access_log /var/log/nginx/log/host.access.log main; index index.php index.html index.htm; location / { root /var/www/html; #设置此虚拟主机的目录地址 #index index.html index.htm; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; #错误页面,改不改无所谓了,都用一样的呗(又暴露了我懒的本质了) } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ { # proxy_pass http://127.0.0.1; #} # 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 /var/www/html$fastcgi_script_name; #把这里的目录改成和上面root一样的 include fastcgi_params; } # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /\.ht { # deny all; #}}
怎么样,是不是和default.conf没多大区别,只是改了三个地方而已。
修改完后,重启一下nginx服务。
systemctl restart nginx
然后配一下hosts文件,重启一下网络服务,如果是在本地虚拟机或局域网安装测试的,别忘了改一下你当前物理机的hosts.
systemctl restart network
在 /var/www/html文件下建一个index.php文件,随便写点东西(懒人同胞们请复制下面的php代码),在浏览器里面输入你的设置的域名访问一下吧,哈哈,是不是出现了久违的“hello world.”,恭喜你,配置成功。
<?php echo "hello world.";?>
- Linux 配置LNMP服务器 并配置虚拟主机
- Linux 配置LNMP服务器 并配置虚拟主机
- LNMP中虚拟主机的配置
- lnmp下 nginx 配置虚拟主机
- Linux(CentOS6.x)下使用yum软件管理工具安装LNMP(Nginx+PHP+Mysql)环境并配置虚拟主机vhost
- Linux yum安装配置lnmp服务器
- 从零配置Linux服务器,部署lnmp
- lnmp服务器配置
- lnmp一键安装包配置虚拟主机
- lnmp下配置PHP虚拟主机vhost
- Apache服务器配置虚拟主机
- apache服务器配置虚拟主机
- 腾讯云服务器配置LNMP环境并安装wordpress
- LNMP服务器配置(Nginx)
- LNMP服务器配置(PHP)
- LNMP服务器配置(mysql)
- linux下配置虚拟主机
- linux lighttpd 配置虚拟主机
- ubuntu16.04 LTS解决/boot空间不足
- 分享把word转换成pdf格式的转换方法
- 【一步步学OpenGL 20】 -《点光源》
- Linux查看程序端口占用情况 netstat -apn | grep 8080
- mysql主从配置,实现读写分离
- Linux 配置LNMP服务器 并配置虚拟主机
- 双十一沦为陪跑的中小商家该如何另觅出路?
- 抽奖
- 日常生活小技巧 -- vmware workstation 无法连接到虚拟机
- 97条架构建议-道德-管家-规模
- hadoop学习之HIVE(3.1):hive建库,建表语句(DDL)
- cookie系列(二)header302跳转引发的思考
- 【CUDA】grid、block、thread的关系及thread索引的计算
- sqlite数据库查看里面数据库版本号