Configuring a LAMPP server for PHP development/Linux desktop

LAMPP server for PHP development, This article offers unique instructions for configuring a LAMP server, not handiest for Joomla!.

However it additionally have to paintings pleasant for PHP development in popular.

For facts on installing other stacks see Installing_Joomla_on_Debian_Linux

These commands ought to paintings satisfactory on any Linux-primarily based distribution.

Which includes Debian, Ubuntu, Linux Mint, Xubuntu, Kbuntu and others.

Note: To complement the safety of your computer, set up a firewall to dam external incoming site visitors to your Web service. You may additionally must trade some directives to your web page configuration file to serve handiest requests to the localhost address.

LAMPP server for PHP development,Installation

NOTE: You need a strong Internet connection for this educational. If you formerly tried to put in the LAMP stack and failed for any motive, go to this web page and follow the instruction to delete any server configuration and start from scratch “How to do away with the LAMP stack”

LAMPP server for PHP development,The installation of a LAMP server on Linux is easy. Just comply with those instructions:

  • Open a terminal and kind:
sudo apt-get install apache2 php5-mysql libapache2-mod-php5 mysql-server phpmyadmin php5-curl
  • Say yes [Y] whilst the package supervisor asks you down load and deploy the programs. This step will make an effort relying on your connection pace.
  • At a few point the installer will ask you for the MySQL root password. Use any password you want. For this example we are going to use “myadmin”.
  • The installer will ask for “the Web server that should be mechanically configured to run phpmyadmin”. Press the [spacebar] to pick “apache2” and press [enter]. NOTE: Make certain the choice is marked with an asterisk [*].
  • The installer will ask for “Configure database for PHPMyAdmin with dbconfig-commonplace”. Choose “” and press [enter].
  • The installer will ask for “password of the database’s administrative person”. Use any password you like, however for this case we’re going to use “myadmin”.
  • The installer will ask for “mysql software password for PHPMyAdmin”. Use any password you want, but for this case we are going to use “myadmin”.
  • If no errors have being displayed, the set up is finished.

LAMPP server for PHP development,Apache Installation Test

LAMPP server for PHP development,Open your Web browser and sort within the deal with bar “localhost” and press [enter].

Normally Apache display a test page with some textual content like this:

It works!
This is the default Web page for this server.
The Web server software is running but no content has been added yet.

LAMPP server for PHP development,PHP Installation Test

To confirm that the PHP server is operating, create a quick test report using the command line.

Open a terminal and type:

echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/test.php 
  • Open your Web browser and type inside the deal with bar “localhost/take a look at.Php” and press [enter].
  • The subsequent aspect you should see for your browser is an extended web page displaying facts about the PHP server. If not, the set up become now not successful.
  • Once the PHP server is operating great we don’t want that test document anymore. Type the subsequent command on your terminal to delete the record:
sudo rm /var/www/html/test.php

LAMPP server for PHP development, PHPMyAdmin Installation Test

  • Open your Web browser and sort within the cope with bar “localhost/phpmyadmin” and press [enter].
  • The subsequent thing you should see is the PHPMyAdmin login web page. If no longer, then maximum in all likelihood you skipped or did not mark the option “apache2” at the question “Web server that must be routinely configured to run PHPMyAdmin”. To restore this problem, purge the set up and start yet again.
  • Login to PHPMyAdmin with the subsequent credentials:
  • username = root
  • password = myadmin
  • You must be capable of login generally and have no errors messages.

A server for PHP development, Understanding the Folder Structure

Configuring server for PHP development,There are several folders and files.

That the server makes use of to store the configurations of the LAMP services and to shop the documents of your hosted Websites.

Server for PHP development,Apache Default Web Site Folder

Location: “/var/www/”

Description: By default the Apache server enables a take a look at Website and stores the wWebsite files in that area.

Every time you go to the page http://localhost, the browser shows the page placed at “/var/www/”.

With your document browser, navigate to “/var/www/”. There should be a document called “index.Html”.

Change the content material of the file to whatever you want and refresh the Web page to see the changes.

LAMPP server for PHP development,Apache Web Sites Configuration Files

Location: /etc/apache2/websites-available/

Description: You can host multiples web sites at the equal server.

This folder incorporates a configuration file for each web site.

LAMPP server for PHP development, Apache Configuration Files

Location: “/etc/apache2/apache2.Conf” Location: “/etc/apache2/envvars”

