搭建lnmp环境
1.搭建Nginx静态服务器
– 安装Nginx
使用yum
安装Nginx
yum install nginx -y
修改/etc/nginx/conf.d/default.conf,去除对IPv6地址的监听(centos6不支持IPv6,需要取消对IPv6地址的监听,否则Nginx不能成功启动),可参考下面的代码案例
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设置为开机自动启动
chekconfig nginx on
2.安装Mysql数据库服务
– 安装mysql
使用yum
安装Mysql
yum install mysql-server -y
安装完后,启动Mysql服务
service mysqld restart
设置Mysql账户root密码
/usr/bin/mysqladmin -u root password '123456
将Mysql设置开机自动启动
chkconfig mysqld on
3.搭建php环境
– 安装php
使用yum安装php(centos6默认已安装了PHP-FPM及PHP-MYSQL,下面的命令可能提示已经安装)
yum install php php-fpm php-mysql -y
安装之后,启动PHP-FPM进程
service php-fpm start
启动之后,可以使用下面的命令查看PHP-FPM进程监听哪个端口(PHP-FPM默认监听9000端口)
nestat -nlpt | grep php-fpm
把PHP-FPM也设置成开机自启动
4.配置Nginx并运行PHP程序
– 配置Nginx
在 /etc/nginx/conf.d 目录中新建一个名为 php.conf 的文件,并配置 Nginx 端口 ,配置示例如下:
server {
listen 8000;
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ .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;
}
}
修改配置完成后,重启 nginx 服务
service nginx restart
这时候,我们就可以在/usr/share/php 目录下新建一个 info.php 文件来检查 php 是否安装成功了,文件内容参考如下:
<?php phpinfo(); ?>
此时,访问 localhost:8000/info.php 可浏览到我们刚刚创建的 info.php 页面了
原创文章转载请注明:转载自:centos搭建lnmp服务器
发表评论
沙发空缺中,还不快抢~