运维之路-阿里云 ubuntu LAMP环境部署

阐述

对自己的服务器部署过程做的记录,供大家参考,欢迎交流。
基本上按照步骤一步步下来就可以很快的完成自己的php部署环境了

系统版本

阿里云 轻量应用服务器 ubuntu 18.04

首次登陆

更新本地 apt 源

sudo apt-get update

安装下vim编辑器

sudo apt-get install vim

APT更新国内源

切换到 root 目录

su

备份源文件

cp /etc/apt/sources.list /etc/apt/sources.list.bak

清空内容

true > /etc/apt/sources.list

阿里源

deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse

将上面的源复制到文件中, 保存退出

vi /etc/apt/sources.list

更新本地 apt 源

sudo apt-get update

进行一次软件升级

sudo apt-get upgrade

SSH登陆

这个就不写了,可参考文献.
https://www.cnblogs.com/asyang1/p/9467646.html

设置服务端保持长连接

为解决一段时间不操作或屏幕无输出自动断开问题,不熟悉部署流程的朋友,可以先提前设置下,可以偷懒。
#编辑客户端ssh配置文件,也就是你本地的,这里我刚开始也搞混了
vim /etc/ssh/ssh_config
#末尾添加以下内容 大致意思是定时30秒向服务器发送一次请求
ServerAliveInterval 30
#编辑服务端ssh配置文件
vim /etc/ssh/sshd_config
#去掉以下两个参数的注释,保存退出
ClientAliveInterval 60
ClientAliveCountMax 1
#重启服务
/etc/init.d/ssh restart
#每 60 秒就会自动发送一个信号给 Client,而等待 Client 回应

php环境搭建 apache2+mysql+php

安装apacha2

sudo apt-get install apache2

安装完后 可以尝试访问网站了

可选步骤:apache允许https访问

新建Apache2配置项

vim /etc/apache2/sites-available/default-ssl.conf

一般默认会出来以下内容的,如果没有可复制粘贴,然后按步骤 ESC>>:>>wq>>Enter


<IfModule mod_ssl.c>
<VirtualHost _default_:443>
ServerAdmin webmaster@localhost

DocumentRoot /var/www/html/app/public/

# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf

# SSL Engine Switch:
# Enable/Disable SSL for this virtual host.
SSLEngine on

# A self-signed (snakeoil) certificate can be created by installing
# the ssl-cert package. See
# /usr/share/doc/apache2/README.Debian.gz for more info.
# If both key and certificate are stored in the same file, only the
# SSLCertificateFile directive is needed.
SSLCertificateFile /etc/letsencrypt/live/fx.yunfeisky.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/fx.yunfeisky.com/privkey.pem

# Server Certificate Chain:
# Point SSLCertificateChainFile at a file containing the
# concatenation of PEM encoded CA certificates which form the
# certificate chain for the server certificate. Alternatively
# the referenced file can be the same as SSLCertificateFile
# when the CA certificates are directly appended to the server
# certificate for convinience.
#SSLCertificateChainFile /etc/apache2/ssl.crt/server-ca.crt

# Certificate Authority (CA):
# Set the CA certificate verification path where to find CA
# certificates for client authentication or alternatively one
# huge file containing all of them (file must be PEM encoded)
# Note: Inside SSLCACertificatePath you need hash symlinks
# to point to the certificate files. Use the provided
# Makefile to update the hash symlinks after changes.
#SSLCACertificatePath /etc/ssl/certs/
#SSLCACertificateFile /etc/apache2/ssl.crt/ca-bundle.crt

# Certificate Revocation Lists (CRL):
# Set the CA revocation path where to find CA CRLs for client
# authentication or alternatively one huge file containing all
# of them (file must be PEM encoded)
# Note: Inside SSLCARevocationPath you need hash symlinks
# to point to the certificate files. Use the provided
# Makefile to update the hash symlinks after changes.
#SSLCARevocationPath /etc/apache2/ssl.crl/
#SSLCARevocationFile /etc/apache2/ssl.crl/ca-bundle.crl

