Ubuntu从零搭建LAMP环境

Ubuntu从零搭建PHP环境

新购买了阿里云的ECS,记录一下PHP环境的搭建过程:

操作系统: Ubuntu 16.04 64位


一、安装PHP、Apache、MySQL

通过apt-get安装,执行以下命令:

apt-get update
apt-get insatll php
apt-get install apache2
apt-get install mysql-server

注:mysql在安装时会让你输入root用户的密码

二、配置Apache

1、绑定测试域名

首先在/etc/apache2/sites-available目录创建配置文件:
vi /etc/apache2/sites-available/test.com.conf
配置如下:

<VirtualHost *:80>
   ServerAdmin test@test.com  ###管理员邮箱 
   DocumentRoot /var/www/html ###项目目录
   ServerName test.com        ###要绑定的域名 
   DirectoryIndex index  index.html index.php index.htm ###执行文件的优先级
   ErrorLog /var/wwwLogs/error/test.com.log  ###error日志
   CustomLog /var/wwwLogs/access/test.test.log combined ###access日志
</VirtualHost>

加载Apache配置
a2ensite

输入test.com.conf

重启Apache
service apache2 restart

2、开启php扩展

执行命令:
apt-get install libapache2-mod-php7.0
a2enmod php7.0

3、开启MySQL扩展

执行命令:
apt-get install php7.0-gd
apt-get install php7.0-mysql

注:扩展需根据自己的php版本选择。

最后重启Apache
service apache2 restart

补充:

阿里云的ECS默认没有开放80等端口,需要到控制台设置安全组,设置之后才能访问。详情参照链接,这里不赘述了。

https://help.aliyun.com/document_detail/69888.html?spm=5176.11065259.1996646101.searchclickresult.5bc177d5HHUBRr

https://help.aliyun.com/document_detail/25475.html?spm=5176.2020520101.0.0.3aba4df5i3Nuws


至此,LAMP环境已经搭建完成。

但MySQL默认是开启严格模式的,对于生产环境兼容不友好,可通过以下方式解决:

1、登录MySQL(若需要)

mysql -uroot -p

2、关闭严格模式(若需要)

set global SQL_MODE="NO_ENGINE_SUBSTITUTION";

3、开启严格模式(若需要)

`set global SQL_MODE=”STRICT_TRANS_TABLES”;”;

猜你喜欢

转载自blog.csdn.net/l_Laity/article/details/80673402