1、准备

#更新软件源中的所有软件列表(必须)

sudo apt update

# 更新软件(建议)

sudo apt upgrade

# 更新系统版本(非必要时,不建议升级)

sudo apt dist-upgrade

2、安装Apache

sudo apt install apache2

3、安装PHP

sudo apt install php

4、安装MySQL

sudo apt install mysql-server php-mysql

5、配置MySQL

mysql -u root
use mysql;
update mysql.user <span class="hljs-built_in">set</span> authentication_string=PASSWORD(<span class="hljs-string">'你的密码'</span>), plugin=<span class="hljs-string">'mysql_native_password'</span> <span class="hljs-built_in">where</span> user=<span class="hljs-string">'root'</span>;
flush privileges;
quit;
sudo service mysql stop
sudo service mysql start

6、附加安装

sudo apt install libapache2-mod-php php-mysql php-curl php-gd

7、安装phpMyAdmin

sudo apt install phpmyadmin

8、启用mod_rewrite模块

sudo a2enmod rewrite
sudo service apache2 restart

9、配置

#编辑apache2.conf,/var/www/路径可修改(如修改为/data/www/),启用RewriteEngine
<Directory /var/www>
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
    RewriteEngine On
</Directory>
#编辑 /etc/apache2/sites-available/000-default.conf
<VirtualHost *:80>
    ServerName example.com
    ServerAlias www.example.com
    ServerAdmin service@example.com
    DocumentRoot /var/www/example
    <Directory />
        DirectoryIndex index.html index.php
        Options FollowSymLinks
        AllowOverride All
        RewriteEngine On
    </Directory>
    ErrorLog /var/log/apache2/example_error.log
    CustomLog /var/log/apache2/example_access.log combined
</VirtualHost>

10、权限设置

#改变/var/www/目录所有者为ubuntu(腾讯云Ubuntu默认用户)
sudo chown -R ubuntu /var/www/

#设置网站权限

chmod 755 /var/www/
chmod 777 /var/www/example/application
chmod 777 /var/www/example/uploads -R

作者:宝庆陈
来源:CSDN
原文:https://blog.csdn.net/sanve/article/details/80770675
版权声明:本文为博主原创文章,转载请附上博文链接!

文档更新时间: 2019-02-13 09:14   作者:cklx