# Client Authentication (Type):
# Client certificate verification type and depth. Types are
# none, optional, require and optional_no_ca. Depth is a
# number which specifies how deeply to verify the certificate
# issuer chain before deciding the certificate is not valid.
#SSLVerifyClient require
#SSLVerifyDepth 10

# SSL Engine Options:
# Set various options for the SSL engine.
# o FakeBasicAuth:
# Translate the client X.509 into a Basic Authorisation. This means that
# the standard Auth/DBMAuth methods can be used for access control. The
# user name is the `one line' version of the client's X.509 certificate.
# Note that no password is obtained from the user. Every entry in the user
# file needs this password: `xxj31ZMTZzkVA'.
# o ExportCertData:
# This exports two additional environment variables: SSL_CLIENT_CERT and
# SSL_SERVER_CERT. These contain the PEM-encoded certificates of the
# server (always existing) and the client (only existing when client
# authentication is used). This can be used to import the certificates
# into CGI scripts.
# o StdEnvVars:
# This exports the standard SSL/TLS related `SSL_*' environment variables.
# Per default this exportation is switched off for performance reasons,
# because the extraction step is an expensive operation and is usually
# useless for serving static content. So one usually enables the
# exportation for CGI and SSI requests only.
# o OptRenegotiate:
# This enables optimized SSL connection renegotiation handling when SSL
# directives are used in per-directory context.
#SSLOptions +FakeBasicAuth +ExportCertData +StrictRequire
<FilesMatch "\.(cgi|shtml|phtml|php)$">
SSLOptions +StdEnvVars
</FilesMatch>
<Directory /usr/lib/cgi-bin>
SSLOptions +StdEnvVars
</Directory>

# SSL Protocol Adjustments:
# The safe and default but still SSL/TLS standard compliant shutdown
# approach is that mod_ssl sends the close notify alert but doesn't wait for
# the close notify alert from client. When you need a different shutdown
# approach you can use one of the following variables:
# o ssl-unclean-shutdown:
# This forces an unclean shutdown when the connection is closed, i.e. no
# SSL close notify alert is send or allowed to received. This violates
# the SSL/TLS standard but is needed for some brain-dead browsers. Use
# this when you receive I/O errors because of the standard approach where
# mod_ssl sends the close notify alert.
# o ssl-accurate-shutdown:
# This forces an accurate shutdown when the connection is closed, i.e. a
# SSL close notify alert is send and mod_ssl waits for the close notify
# alert of the client. This is 100% SSL/TLS standard compliant, but in
# practice often causes hanging connections with brain-dead browsers. Use
# this only for browsers where you know that their SSL implementation
# works correctly.
# Notice: Most problems of broken clients are also related to the HTTP
# keep-alive facility, so you usually additionally want to disable
# keep-alive for those clients, too. Use variable "nokeepalive" for this.
# Similarly, one has to force some clients to use HTTP/1.0 to workaround
# their broken HTTP/1.1 implementation. Use variables "downgrade-1.0" and
# "force-response-1.0" for this.
# BrowserMatch "MSIE [2-6]" \
# nokeepalive ssl-unclean-shutdown \
# downgrade-1.0 force-response-1.0

</VirtualHost>
</IfModule>

建立软连接

ln -s /etc/apache2/sites-available/default-ssl.conf /etc/apache2/sites-enabled/default-ssl.conf

模块开启https

ln -s /etc/apache2/mods-available/ssl.conf /etc/apache2/mods-enabled/ssl.conf

ln -s /etc/apache2/mods-available/ssl.load /etc/apache2/mods-enabled/ssl.load

ln -s /etc/apache2/mods-available/socache_shmcb.load /etc/apache2/mods-enabled/socache_shmcb.load

重启Apache使配置生效

/etc/init.d/apache2 restart

我这边的ssl证书是通过CDN去走的,如果你自己有证书可通过以下方法配置,假设已经有证书文件apache.crt 和私匙apache.key在/etc/apache2/ 下新建一个ssl 文件夹,把这两个文件扔进去。

配置SSL证书

