dpdkqls6399 2019-06-13 19:04
浏览 494
已采纳

如何为php项目设置端口?

My php project by default has port:80, I need to make it any port above 1024.

I have multiple files in my project, when I try to make something like "myproject/item/1" it responds with error 404 even if I have this URI in my routes.
On the other hand, when I start project by typing php -S localhost:8050, and do like "myproject:8050/item/1" everything works perfectly. I use method from some dude in github to create php projects, by default it copies /etc/apache2/sites-available/000-default.conf, where default port is *80.

I need to make first example "myproject/item/1" working properly

P.S. I don't want to change 000-default file, because I don't want all my projects to be broken.

  • 写回答

1条回答 默认 最新

  • dongyan7172 2019-06-14 07:58
    关注

    For HTTP, browser by default is sending request to port 80, if you want run your project under another port you always need to specify that in request URI.

    You need to create new configuration in /etc/apache2/sites-available eg. myproject.conf which may look like this:

    Listen 8050
    NameVirtualHost *:8050
    <VirtualHost *:8050>    
            ServerName myproject
            ServerAlias www.myproject
    
            DocumentRoot /var/www/myproject
    
            <Directory /var/www/myproject>
                    Options Indexes FollowSymLinks MultiViews
                    AllowOverride None
                    Order allow,deny
                    allow from all
            </Directory>
    
            ErrorLog /var/log/apache2/error.log
    </VirtualHost>
    

    save, and enable your vhost by typing a2ensite myproject.conf, reload or restart apache and that's it.

    Another way is create an alias in default configuration:

    Alias /myproject "/var/www/myproject/"
    <Directory /var/www/myproject>
         Options Indexes FollowSymLinks MultiViews
         AllowOverride None
         Order allow,deny
         allow from all
    </Directory>
    

    That way, your project will be accessible by requesting like http://{your_server_addr}/myproject without specifying port.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 java在应用程序里获取不到扬声器设备
  • ¥15 echarts动画效果的问题,请帮我添加一个动画。不要机器人回答。
  • ¥60 许可证msc licensing软件报错显示已有相同版本软件,但是下一步显示无法读取日志目录。
  • ¥15 Attention is all you need 的代码运行
  • ¥15 一个服务器已经有一个系统了如果用usb再装一个系统,原来的系统会被覆盖掉吗
  • ¥15 使用esm_msa1_t12_100M_UR50S蛋白质语言模型进行零样本预测时,终端显示出了sequence handled的进度条,但是并不出结果就自动终止回到命令提示行了是怎么回事:
  • ¥15 前置放大电路与功率放大电路相连放大倍数出现问题
  • ¥80 部署运行web自动化项目
  • ¥15 腾讯云如何建立同一个项目中物模型之间的联系
  • ¥30 VMware 云桌面水印如何添加