Description: These documents include critical information about the Apache provider.

LAMPP server for PHP development,Apache Ports Configuration File

Location: “/and many others/apache2/ports.Conf”

Description: This record configures what port the Apache server will concentrate to for HTTP requests.

By default, HTTP requests are assigned to port eighty however you could adjust or add more ports.

Apache Log Files

Location: “/var/log/apache2/”

Description: This folder includes numerous documents to hold track of occasions for your Apache.

Web server along with errors inside the offerings, errors inside the code of your site and failed authentication attempts.

This is a superb vicinity to look whilst some thing isn’t working or you think a person is attempting to breach your server safety.

LAMPP server for PHP development, Configuration

Enabling mod_rewrite

LAMPP server for PHP development, Enabling mod_rewrite The mod_rewrite module uses a rule-primarily based rewriting engine.

based totally on a PCRE normal-expression parser to rewrite requested URLs on the fly.

By default, mod_rewrite maps a URL to a filesystem course.

However, it could also be used to redirect one URL to some other URL, or to invoke an internal proxy fetch.

For extra statistics, visit http://httpd.Apache.Org/docs/modern-day/mod/mod_rewrite.Html

  • Open a terminal and type:
sudo a2enmod rewrite
  • Now that the rewrite module is enabled, restart Apache.
sudo service apache2 restart
  • done

LAMPP server for PHP development, Deploying a New Site Folder Structure

By default the Web server is hosting the documents in the vicinity “/var/www”.

However for safety reasons and to keep away from possession issues.

We’re going to use every other vicinity to host our Website files.

Let’s create a brand new folder to store the Web files and the log documents of the web page.

Open a terminal and type:

 mkdir /home/youruser/lamp/
 mkdir /home/youruser/lamp/public_html/
 mkdir /home/youruser/lamp/logs/

NOTE: You can area your new website folders at any region.

This is simply an instance. Replace “youruser” with an real Linux username.

To keep the Website files we are going to use the folder “public_html”.

For our log files, we are going to use the folder “logs”.

LAMPP server for PHP development, Creating the New Site

LAMPP server for PHP development, To create and enable a brand new site for your server follow these steps:

NOTE: gedit is a commonplace Linux editor however you can use any other opportunity you want together with geany, nano, vim, percent and many others.

  • Open a terminal an type:
sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/mydevsite.conf

NOTE: “mydevsite” is the call of the new website used in this case. You can use any other call you like.

  • Open the website online configuration
sudo gedit /etc/apache2/sites-available/mydevsite.conf
  • The content of that file should be something like this:
The content of that file should be something like this:
 <VirtualHost *:80>
        # The ServerName directive sets the request scheme, hostname and port that
        # the server uses to identify itself. This is used when creating
        # redirection URLs. In the context of virtual hosts, the ServerName
        # specifies what hostname must appear in the request's Host: header to
        # match this virtual host. For the default virtual host (this file) this
        # value is not decisive as it is used as a last resort host regardless.
        # However, you must set it for any further virtual host explicitly.
        #ServerName www.example.com

        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html

        # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
        # error, crit, alert, emerg.
        # It is also possible to configure the loglevel for particular
        # modules, e.g.
        #LogLevel info ssl:warn

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        # For most configuration files from conf-available/, which are
        # enabled or disabled at a global level, it is possible to
        # include a line for only one particular virtual host. For example the
        # following line enables the CGI configuration for this host only
        # after it has been globally disabled with "a2disconf".
        #Include conf-available/serve-cgi-bin.conf
</VirtualHost>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
  • Make some modifications to make it look like this, or simply copy and paste it:
<VirtualHost *:80>
        ServerAdmin webmaster@localhost
 
        DocumentRoot /home/youruser/lamp/public_html
        <Directory />
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Order allow,deny
                Allow from all
                Require all granted
        </Directory>
 
        ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
        <Directory "/usr/lib/cgi-bin">
                AllowOverride All
                Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
                Order allow,deny
                Allow from all
        </Directory>
 
        ErrorLog /home/youruser/lamp/logs/error.log
 
        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn
 
        CustomLog /home/youruser/lamp/logs/access.log combined
 
     Alias /doc/ "/usr/share/doc/"
     <Directory "/usr/share/doc/">
         Options Indexes MultiViews FollowSymLinks
         AllowOverride All
         Order deny,allow
         Deny from all
         Allow from 127.0.0.0/255.0.0.0 ::1/128
     </Directory>
 </VirtualHost>