vim /etc/apache2/sites-available/default-ssl.conf
在ServerAdmin下另起一行加上ServerName 你的域名:443
找到SSLEngine,SSLCertificateFile,SSLCertificateKeyFile并修改成以下内容

SSLEngine on
SSLCertificateFile /etc/apache2/ssl/apache.crt
SSLCertificateKeyFile /etc/apache2/ssl/apache.key

SSL证书配置完毕,保存退出。

最后重启Apache是配置生效
/etc/init.d/apache2 restart

可选配置虚拟主机

在apache2里面目录结构中是没有httpd.conf。正确的方法应该如下:

定位到配置目录
cd /etc/apache2/sites-available

编辑配置文件
sudo vi 000-default.conf

添加一个船新的虚拟主机

<VirtualHost *:80>
        ServerName chase.xxxxxx.cn
        DocumentRoot /var/www/html/chase
        <Directory /var/www/html/chase/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                Order allow,deny
                allow from all
        </Directory>
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

建立关联文件
sudo ln -s /etc/apache2/sites-available/linyupark /etc/apache2/sites-enabled/linyupark

在/etc/apache2/sites-enabled下生成如下软链接

检查配置文件语法
sudo apache2ctl configtest

重启Apache
/etc/init.d/apache2 restart

安装PHP7.2

sudo apt-get install php7.2

如有选择 地区选6 时区选70
查看是否安装成功
php -v

安装PHP7.2插件
sudo apt-get install libapache2-mod-php7.2

安装完成之后我们可以写一个简单的PHP文件检查是不是可以解析PHP了
cd /var/www/html

创建php文件
vi info.php

输入测试内容 保存退出

<?php
echo phpinfo();

通过浏览器访问 域名+info.php 正常会显示php相关配置信息

安装mysql

服务 客户端 php插件 安装
sudo apt-get install mysql-server mysql-client php7.2-mysql

检查是否安装成功
mysql -V

设置可远程访问
sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf

将bind-address = 127.0.0.1注释掉保存退出

删除匿名用户访问

登录mysql
mysql -u root
切换至mysql数据库
use mysql;
删除匿名访问执行删除sql语句
delete from user where user='';
增加允许远程访问的用户或者允许现有用户的远程访问,如果需要指定访问主机,可以把%替换为主机的IP或者主机名
grant all privileges on *.* to 'root'@'%' identified by '新的密码' with grant option;

已存在的用户修改成允许远程访问

例 root ,如出现以下提示不用理会 ERROR 1062 (23000): Duplicate entry ‘%-root’ for key ‘PRIMARY’

update user set host='%' where user='root' and host='localhost';

刷新MySQL的系统权限
flush privileges;

退出mysql
exit
重启mysql
/etc/init.d/mysql restart

FTP服务安装

安装 vsftpd
sudo apt-get install vsftpd
启动vsftpd服务
sudo service vsftpd start
查看vsftpd服务
sudo service vsftpd status
新建ftp用户 例:新用户chase 回车>新建成功
sudo useradd -d /home/chase -s /bin/bash chase
设置用户的密码>回车>输入两次密码>回车>设置成功
sudo passwd chase
修改文件夹的拥有者为chase用户
sudo chown chase /home/chase/

修改配置文件/etc/vsftpd.conf
添加以下配置 :

userlist_deny=NO
userlist_enable=YES
userlist_file=/etc/allowed_users
seccomp_sandbox=NO
pasv_promiscuous=YES

修改以下配置

local_enable=YES #默认为YES
write_enable=YES  (是否可写入)
#新建允许访问的用户清单文件 输入用户名 chase 保存退出
sudo vi /etc/allowed_users 

查看禁止访问用户清单文件中的内容,如有chase请删除
sudo vim /etc/ftpusers

可选安装php包管理 composer

sudo apt-get install composer
检查是否安装成功
composer

可选安装git

默认自带git不需要额外安装,如果没有可以通过sudo apt-get install git安装,使用git检查是否安装成功。

可选安装sftp

sudo apt-get install openssh-server
检查是否安装成功
sfrp

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值