Difference between revisions 24744 and 24754 on iswikibooks{{eyða|Nokkurnveginn sama síðan og [[PHP/Uppsetning]]. Munurinn liggur í því að þessi síða hefur kafla á ensku en á hinni hafa þeir verið þýddir. Sjá [{{FULLURL:Kerfissíða:Bera_saman_síður|page1=PHP%2FUppsetning&rev1=&page2=PHP%2FSetup+and+Installation&rev2=}} samanburð]}}⏎ = Uppsetning = Þar sem PHP er forritunarmál sem keyrt er á vefþjóni er möguleiki á að þú þurfir að eyða smá tíma í uppsetningu á vefþjóni til að geta hannað og keyrt forritin sem þú skrifar. Sem betur fer er PHP nokkuð auðveldar í uppsetningu en til dæmis J2EE, en þú ættir samt að vera aðeins að þér í uppsetningu á hinum ýmsu "bragðtegundum" af uppsetningum á PHP, vefþjónum og gagnagrunnum (oftast MySQL). Hér fyrir neðan mun ég kynna fyrir þér þau skref sem þú þarft til að geta sett upp PHP þróunarumhverfi með MySQL gagnagrunni. == Linux == Ef að tölvan þín er að keyra Linux eru töluverðir möguleikar á því að Apache (vefþjónninn), PHP og MySQL séu núþegar uppsettir fyrir þig. Þessi mjög svo vinsæla samþætting er mjög oft kölluð LAMP (e. '''L'''inux '''A'''pache '''M'''ySQL '''P'''HP). Ef einhverjir af þessum hlutum eru ekki til staðar er líklegt að þú þurfir að setja upp handvirkt eftirfarandi pakka: * Apache eða Lighttpd * PHP * MySQL eða Postgres * Gagnagrunnsviðbót fyrir PHP === Debian eða skyld stýrikerfi === Á Debian eða skyldum stýrikerfum (Ubuntu meðtalið) getur þú notað eftirfarandi skipanir: <source lang="bash"> apt-get install php5 ## Vefþjónn #### Ef þú vilt nota Apache apt-get install apache2 libapache2-mod-php5 a2enmod php5 service apache2 restart ## -eða- #### Ef þú vilt nota Lighttpd apt-get install lighttpd php5-cgi lighttpd-enable-mod fastcgi fastcgi-php service lighttpd restart ## Gagnagrunnur #### Ef þú vilt nota Postgres apt-get install postgres-server postgres-client php5-pg ## -eða- #### Ef þú vilt nota MySQL apt-get install mysql-server mysql-client php5-mysql </source> {{note|Ubuntu}} Ef þú velur að nota Ubuntu með Apache og MySQL væri sniðugt fyrir þig að kíkja á samfélagssíðuna fyrir slíka uppsetningu: [https://help.ubuntu.com/community/ApacheMySQLPHP ubuntu lamp wiki]. === Gentoo === Fyrir þá sem keyra Gentoo Linux þá hefur gentoo-wiki síðan þessar upplýsingar um uppsetninguna:[http://gentoo-wiki.com/HOWTO_Apache2_with_PHP_MySQL Apache2 with PHP and MySQL]. Í grunninn er þetta það sem þú vilt gera undir Gentoo: <source lang="bash"> emerge apache emerge mysql emerge mod_php </source> === RPM-based === Uppsetningarnar eru mismunandi eftir því hvaða Linux útgáfu þú ert að keyra. T.d. á Fedora kerfi eru skipanirnar nokkurnvegin svona: <source lang="bash"> yum install httpd yum install php yum install mysql yum install php-mysql </source> Það er eiginlega algjörlega útilokað að tækla allar útgáfurnar hér, þannig að ef þú ert að keyra aðra útgáfu af Linux en nefnd er hér fyrir ofan skaltu grípa í handbókina eða góðan vin til að aðstoða þig. Ein mjög góð leið til að fá PHP til að "fara í gang" á *nix tölvu er að þýða það beint frá frumkóðanum. Það er ekki eins erfitt og það hljómar og það eru góðar leiðbeiningar í [http://au.php.net/manual/en/install.unix.php PHP handbókinni]. == Windows == {{Hreingera}} PHP on Windows is also a very popular option. On a Windows platform, you have the option to use either the open source [http://httpd.apache.org/ Apache] web server, or the native Internet Information Services (IIS) server from Microsoft, which can be installed from your Windows CD. When you have one of these servers installed, you can download and install the appropriate PHP Windows binaries distributions from [http://www.php.net/downloads.php PHP download page]. The installer version requires less user-interaction. For increased performance you will want to use FastCGI. There is a wikibook that will assist you on [[IIS and FastCGI|Setting up IIS with FastCGI]]. === Databases === On Microsoft Windows you must always install your own database. Two popular choices are the open source Postgres, and MySQL. Postgres is more liberally licensed, and is free to use for commercial purposes. ==== Postgresql ==== Official Zend documentation: [http://us.php.net/pgsql http://us.php.net/pgsql] Postgres is simple and easy to install, browse to [http://www.postgresql.org/ftp/binary/v8.3.0/win32/ http://www.postgresql.org/ftp/binary/v8.3.0/win32/] and download the exe and double-click. ==== MySQL ==== Official MySQL documentation: [http://us.php.net/mysql http://us.php.net/mysql] You might wish to install the MySQL database. You can download the Windows version of [http://dev.mysql.com/downloads/ MySQL], and follow the installation instructions. If you have PHP 4, you do not need to install the equivalence of php-mysql on Linux, as MySQL support is built-in in Windows distributions of PHP. In PHP 5 you will need to uncomment the following line in your php.ini file (that is, remove the ';' at the beginning of the line): <source lang="ini"> ;extension=php_mysql.dll </source> === Bundled Package === If you find all the above too much a hassle, you have another option. Driven by the eternal desire to do things the safe/easy way, several conveniently packaged AMP bundles of Apache/MySQL/PHP can be found on the net. One of them is [http://sourceforge.net/projects/phptriad/ PHPTriad]. Or, you can try [http://www.uniformserver.com Uniform Server]. It is a small [[WAMP]] Package. (The acronym ''WAMP'' refers to a server stack where Microsoft Windows is the operating system, Apache is the Web server, MySQL handles the database components, and PHP, Python, or PERL represents the dynamic scripting languages). <ref>http://www.webopedia.com/TERM/W/WAMP.html</ref> Uniformserver is packaged as a self-extracting zip archive, and is easy to use. After trying it out you can simply delete the directory and everything is clean. [http://www.apachefriends.org/en/xampp-windows.html XAMPP for Windows] is another WAMP server that is easy to use. In addition, is has an installation option that allows you to install it on a computer if you have administration rights. XAMPP has options to run PERL and JAVA (on a tomcat server). A number of other portable Windows AMP package choices are summarized at [http://www.portablefreeware.com/?sc=125 List of portable Web Servers]. Also, a package installer called '''WAMPserver''' is available. It simply installs Apache, PHP and MySQL on windows with ease. [http://www.wampserver.com/en/ http://www.wampserver.com/en/] === Easy Windows Setup Instructions === 1) PHP authoring environment * Any text editor will do, but I recommend one with syntax coloring especially for someone new to coding or PHP. Notepad++ is my favorite so far with its ease of use, customizability and the ability to collapse tags. All editor help will be in reference to Notepad++ * Install Notepad++. Download the binary file from here: http://notepad-plus.sourceforge.net/uk/site.htm 2) PHP running environment * Now that you have the ability to create and save PHP files you need an environment that can process them and generate the output that your browser displays. There are two ways to accomplish this. # Get a web host that supports PHP and upload your files every time you make a change. # Use you own computer as a personal server with PHP support, and only upload final versions to a web host. * Accomplishing 2. above is actually easier than you think (assuming you are running Windows). # Download The uniform server. Here is the link to the latest version: http://sourceforge.net/projects/miniserver/files/ # Run the self-extracter UniServerX_Y_Z.exe. Copy the directory to your "C:" drive so the full path is "C:\UniServer". # In the directory where you had it extract hit the "Start.exe" file to get the server running # Place any files and subfolders you want the server to read and process in the "www" folder. # Your web browser should open to "http://localhost/index.php" * Now you have the resources to effectively edit PHP documents and process them on your own computer. * Here is how to create a test page # Inside "C:\UniServer\www\", create a webpage called "test.php" # Edit "test.php" with Notepad++, and copy the following <source lang="html4strict"> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html;charset=utf-8" /> <title>Test Page</title> <meta name="Description" content="Test Page" /> <meta name="Keywords" content="Test,Page" /> </head> <body> <?php $string = 'Hello world! <br/>'; echo $string; print $string; printf('%s', $string); ?> </body> </html> </source> # Save the webpage as "C:\UniServer\www\test.php" # Open "http://localhost/test.php" in your web browser to view the page. You should see: Hello world!<br/> Hello world!<br/> Hello world!<br/> # (Optional: Follow these instructions for how to make PHP code work with webpages that end in ".html" in addition to ".php": [http://www.desilva.biz/php/phpinhtml.html http://www.desilva.biz/php/phpinhtml.html]) == Mac OS X == Mac OS X comes with Apache server as standard, and enabling it is as simple as checking the box next to 'Personal Web Sharing' in the 'Sharing' section of System Preferences. Once you have done this you can place files in /Library/WebServer/Documents to access them on your server. Mac OS X does come with PHP but the installation lacks any significant quantity of extensions, so if you want any you're going to have to install PHP yourself. You can do this by following the instructions in Apple's [http://developer.apple.com/internet/opensource/php.html Developer Connection], or you can download an automatic installer such as the ones available at [http://www.entropy.ch/software/macosx/php/ Entropy]. Once you've done one of those, you'll have a server with PHP running on your Mac. To install MySQL just download and run the [http://www.serverlogistics.com/mysql.php OS X installer package] or use [http://www.apachefriends.org/en/xampp-macosx.html XAMPP for MacOS X]. If you use unix or learning it, however, compiling might be the way to go for all three, or just the ones you like. The advantage is that you can choose exactly which extensions you want for PHP and Apache. Also you can choose which versions to compile together. To do this make sure you have the Developer Tools installed. They are shipped with OS X. = How Do I Know My Setup is Working? = After you have successfully completed the previous section, it's time to make sure that everything went well. You also get the chance to write your very first PHP scripts! Open your favourite ''plain'' [[w:text editor|text editor]] (''not'' Microsoft Word or another [[wikipedia:word processor|word processor]]), and type the following magical line: <source lang="php"> <?php phpinfo(); ?> </source> Save it as phpinfo.php in your web server's root document directory. If you are using a web hosting server, upload it to the server to where you would place HTML files. Now, open up your web browser, and go to <nowiki>http://localhost/phpinfo.php</nowiki>, or <nowiki>http://your-web-hosting-server.com/phpinfo.php</nowiki> if you are using a web hosting server, and look at the output. Now scroll down that page and make sure there is a table with the title "mysql", and the top row should read: "MySQL support: enabled". If your output does not have this, your particular installation of PHP does not have MySQL support enabled. Note that this test doesn't tell you whether MySQL server is running. You should fire up your MySQL client and check before you proceed. Some dedicated php or script editors even have color coding of different words which can be very useful for finding mistakes. A free implementation of this is the powerful Notepad++, available from [http://sourceforge.net/projects/notepad-plus Sourceforge] and licensed under the GPL. <references/> All content in the above text box is licensed under the Creative Commons Attribution-ShareAlike license Version 4 and was originally sourced from https://is.wikibooks.org/w/index.php?diff=prev&oldid=24754.
![]() ![]() This site is not affiliated with or endorsed in any way by the Wikimedia Foundation or any of its affiliates. In fact, we fucking despise them.
|