基于CentOS安装LNMP
LNMP:是指一组通常一起使用来运行动态网站或者服务器的自由软件名称首字母缩写。L指Linux,N指Nginx,M一般指MySQL,也可以指MariaDB,P一般指PHP。 本实验在Cenots上搭建 LNMP 环境。
安装Nginx
使用yum安装Nginx:
yum install Nginx -y修改配置
点击/etc/nginx/conf.d/default.conf打开,编辑完成后进行保存
windows环境下ctrl+s进行保存
Mac 环境下 command+s进行保存
去除对IPv6地址的监听,可参考下面的代码示例:
server {listen 80 default_server;# listen [::]:80 default_server;server_name _;root /usr/share/nginx/html;# Load configuration files for the default server block.include /etc/nginx/default.d/*.conf;location / {}error_page 404 /404.html;location = /40x.html {}error_page 500 502 503 504 /50x.html;location = /50x.html {}}Nginx 自启动配置
配置修改后,需要对nginx进行启动
nginx将Nginx设置为开机自启动
chkconfig nginx on启动后,我们可访问 来确定安装是否成功
安装MySql
使用Yum安装mysql:
yum install mysql-server -y将MySql设置为开机自启动
chkconfig mysqld on重启Mysql服务
service mysqld restart设置MySql root的账户密码
/usr/bin/mysqladmin -u root password '123456'安装PHP
使用yum安装php
yum install php php-fpm php-mysql -y等待PHP安装完成后,启动PHP-FPM进程
service php-fpm startPHP-FPM启动之后,可以使用下面的命令查看PHP-FPM进程监听哪个端口
netstat -nlpt | grep php-fpm配置php.conf
新建一个php.conf文件
touch /etc/nginx/conf.d/php.conf修改php.conf文件,并配置Nginx端口,配置示例如下:
server {listen 8000;# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000location ~ \.php$ {root /usr/share/php;fastcgi_pass 127.0.0.1:9000;fastcgi_index index.php;fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;include fastcgi_params;}}编辑完成后,请进行保存
windows环境下ctrl+s进行保存
Mac 环境下 command+s进行保存
设置PHP-FPM为开机启动
chkconfig php-fpm onNginx重启
修改配置信息后,需要对Nginx服务进行重新启动
service Nginx restart配置info.php
新建php.info文件
touch /usr/share/php/info.php在info.php中添加代码来检查php是否安装成功
<?php phpinfo();?>编辑完成后,进行保存
windows环境下ctrl+s进行保存
Mac 环境下 command+s进行保存
访问http://XXX.XXX.XXX.XXX:8000/info.php 可浏览刚刚创建的info页面
