PHP Programming in Ubuntu
Installing PHP on Ubuntu
You need to install the Apache2 package to run PHP. Before doing this, make sure that you have the required dependencies installed. For example, if you want your Apache2 installation to be able to serve PHP files as well as static content from a directory called /var/www/my_website/, then create that directory first:
$ sudo mkdir -p /var/www/my_website
You can now proceed with installing apache2 and its associated PHP module:
$ sudo apt-get install apache2 php5 libapache2-mod-php5 php5-gd php5-mysql php5-curl php5-imagick libapache2-mod-php7
You will also need MySQL and MariaDB (a fork of MySQL) in order for some modules to work properly. You might also want to consider installing some additional packages such as ImageMagick and GD Library which are needed by many image manipulation libraries like Imagick or Gmagick.:
How to install the PHP Server
Install the PHP Server. To install the PHP Server, open a terminal window and enter the following commands:
sudo apt-get update sudo apt-get install php5-cli sudo apt-get install php5-mysql sudo apt-get install php5-fpm sudo apt-get install php5-gd sudo apt-get install php5-curl sudo apt-get install php5-intl
Setting up localhost
Now that you've got some idea of what Apache2, MySQL and PHP are all about, let's set up a localhost.
To install Apache2 in Ubuntu 14.04, open the terminal and type:
sudo apt-get install apache2
To install MySQL 5.6 in Ubuntu 14.04, open the terminal and type:
sudo apt-get install mysql-server php5-mysql libapache2-mod-php5 libmysqlclient18 mariadb-client mariadb-server mariadb-client phpmyadmin
First PHP script
In Linux, you can write a simple PHP script. To run the script, open a terminal window and type:
```
sudo nano myfirstphpscript.php
```
This will open the nano text editor in your default directory. You should see something like this:
```
``*
Configuring Apache2 with PHP 5
Set up Apache2 with PHP5
First, you need to install Apache2 on your server. This can be done by running the following command:
(sudo) apt-get install apache2
Now that Apache2 is installed, we will create a file called php.ini which will enable us to configure our server for PHP5 and also set some other options (these options are explained below).
Note: If you have already configured Apache on your system and it’s not currently running, then it will be necessary for you to start/restart it before proceeding any further from this point onwards.
Installing MySQL
To install MySQL, use the following commands:
sudo apt-get install mysql-server php5-mysql
To install PHP modules for MySQL:
sudo apt-get install php5-mysqlnd libapache2-mod-php5 libmysqli1 libmcrypt4 php5-curl php5-gd
With these instructions you can set up a PHP development environment in Ubuntu.
This tutorial will teach you how to set up a PHP development environment on Ubuntu.
First, we’ll install Apache2 and PHP 5. Then we’ll create a database server and configure Apache2 with PHP 5 support. Finally, we’ll install MySQL so that you can work with databases from your scripts.
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.