Reputation: 307
I am newbie in PHP. I have successfully installed PHP on Ubuntu, now I want start my first program. I am using gPHPEdit as IDE. Where should I save .php files that I create? And how to run/test them?
Upvotes: 5
Views: 42531
Reputation:
https://www.php.net/manual/en/features.commandline.webserver.php
this is an easy way to test your files in php.
$ cd ~/public_html
$ php -S localhost:8000
then you can go to your browser and enter localhost:8000/myfile.php
.
Upvotes: 0
Reputation: 1366
remove the index.html file from /var/www/
$ sudo rm index.html
create a new php file there:
$ sudo gedit /var/www/index.php
write in it:
<?php
print_r(phpinfo());
?>
Restart your Apache2 Server :
$ sudo service apache2 restart
OR
$ sudo /etc/init.d/apace2 restart
and point to yout localhost and /index.php
if err arises visit : http://www.allaboutlinux.eu/how-to-run-php-on-ubuntu/
Upvotes: 1
Reputation: 131
If you cannot save or copy to var/www/html, to run your php scripts on your browser. If you are using Ubuntu 14.04. I followed these steps and it worked for me.
sudo su
on the terminal. sudo subl /etc/apache2/sites-available/000-default.conf
on your terminal to open this file. Note you can change the subl to any text editor to open the file e.g sudo nano /etc/apache2/sites-available/000-default.conf.
DocumentRoot /var/www/html
to /home/user/yoursubdir
sudo subl /etc/apache2/apache2.conf
on your terminal to open this file. Add the following to end of the file
<Directory /home/user/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
Save and Close the file.
sudo service apache2 restart
127.0.1.1/directory/document.php.
I hope this helps.
Upvotes: 1
Reputation: 67039
Make sure you have LAMP
installed. Do a sudo tasksel
and select lamp then hit enter, its gotta be the most simple *amp install ever made. Its a good idea to install phpmyadmin: sudo apt-get install phpmyadmin
. After that just copy the files to /var/www/
and then they will show up on http://localhost
. I recommended using Eclipse PDT or the Netbeans build for PHP.
Upvotes: 4
Reputation: 6520
You should pick up a book or start following some good tutorials on the web.
If you are just scripting using php, you can save them anywhere and run the php on the terminal using the php command line interpreter.
If you are trying write web scripts (and I think you are), you need to install and configure a web server (typically apache) and save your scripts in the server's document root (typically /var/www). Also, I highly recommend you to read up a little about servers and HTTP and figure out how all this works on the inside before learning to building websites in php.
Upvotes: 1