1 部署apache2
- cmd
sudo apt-get install apache2
- validate
localhost
2 apache2 Usage
2.1 启动
apache2默认监听80端口,启动后输入:localhost
即可获取Home信息,如下图。
sudo service apache2 start
- 启动
sudo service apache2 start
- 重启
sudo service apache2 restart
2.2 配置监听端口
- apache2路径
/etc/apache2
- 修改端口配置文件ports.conf
sudo vim /etc/apache2
Listen 8899
- 重启apache2
sudo service apache2 restart
- Home
localhosnt:8899
3 部署php
3.1 安装php
sudo apt-get install php7.0
- php安装路径
/etc/php/7.2
- 查看php版本
php -v
3.2 安装插件
- 查看安装的插件
php -m
- 搜索插件
apt-cache search libapache2-mod-php
- 安装插件
sudo apt-get install libapache2-mod-php7.2
- 测试
# 进入apache的html目录
cd /var/www/html
vim test.php
<?php
phpinfo();
?>
- 访问
localhost/test.php
4 Usage
4.1 命令行执行php
php -a
>echo "hello world";
hello world
4.2 执行*.php文件
- 【test.php】
<?php
echo "helloworld";
?>php
- 执行
php test.php
4.3 Web端直接访问
在apache2目录下新建php文件name.php,直接访问:localhost/name.php
/etc/www/html
sudo vim /etc/www/html name.php
5 PHP安装MySQL驱动
PHP7.2默认已经启动PDO(PHP Data Object),如下:
5.1 搜索mysql插件
apt-cache search php7.2-
5.2 安装mysql插件
sudo apt-get install php7.2-mysql
5.3 配置php.ini
sudo vim /etc/php/7.2/phpdbg/php.ini
找到如下:
;extension=pdo_mysql
将分号去掉,使该pdo_mysql生效.
5.4 重启apache2服务
sudo service apache2 restart
mysql驱动已配置成功.
6 安装phpMyadmin
功能:php mysql管理UI.
6.1 安装
sudo apt-get install -y phpmyadmin
6.2 配置
选择apache2,使用空格选中,出现星号:*
,说明成功选中,确定并安装.
6.3 用户
- 用户名
phpmyadmin
- 密码
123456
7 Q&A
7.1 安装后自动启动失败
● apache2.service - The Apache HTTP Server
Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
Drop-In: /lib/systemd/system/apache2.service.d
└─apache2-systemd.conf
Active: failed (Result: exit-code) since Sat 2019-08-03 21:01:04 CST; 5ms ago
Process: 9247 ExecStart=/usr/sbin/apachectl start (code=exited, status=1/FAILURE)
7.2 启动失败
[....] Starting apache2 (via systemctl): apache2.serviceJob for apache2.service failed because the control process exited with error code.
See "systemctl status apache2.service" and "journalctl -xe" for details.
failed!
7.3 重启失败
[....] Restarting apache2 (via systemctl): apache2.serviceJob for apache2.service failed because the control process exited with error code.
See "systemctl status apache2.service" and "journalctl -xe" for details.
failed!
- Reason
80端口被占用 - Plan
端口查看
sudo netstat -pant
- 端口进程
ps -ef | grep nginx
- 关闭进程
sudo kill 10104
7.4 运行curl_init()调用失败
PHP Fatal error: Uncaught Error: Call to undefined function curl_init()
- Reason
php-curl未安装. - Plan
sudo apt-get install -y php-curl
【参考文献】
[1]https://www.cnblogs.com/fireicesion/p/8457898.html
[2]https://stackoverflow.com/questions/32926207/error-apache2-service-and-journalctl-xe
[3]https://www.jianshu.com/p/a1e1b041f815
[4]https://www.csdn.net/gather_2f/MtTaEg3sMzkzMy1ibG9n.html
[5]https://blog.csdn.net/qq_33188837/article/details/88904335