calling PHP script- getting the script as an output

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP








up vote
1
down vote

favorite












I wrote a simple PHP script to connect to a SQL database. I ran chmod +x script.php. The problem is that when I call the script (./script.php) the output is the script itself (the whole script written as an output). Any ideas what I'm missing?



#!/usr/bin/php
<?
$servername = "localhost";
$username = "username";
$password = "password";

// Create connection
$conn = new mysqli($servername, $username, $password);

// Check connection
if ($conn->connect_error)
die("Connection failed: " . $conn->connect_error);

echo "Connected successfully";
?>









share|improve this question



















  • 1




    Short tags are probably disabled. Replace <? with <?php
    – vidarlo
    Mar 21 at 20:05










  • That was the problem. Thanks vidarlo
    – ItInNeed
    Mar 21 at 20:16














up vote
1
down vote

favorite












I wrote a simple PHP script to connect to a SQL database. I ran chmod +x script.php. The problem is that when I call the script (./script.php) the output is the script itself (the whole script written as an output). Any ideas what I'm missing?



#!/usr/bin/php
<?
$servername = "localhost";
$username = "username";
$password = "password";

// Create connection
$conn = new mysqli($servername, $username, $password);

// Check connection
if ($conn->connect_error)
die("Connection failed: " . $conn->connect_error);

echo "Connected successfully";
?>









share|improve this question



















  • 1




    Short tags are probably disabled. Replace <? with <?php
    – vidarlo
    Mar 21 at 20:05










  • That was the problem. Thanks vidarlo
    – ItInNeed
    Mar 21 at 20:16












up vote
1
down vote

favorite









up vote
1
down vote

favorite











I wrote a simple PHP script to connect to a SQL database. I ran chmod +x script.php. The problem is that when I call the script (./script.php) the output is the script itself (the whole script written as an output). Any ideas what I'm missing?



#!/usr/bin/php
<?
$servername = "localhost";
$username = "username";
$password = "password";

// Create connection
$conn = new mysqli($servername, $username, $password);

// Check connection
if ($conn->connect_error)
die("Connection failed: " . $conn->connect_error);

echo "Connected successfully";
?>









share|improve this question















I wrote a simple PHP script to connect to a SQL database. I ran chmod +x script.php. The problem is that when I call the script (./script.php) the output is the script itself (the whole script written as an output). Any ideas what I'm missing?



#!/usr/bin/php
<?
$servername = "localhost";
$username = "username";
$password = "password";

// Create connection
$conn = new mysqli($servername, $username, $password);

// Check connection
if ($conn->connect_error)
die("Connection failed: " . $conn->connect_error);

echo "Connected successfully";
?>






php






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Apr 5 at 23:57









Elder Geek

25.3k949120




25.3k949120










asked Mar 21 at 19:48









ItInNeed

61




61







  • 1




    Short tags are probably disabled. Replace <? with <?php
    – vidarlo
    Mar 21 at 20:05










  • That was the problem. Thanks vidarlo
    – ItInNeed
    Mar 21 at 20:16












  • 1




    Short tags are probably disabled. Replace <? with <?php
    – vidarlo
    Mar 21 at 20:05










  • That was the problem. Thanks vidarlo
    – ItInNeed
    Mar 21 at 20:16







1




1




Short tags are probably disabled. Replace <? with <?php
– vidarlo
Mar 21 at 20:05




Short tags are probably disabled. Replace <? with <?php
– vidarlo
Mar 21 at 20:05












That was the problem. Thanks vidarlo
– ItInNeed
Mar 21 at 20:16




That was the problem. Thanks vidarlo
– ItInNeed
Mar 21 at 20:16










1 Answer
1






active

oldest

votes

















up vote
1
down vote













As @vidarlo suggests, the short tags directive in the PHP configuration file is disabled.
If you'd like to use the short tags syntax, you'll have to enable it.
Change your php.ini file accordingly:



short_open_tag=On


And restart apache. Assuming you're using some kind of Debian-based system and apache2, execute the following command (or similar, depending on your system):



sudo service apache2 restart


Note: If you don't know where your php.ini configuration file is, just run the following in the terminal:



php --ini





share|improve this answer
















  • 1




    It appears he is not using apache2 (or any web server). Anyway, I'd say don't enable short tags; change tags to the long form in the script. Short tags are discouraged, and makes scripts less portable. There's no reason to use them.
    – vidarlo
    Mar 22 at 6:24










  • Well, we use short tags in all of our projects, but only in the views. In my opinion, it improves the readability.
    – Brood
    Mar 23 at 20:59










  • I don't see how a tag that is not repeated trough code improves readability. I typically see it on the first line of the file... Anyway, that is not really the point. Long tags eases portability, as it is supported everywhere, and it is enabled by default. In addition I'd not feel sure that short tags will be around for that long either...
    – vidarlo
    Mar 24 at 9:53










Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "89"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1018051%2fcalling-php-script-getting-the-script-as-an-output%23new-answer', 'question_page');

);

Post as a guest






























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
1
down vote













As @vidarlo suggests, the short tags directive in the PHP configuration file is disabled.
If you'd like to use the short tags syntax, you'll have to enable it.
Change your php.ini file accordingly:



short_open_tag=On


And restart apache. Assuming you're using some kind of Debian-based system and apache2, execute the following command (or similar, depending on your system):



sudo service apache2 restart


Note: If you don't know where your php.ini configuration file is, just run the following in the terminal:



php --ini





