CentOS 之LNMP环境搭建
|2435字|435阅读
LNMP环境搭建
安装 Nginx 服务器
安装 Nginx使用 yum 安装 Nginx:yum install nginx -y修改 /etc/nginx/conf.d/default.conf,去除对 IPv6 地址的监听,可参考下面的代码示例:default.conf
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此时,可访问实验机器外网 HTTP 服务(http://139.199.174.103)来确认是否已经安装成功。将 Nginx 设置为开机自动启动:
chkconfig nginx on
2.安装 MySQL 数据库服务
安装 MySQL使用 yum 安装 MySQL:yum install mysql-server -y
安装完成后,启动 MySQL 服务:service mysqld restart设置 MySQL 账户 root 密码:
/usr/bin/mysqladmin -u root password \'VsoUWMsv\'
将 MySQL 设置为开机自动启动:
chkconfig mysqld on
3.搭建 PHP 环境
安装 PHP使用 yum 安装 PHP:yum install php php-fpm php-mysql -y安装之后,启动 PHP-FPM 进程:
service php-fpm start启动之后,可以使用下面的命令查看 PHP-FPM 进程监听哪个端口 netstat -nlpt | grep php-fpm把 PHP-FPM 也设置成开机自动启动:
chkconfig php-fpm on已完成,下一步
4.配置 Nginx 并运行 PHP 程序
配置 Nginx在 /etc/nginx/conf.d 目录中新建一个名为 php.conf 的文件,并配置 Nginx 端口 ,配置示例如下: php.conf
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 是否安装成功了,文件内容参考如下: info.php
此时,访问 http://139.199.174.103:8000/info.php 可浏览到我们刚刚创建的 info.php 页面了
nginx -s reload sudo add-apt-repository ppa:certbot/certbot
sudo apt-get update sudo apt-get install certbot
cd /home/ubuntu mkdir keys
cd keys/
certbot certonly --webroot -w /usr/share/nginx/html/blog.acanx.com/ -d blog.acanx.com history
|2435字|435阅读