当前位置首页 > Ubuntu知识

Ubuntu18.04apache2配置ThinkPHP6

阅读次数:289 次  来源:admin  发布时间:

1.修改apache2的配置文件 /etc/apache2/apache2.conf

修改根目录和AllowOverride权限

lt;Directory /home/ubuntu/thinkphp/tp6/think/public/>

Options Indexes FollowSymLink

AllowOverride All

Require all granted

lt;/Directory>

2.修改/etc/apache2/sites-available/000-default.conf中的根目录

DocumentRoot /home/ubuntu/thinkphp/tp6/think/public

3.修改ThinkPHP public目录下的.htaccess文件:

lt;IfModule mod_rewrite.c>

Options +FollowSymlinks -Multiview

RewriteEngine O

RewriteCond %{REQUEST_FILENAME} !-d

RewriteCond %{REQUEST_FILENAME} !-f

#RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]

RewriteRule ^(.*)$ index.php [L,E=PATH_INFO:$1]

lt;/IfModule>

4.执行

udo a2enmod rewrite

5.重启服务

udo service apache2 restart

可以这样访问了:

http://111.229.200.158/Index/myhello

注意,自带的hello因为路由问题不能http://111.229.200.158/Index/hello这样访问

如果配置了多站点,如/etc/apache2/sites-available/mysite.conf:

lt;VirtualHost *:8080>

lt;Directory /home/ubuntu/xhadmin/public>

AllowOverride All

Options Indexes FollowSymLink

Require all granted

lt;/Directory>

ServerAdmin webmaster@localhost

DocumentRoot /home/ubuntu/xhadmin/public

ErrorLog ${APACHE_LOG_DIR}/error.log

CustomLog ${APACHE_LOG_DIR}/access.log combined

lt;/VirtualHost>

则一定要执行:

cd /etc/apache2/sites-available
sudo a2ensite mysite
sudo service apache2 reload
上一篇:网站性能优化之Apache调整
下一篇:Linux入门到放弃之六《磁盘和文件系统管理三》