Saturday, December 28, 2019

Installing PHP on Linux

It can be really helpful to have PHP installed on your home computer. Especially if youre still learning. So today Im going to walk you through how to do so on a PC with linux. First things first, youre going to need Apache to be installed already. 1. Download Apache, this will assume you download the latest version as of this publication, which is 2.4.3. If you use a different one, be sure to change the commands below (since we use the name of the file). 2. Move this to your src folder, at / usr/local/src, and run the following commands, which will un archive the zipped source, in a shell: cd /usr/local/srcgzip -d httpd-2.4.3.tar.bz2tar xvf httpd-2.4.3.tarcd httpd-2.4.3 3. The following command is semi-optional. If you dont mind the default options, which installs it to /usr/local/apache2, you can skip to step 4. If youre interested as to what can be customized, then run this command: ./configure --help This will give you a list of the options you can change for when it installs. 4. This will install Apache: ./configure --enable-somakemake install Note: if you get an error that says something like this: configure: error: no acceptable C compiler found in $PATH, then you need to install a C compiler. This probably wont happen, but if it does, Google install gcc on [insert your brand of linux] 5. Yay! Now you can start up and test Apache: cd /usr/local/apache2/bin./apachectl start Then point your browser to http://local-host and it should tell you It Works! Note: if you changed where Apache installed, you should adjust the above cd command accordingly. Now that you have Apache installed, you can install and test PHP! Again, this assumes youre downloading a certain file, which is a certain version of PHP. And again, this is the latest stable release as of writing this. That file is named php-5.4.9.tar.bz2 1. Download php-5.4.9.tar.bz2 from www.php.net/downloads.php and again place it in your /usr/local/src then run the following commands: cd /usr/local/srcbzip2 -d php-5.4.9.tar.bz2tar xvf php-5.4.9.tarcd php-5.4.9 2. Again, this step is semi-optional as it deals with configuring php before you install it. So, if you want to customize the installation, or see how you can customize it: ./configure --help 3. The next commands actually install PHP, with the default apache install location of /usr/local/apache2: ./configure --with-apxs2/usr/local/apache2/bin/apxsmakemake installcp php.ini-dist /usr/local/lib/php.ini 4. Open the file /usr/local/apache2/conf/httpd.conf and add the following text: SetHandler application/x-httpd-php Then while in that file make sure it has a line that says LoadModule php5_module modules/libphp5.so 5. Now you will want to restart apache and verify that php is installed and woking correctly: /usr/local/bin/apache2/apachectl restart No make a file called test.php in your /usr/local/apache2/htdocs folder with the following line in it: phpinfo(); ? Now point your favorite internet browser at http://local-host/test.php and it should tell you all about your working php installation.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.