Php ditampilkan sebagai teks biasa

Anda telah menulis program PHP pertama Anda, tetapi ketika Anda ingin menjalankannya, yang Anda lihat di browser hanyalah kode—program tersebut tidak benar-benar berjalan. Ketika ini terjadi, penyebab paling umum adalah Anda mencoba menjalankan PHP di suatu tempat yang tidak mendukung PHP

Menjalankan PHP di Server Web

Jika Anda menjalankan PHP di server web, pastikan Anda memiliki host yang diatur untuk menjalankan PHP. Meskipun sebagian besar server web mendukung PHP saat ini, jika Anda tidak yakin, tes cepat dapat memberi Anda jawabannya. Di editor teks apa pun, buat file dan ketik baru

 phpinfo() ; 

?>
Save the file as test.php and upload it to the root folder of your server. (Windows users make sure to display all file extensions.) Open a browser on your computer and enter the URL of your file in the format:

http://nameofyourserver/test.php
Click Enter. If the web server supports PHP, you should see a screen filled with information and a PHP logo at the top. If you don't see it, your server doesn't have PHP or PHP is not started properly. Email the web server to ask about your options.

Menjalankan PHP di Komputer Windows

If you are running your PHP script on a Windows computer, you need to manually install PHP. If you haven't already done so, your PHP code won't execute. Instructions for the installation process, versions and the system requirements are listed at the PHP website. After it is installed, your browser should run your PHP programs directly from your computer.
_

Menjalankan PHP di Komputer Mac

If you are on an Apple, you already have Apache and PHP on your computer. You just need to activate it to get things working. Activate Apache in the Terminal, which is located in the Utilities folder, by using the following command instructions.
Start Apache web sharing: 

?>
0
?>
1______3_______
?>
3
?>
4

?>
6
?>
7
?>
8

Save the file as test.php and upload it to the root folder of your server. (Windows users make sure to display all file extensions.) Open a browser on your computer and enter the URL of your file in the format:
0
Save the file as test.php and upload it to the root folder of your server. (Windows users make sure to display all file extensions.) Open a browser on your computer and enter the URL of your file in the format:
1

Save the file as test.php and upload it to the root folder of your server. (Windows users make sure to display all file extensions.) Open a browser on your computer and enter the URL of your file in the format:
3_______2

Kutip Artikel ini

Format

Kutipan Anda

Bradley, Angela. "Kode PHP Menampilkan Alih-alih Berjalan. "PikirCo. https. // www. thinkco. com/php-code-showing-instead-of-running-2694209 (diakses 23 Januari 2023)

Anda perlu menambahkan penangan di Apache untuk menangani kode php

Edit dengan perintah sudo vi /etc/httpd/conf/httpd. conf

Tambahkan dua penangan ini

  AddType application/x-httpd-php .php
  AddType application/x-httpd-php .php3

pada posisi yang ditentukan di bawah ini



 AddType application/x-compress .Z
 AddType application/x-gzip .gz .tgz

--Add Here--



untuk detail lebih lanjut tentang penangan AddType

http. // httpd. apache. org/dokumen/2. 2/mod/mod_mime. html

Mengapa file PHP saya ditampilkan sebagai teks biasa?

Jika karena beberapa alasan, PHP tidak diinstal di server ATAU PHP tidak dikonfigurasi untuk bekerja dengan server web Anda , itu tidak ada lagi . Itu hanya dilihat sebagai file teks yang dirender sebagai teks HTML di browser.

Mengapa PHP tidak berfungsi di HTML?

File php selalu dapat membaca dan menampilkan kode HTML, tetapi HTML tidak mengurai kode php secara otomatis. Untuk melakukannya, Anda harus melakukan penyesuaian pada. file htaccess . Setelah selesai, kode php akan ditampilkan dalam file HTML tanpa masalah.

Mengapa file PHP saya tidak berjalan?

Jika Anda menjalankan skrip PHP di komputer Windows, Anda perlu menginstal PHP secara manual . Jika Anda belum melakukannya, kode PHP Anda tidak akan dijalankan. Petunjuk untuk proses instalasi, versi, dan persyaratan sistem tercantum di situs web PHP.

Bagaimana cara mengaktifkan PHP di apache2?

Konfigurasikan Apache untuk Melayani Halaman PHP dari Direktori Pengguna. .
Langkah 1. Edit file konfigurasi PHP. sudo gedit /etc/apache2/mods-enabled/php5. conf. .
Langkah 2. Simpan perubahan, dan keluar dari emacs. kontrol-x, kontrol-s
Langkah 3. Mulai ulang Apache, dan Anda selesai. sudo /etc/init. d/apache2 restart