NOTE: Replace “youruser” with your current user name.

Save your changes. Now we need to enable the web site. In a terminal type:

sudo a2ensite mydevsite 
  • Lets disable the default site, since we don’t need it anymore.
sudo a2dissite 000-default
  • Restart Apache to complete the process. In a terminal type:
sudo service apache2 restart 
  • To test out our new site, let’s create a quick test file. In a terminal type:
echo "<?php echo 'Hello world, today is is: '.date('Y/m/d'); ?>" | tee /home/youruser/lamp/public_html/today.php 

NOTE: Replace “yourname” along with your cutting-edge user call.

Open your browser and navigate to “localhost/today.Php”. If everything is operating k, you ought to see some thing like this:

Hello world, today is is: 2012/05/05

LAMPP server for PHP development,Enabling Additional Ports

Note: If you have no plans to show your neighborhood web site to another individual over the Internet, skip this section.

With the last configuration you ought to be capable of get right of entry to your web page and get entry to it from another laptop linked to your LAN.

If your computer is connected to the Internet and additionally has an assigned Public IP.

You could get right of entry to your web page using that IP from any Web browser.

Note that a few ISPs do not permit HTTP visitors (HTTP = port eighty) over dynamic IP addresses.

To remedy this, you need to configure Apache to reply to requests from a exceptional port.

In this situation we are going to use the port range 8080 which is simple to don’t forget.

If you’re using a router to connect with the Internet, you have to configure a port forwarding placing to your router to permit other people see your local website online.

Google “how to do port forwarding” for your current router model.

If you do not know the difference between a Static IP, Dynamic IP, Private IP and a Public IP.

We propose you to do a Wikipedia studying approximately those subjects.

  • Open a terminal and type:

Note: If you have no plans to show your local site to another person over the Internet, skip this section.

Enabling Additional Ports

With the last configuration you should be able to access your page and access it from another computer connected to your LAN.

If your computer is connected to the Internet and also has an assigned Public IP, you can access your site using that IP from any Web browser.

Note that some ISPs do not allow HTTP traffic (HTTP = port 80) over dynamic IP addresses.

To solve this, you need to configure Apache to reply to requests from a different port.

In this case we are going to use the port number 8080 which is easy to remember.

If you are using a router to connect to the Internet, you have to configure a port forwarding setting on your router to let other people see your local site.

Google “how to do port forwarding” on your current router model.

If you don’t know the difference between a Static IP, Dynamic IP, Private IP and a Public IP.

We recommend you to do a Wikipedia reading about these topics.

  • Open a terminal and type:
sudo gedit /etc/apache2/ports.conf 
  • Find the line “listen 80” and insert this line underneath:
Listen 8080 
  • Save the changes.
  • Open your new site configuration.
sudo gedit /etc/apache2/sites-available/mydevsite 
  • Find this directive “<VirtualHost *:80>” and make the following modification:
 <VirtualHost *:80 *:8080>  
  • Save the changes.
  • Restart Apache to complete the process. In a terminal type:
sudo service apache2 restart 
  • To test your new configuration, try to access your site from another computer over Internet. Just type your IP in the browser’s address bar and press enter. If the request fails, try the new alternative port like this: xxx.xxx.xxx.xxx:8080

Preventing Ownership and Permissions Problems

On Linux machines, report permissions are an important aspect.

Linux uses a mechanism to manipulate what users can do and cannot do approximately folders, documents or even the execution of applications.

This mechanism includes parameters, the possession and the permissions.

Files and Folders Ownership

Ownership has parameters: The owner and the organization.

The “owner” is the person that owns the report or folder and is represented through a “username”.

In Linux persons, applications and offerings use usernames. On maximum Linux distributions.

The Apache service runs underneath the username “www-information”.

The “organization” is used to accomplice users into an logical organization.

This parent is useful when an administrator desires to supply or deny permissions to numerous.

users with one single command and no longer user by means of consumer.

Files and Folders Permissions

The permissions have 3 parameters that represent document and folder permissions for the owner, the group and others.

These quantity range from zero to 7, and suggest the subsequent:

  • 4= permission to study
  • 2 = permission to write down
  • 1 = permission to execute
  • 0 = no permissions in any respect
  • Note: “Others” represents all of us. This parameter is used to provide permission to all and sundry irrespective of the user or the organization they belong to. This parameter must be set with care beneath certain conditions. Granting incorrect permissions to touchy files and folders can purpose safety issues.

