How can I run my local server with a specific path with PHP?

0

I have a problem with my local server.

I am using Apache and in turn, I am virtualizing to obtain, for example: milocal.com

The problem is that I need to have it this way: milocal.com/proyecto and then through code I add another route when performing a specific action; what happens is that if I do the tests with milocal.com if it works well, but when I do it with milocal/proyecto it does not work even when I check the console errors in the server response I get the html from the page.

Note: The question is that I need to take it as milocal.com/proyecto as it is an additional module when entering milocal.com .

    
asked by Rocky 09.03.2017 в 06:45
source

2 answers

1

Are you using Apache Virtual Host ?. Make sure you have a directory where your site will be (usually by convention it is placed in /var/www/tusitioweb ). I suggest you always use the domain name for ease of maintenance (in this example it would be /var/www/milocal.com ). You must give permission to the web server (usually the user is www-data that must have read permissions for all and read and write for www-data, this will allow your PHP scripts to manipulate the information in those directories).

Also make sure you have a virtual hosting file in /etc/apache2/sites-available/milocal.com (or whatever your domain is). For this example the file would look something like this:

<VirtualHost *:80>
        ServerAdmin webmaster@localhost
        ServerName milocal.com
        DocumentRoot /var/www/milocal.com/proyecto
        <Directory />
                Options FollowSymLinks
                AllowOverride None
        </Directory>
        <Directory /var/www/milocal.com/proyecto>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                Order allow,deny
                allow from all
        </Directory>

        ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
        <Directory "/usr/lib/cgi-bin">
                AllowOverride None
                Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
                Order allow,deny
                Allow from all
        </Directory>

        ErrorLog ${APACHE_LOG_DIR}/error.log

        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn

        CustomLog ${APACHE_LOG_DIR}/access.log combined

    Alias /doc/ "/usr/share/doc/"
    <Directory "/usr/share/doc/">
        Options Indexes MultiViews FollowSymLinks
        AllowOverride None
        Order deny,allow
        Deny from all
        Allow from 127.0.0.0/255.0.0.0 ::1/128
    </Directory>

</VirtualHost>

Finally, do not forget to activate this configuration with:

a2ensite milocal.com 

to then restart the apache server with:

service apache2 restart

P.D: Do not forget to address your DNS server to the IP address of your machine.

    
answered by 09.03.2017 в 08:08
0

If you want to start your application, you can do it in an easy way by executing the following in the root of your project

php -S localhost:8000

Then you open that address in your browser and you can see what you are developing.

Here you can find more information about this.

    
answered by 09.03.2017 в 08:09