share|improve this answer
















  • 1




    It appears he is not using apache2 (or any web server). Anyway, I'd say don't enable short tags; change tags to the long form in the script. Short tags are discouraged, and makes scripts less portable. There's no reason to use them.
    – vidarlo
    Mar 22 at 6:24










  • Well, we use short tags in all of our projects, but only in the views. In my opinion, it improves the readability.
    – Brood
    Mar 23 at 20:59










  • I don't see how a tag that is not repeated trough code improves readability. I typically see it on the first line of the file... Anyway, that is not really the point. Long tags eases portability, as it is supported everywhere, and it is enabled by default. In addition I'd not feel sure that short tags will be around for that long either...
    – vidarlo
    Mar 24 at 9:53














up vote
1
down vote













As @vidarlo suggests, the short tags directive in the PHP configuration file is disabled.
If you'd like to use the short tags syntax, you'll have to enable it.
Change your php.ini file accordingly:



short_open_tag=On


And restart apache. Assuming you're using some kind of Debian-based system and apache2, execute the following command (or similar, depending on your system):



sudo service apache2 restart


Note: If you don't know where your php.ini configuration file is, just run the following in the terminal:



php --ini





share|improve this answer
















  • 1




    It appears he is not using apache2 (or any web server). Anyway, I'd say don't enable short tags; change tags to the long form in the script. Short tags are discouraged, and makes scripts less portable. There's no reason to use them.
    – vidarlo
    Mar 22 at 6:24










  • Well, we use short tags in all of our projects, but only in the views. In my opinion, it improves the readability.
    – Brood
    Mar 23 at 20:59










  • I don't see how a tag that is not repeated trough code improves readability. I typically see it on the first line of the file... Anyway, that is not really the point. Long tags eases portability, as it is supported everywhere, and it is enabled by default. In addition I'd not feel sure that short tags will be around for that long either...
    – vidarlo
    Mar 24 at 9:53












up vote
1
down vote










up vote
1
down vote









As @vidarlo suggests, the short tags directive in the PHP configuration file is disabled.
If you'd like to use the short tags syntax, you'll have to enable it.
Change your php.ini file accordingly:



short_open_tag=On


And restart apache. Assuming you're using some kind of Debian-based system and apache2, execute the following command (or similar, depending on your system):



sudo service apache2 restart


Note: If you don't know where your php.ini configuration file is, just run the following in the terminal:



php --ini





share|improve this answer












As @vidarlo suggests, the short tags directive in the PHP configuration file is disabled.
If you'd like to use the short tags syntax, you'll have to enable it.
Change your php.ini file accordingly:



short_open_tag=On


And restart apache. Assuming you're using some kind of Debian-based system and apache2, execute the following command (or similar, depending on your system):



sudo service apache2 restart


Note: If you don't know where your php.ini configuration file is, just run the following in the terminal:



php --ini






share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 21 at 22:01









Brood

407410




407410







  • 1




    It appears he is not using apache2 (or any web server). Anyway, I'd say don't enable short tags; change tags to the long form in the script. Short tags are discouraged, and makes scripts less portable. There's no reason to use them.
    – vidarlo
    Mar 22 at 6:24










  • Well, we use short tags in all of our projects, but only in the views. In my opinion, it improves the readability.
    – Brood
    Mar 23 at 20:59










  • I don't see how a tag that is not repeated trough code improves readability. I typically see it on the first line of the file... Anyway, that is not really the point. Long tags eases portability, as it is supported everywhere, and it is enabled by default. In addition I'd not feel sure that short tags will be around for that long either...
    – vidarlo
    Mar 24 at 9:53












  • 1




    It appears he is not using apache2 (or any web server). Anyway, I'd say don't enable short tags; change tags to the long form in the script. Short tags are discouraged, and makes scripts less portable. There's no reason to use them.
    – vidarlo
    Mar 22 at 6:24










  • Well, we use short tags in all of our projects, but only in the views. In my opinion, it improves the readability.
    – Brood
    Mar 23 at 20:59










  • I don't see how a tag that is not repeated trough code improves readability. I typically see it on the first line of the file... Anyway, that is not really the point. Long tags eases portability, as it is supported everywhere, and it is enabled by default. In addition I'd not feel sure that short tags will be around for that long either...
    – vidarlo
    Mar 24 at 9:53







1




1




It appears he is not using apache2 (or any web server). Anyway, I'd say don't enable short tags; change tags to the long form in the script. Short tags are discouraged, and makes scripts less portable. There's no reason to use them.
– vidarlo
Mar 22 at 6:24




It appears he is not using apache2 (or any web server). Anyway, I'd say don't enable short tags; change tags to the long form in the script. Short tags are discouraged, and makes scripts less portable. There's no reason to use them.
– vidarlo
Mar 22 at 6:24












Well, we use short tags in all of our projects, but only in the views. In my opinion, it improves the readability.
– Brood
Mar 23 at 20:59




Well, we use short tags in all of our projects, but only in the views. In my opinion, it improves the readability.
– Brood
Mar 23 at 20:59












I don't see how a tag that is not repeated trough code improves readability. I typically see it on the first line of the file... Anyway, that is not really the point. Long tags eases portability, as it is supported everywhere, and it is enabled by default. In addition I'd not feel sure that short tags will be around for that long either...
– vidarlo
Mar 24 at 9:53




I don't see how a tag that is not repeated trough code improves readability. I typically see it on the first line of the file... Anyway, that is not really the point. Long tags eases portability, as it is supported everywhere, and it is enabled by default. In addition I'd not feel sure that short tags will be around for that long either...
– vidarlo
Mar 24 at 9:53

















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1018051%2fcalling-php-script-getting-the-script-as-an-output%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

pylint3 and pip3 broken

Missing snmpget and snmpwalk

How to enroll fingerprints to Ubuntu 17.10 with VFS491