For instance, if we’ve a document with permissions inclusive of “644”, it method (proprietor=study+write)(organization=examine)(others=examine).

To get extra information about the Linux file systems and report permissions study this newsletter.

Adding Yourself to the Apache Group and Modifying Permissions

For this situation, your username can be “youruser”. On maximum Linux distributions.

The Apache provider runs on the user “www-statistics” and the organization “www-information”.

We want to encompass our consumer “youruser” within the “www-facts” organization in order to set permissions to the Web server documents and have no troubles while we must edit them.

  • To upload “youruser” to the Apache group, open a terminal and sort:
sudo adduser youruser www-data
  • Now we need to change the owner and group of all our Web server files to owner “www-data” and group “www-data”.
sudo chown -R www-data:www-data /home/youruser/lamp/public_html 
  • Finally, we have to set the correct folder permission so both Apache and our user can edit the files with no problems. On a terminal type:
sudo chmod -R 775 /home/youruser/lamp/public_html

Common Problems and Confusions

When Joomla creates documents on extension installations or some other operatio.

it uses the default masks 755 for folders and 644 for documents.

These permissions are correct and secure for production servers.

However it’ll give us problems on our local server due to the fact our editor will no longer be capable of edit those files and folders.

To repair these troubles, genuinely run once more this command:

sudo chmod -R 775 /home/youruser/lamp/public_html

In the case you manually flow documents from your non-public folders to the server Web folder “public_html”.

The ones new documents most in all likelihood will be owned by your username.

This can reason issues if the server needs to regulate or delete records.

To prevent this trouble, each time you flow or replica facts for your server.

Web folder you need to set the proper proprietor and group permissions for all those new files.

Open a terminal and run this command:

sudo chown -R www-data:www-data /home/youruser/lamp/public_html

Note: If your server has too many documents, those commands may be gradual but you could constantly set a greater particular path to apply permission in fewer documents.

An distinctive alternative is to configure the default Apache owner and institution.

For all new documents created with the aid of the server the ones settings are used.

We can change the within the environment variables report. Run this command to open and edit the record:

sudo gedit /etc/apache2/envvars

Find the subsequent traces and trade them this manner (update “youruser” along with your modern-day username):

export APACHE_RUN_USER=youruser
export APACHE_RUN_GROUP=www-data

Restart apache with the following command:

 

sudo service apache2 restart

Other Configurations

  • Open a terminal and type:
  •  
 sudo gedit /etc/php5/apache2/php.ini
  • Find the line:
output_buffering =
  • Set the value to “= Off”.
  • Find the line:
post_max_size =
  • Set the value to “= 20M”.
  • Find the line:
upload_max_filesize =
upload_max_filesize =
  • Set the value to “= 20M”.
  • Save the changes.
  • Type in your terminal:
sudo service apache2 restart

Enforcing Security

Enforcing Security

Since your laptop is now strolling Web offerings.

These offerings are listening for requests and will respond to anybody.

who has the appropriate IP and port.

In different words, other people in your LAN and Internet can get admission to your nearby web page without your permission.

They could even try and crack or hack your workstation.

To save you this, you want to put in a firewall and “deny” through default any external incoming requests on your laptop.

For Linux customers, there may be a nice and easy firewall referred to as “Uncomplicated Firewall”.

To deploy the consumer interface and control the firewall from your desktop, just observe these steps:

  • Open a terminal and sort:
sudo apt-get install gufw

Note: You also can installation the utility from the Software Manager.

  • Open the application. When the set up finishes, press the “free up” button and type your administrative password.
  • Set “Status = On” and “Incoming = Deny”. Leave the relaxation of the settings at their default values.
  • To take a look at your firewall, just try to connect with your neighborhood web site from a neighborhood pc to your LAN or a far off pc over the Internet. When the firewall status is “Status = On”, you should not be capable of join at all.
  • Now quickly change the fame of your firewall to “Status = Off” and try to join again. People have to be able to see your neighborhood web page just high-quality. Remember to set “Status = On” after this test.

Note: In this academic we’re denying any incoming external requests to any port. As a side notice, you may additionally Deny all incoming requests and manually permit incoming requests to few precise ports if you desire, but those forms of settings are as much as you. Since a PC computing device is not a server, it’s miles okay to deny all incoming visitors by way of default.