Php files are not running on ubuntu

3

Hi, I'm working with php mvc without frameworks on ubuntu and apache . When I work with codeigniter everything works fine, but% co_of pure% no. It's weird because I can see the files in the browser at the root of the project, but when you run them by url it goes out php and I do not think my code is wrong because I've tried it in error 404 and it works fine.

What can it be?

    
asked by daniel 11.06.2016 в 00:48
source

5 answers

2

Good morning,

For the information and comments made, I think the topic is based on the suggestion you made Juan Pinzón :

  

Are you placing pure php in the same root directory of your project in codeigniter ??

As a general rule, Frameworks are usually designed to redirect all traffic towards index.php of the root of the application with the help of .htaccess . And any other url that is not in the router configuration resolves it as a error 404 .

The simplest way ( personal opinion ) to manage multiple projects is to use virtual hosts . You can find information about the different configurations and how to adapt it to your needs. But basically it's about creating a virtual host on your Ubuntu machine, and configuring the file hosts on the client machine, either the Ubuntu itself or if you have it mounted on a Virtual Machine, then on the Client Machine.

  

The configuration that I have is Mac and Ubuntu Virtual Machine that I will give example.

Create a project, phptest.web for example

1 .- Create a root directory for the project

sudo mkdir /var/www/phptest

Grant permissions

sudo chown -R $USER:$USER /var/www/phptest
sudo chmod -R 755 /var/www

2 .- Create a file% test_co%, php within the root directory of the new index.php .

/var/www/phptest/index.php  
<?php echo 'run!'; ?>

3 .- Create the file of virtual host phptest.web for example:

The file is called virtual host
And it's saved on the route phptest.conf

<VirtualHost *:80>
    ServerName phptest.web
    ServerAlias www.phptest.web
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/phptest
        <Directory /var/www/phptest>
                DirectoryIndex index.php
                AllowOverride All
                Order allow,deny
                Allow from all
        </Directory>
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

4 .- Activate the virtual host

sudo a2ensite phptest.conf

5 .- Restart apache

sudo service apache2 restart

6 .- Edit the file /etc/apache2/sites-available/

On Ubuntu or Mac, you can find that file at: hosts

You open it and at the end of the file you set the new /etc/hosts
I have put the ip of the virtual machine as an example. You just have to change it to the server.

192.168.1.2 phptest.web www.phptest.web

7 .- Test if it works

You open the browser and go to: host

Logically you will have to configure everything with the data and under the structure you have to function. If I have not skipped any step, that sequence should let you have several projects, frameworks or php files running independently without affecting the configurations of http://www.phptest.web/ of projects you have.

I hope it works.

Greetings,

PS .: If you find an error, comment and edit it.

    
answered by 11.06.2016 в 13:51
0

Check that you have started the httpd service that corresponds to the web server and you have installed the php interpreter.

I recommend you follow this guide.

link

    
answered by 11.06.2016 в 00:54
0

I think that basically Oscar's answer is the most valid but a valid answer could be these running the php from the apache directory and the browser ?? If it does not work for you. ..

    
answered by 12.07.2016 в 07:26
0

Something similar happened to me. It turns out that linux is very sensitive to uppercase and lowercase, which means that if within your project you are calling your file estilo , for example as follows:

ruta/Estilo

but the name of the file is written in lowercase you will never find it! At least that was my problem. Maybe yours will go out there.

    
answered by 12.12.2017 в 03:30
-1

Most people who start with PHP usually run the PHP file by double clicking on it directly from the directory where they file it. To correct this problem and your PHP codes work, you must execute it from the browser address line that you use:

Example: if you created a file called "Index.html" that calls another file called "Registry.php", under a folder called "Registers", the first thing is that this folder must be inside the folder " htdocs "from XAMPP or on WWW if you use WAMP.

Just do the following: Go to the browser command line and type:

Localhost/registro/Index.html

And ready!

    
answered by 16.12.2016 в 01:42