ubuntu apache2的某些配置
多虚拟主机
- 所在路径 /etc/apache2/sites-available/000-default.conf
- 若要修改存放源文件的路径须先修改/etc/apache2/apache2.conf
<Directory /var/www>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
<VirtualHost *:8080>
ServerName www.t1.com
ServerAdmin www.tt1.com
DocumentRoot /var/www/html8080
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<VirtualHost *:80>
ServerName www.t2.com
ServerAdmin www.tt2.com
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
响应头显示修改
- 所在路径 /etc/apache2/apache2.conf
ServerSignature Off
ServerTokens Prod
效果如下:
apache2的重启 开始 停止
sudo /etc/init.d/apache2 start/stop/restart
让apache解析html中的php
在/etc/apache2/apache2.conf文件中添加下面两行即可:
AddHandler php-script .php .html
AddType text/html .php .html
# 直接在文本最后添加一行文本
echo 'AddHandler php-script .php .html'>> /etc/apache2/apache2.conf
echo 'AddType text/html .php .htmll'>> /etc/apache2/apache2.conf
LAMP环境搭建
sudo apt install apache2 mysql-server php php-fpm php-cgi php-common php-curl php-mysql php-mbstring php-xml php-gd -y
php-gd库无法显示图片的一种情况
php-gd库无法显示图片
在生成图片前清空输出缓冲区
ob_clean();
header (‘Content-type: image/png’);
ob_get_contents() - 返回输出缓冲区的内容
ob_flush() - 冲刷出(送出)输出缓冲区中的内容
ob_clean() - 清空(擦掉)输出缓冲区
ob_end_flush() - 冲刷出(送出)输出缓冲区内容并关闭缓冲
ob_end_clean() - 清空(擦除)缓冲区并关闭输出缓冲
flush() - 刷新输出缓冲