LAMP Installation and Important PHP Configurations on Ubuntu


PHP: PHP (Hypertext Preprocessor) is a widely-used open-source server-side scripting language that is specifically designed for web development. It was originally created by Rasmus Lerdorf in 1994 and has since evolved into a powerful language used by millions of developers worldwide.

PHP is primarily used to develop dynamic web pages and web applications. It allows developers to embed PHP code within HTML, making it easy to mix server-side logic with the presentation layer. PHP scripts are executed on the server, and the resulting HTML is sent to the client's browser.

Let us get started with installing PHP in Ubuntu. In order to test our PHP pages, a server is needed. MySQL database is also required to manage or save data. Don't worry you don't have to buy a web hosting for testing your Web pages, I'm going to tell you how to install your own local host web server.

LAMP is basically a collection of software which you require to create the dynamic website and web applications. These tools are capable enough that you don't require any other tool for the purpose. The interesting thing about LAMP is that all the tools in it are free and open-source.

Software components of LAMP

  • Linux is an operating system which UNIX-like and it's free and open source for development and distribution. All of the Linux based operating systems provide Lamp packages.

  • Apache is an HTTP Server which is used to process the HTTP request i.e. the webpages. It is one of the most popular web servers used by the developers around the globe. It is developed and maintain by the Apache Software Foundation.

  • MySQL is the Role of the RDBMS (Relational Database Management System) in LAMP bundle is played by MySQL. It helps us to save and manage data efficiently.

  • PHP is a server-side scripting language used to interact with web server. It embeds with the HTML code.

To install a LAMP (Linux, Apache, MySQL, PHP) stack on Ubuntu and configure important PHP settings, follow the steps below:

Step 1: Update system packages

Open a terminal and run the following commands to update the package lists for upgrades and new package installations:

sudo apt update
sudo apt upgrade

Step 2: Install Apache

Install the Apache web server by running the following command:

sudo apt install apache2

After the installation, Apache should start automatically. You can verify its status by running:

sudo systemctl status apache2

Step 3: Install MySQL

Install the MySQL database server by running the following command:

sudo apt install mysql-server

During the installation, you'll be prompted to set a root password for MySQL.

Step 4: Install PHP

Install PHP and necessary modules by running the following command:

sudo apt install php libapache2-mod-php php-mysql

Step 5: Configure PHP

To modify PHP settings, you need to edit the php.ini configuration file. Open it in a text editor using the command:

sudo nano /etc/php/7.x/apache2/php.ini

Note: Replace 7.x with the appropriate PHP version installed on your system.

Here are some important PHP configurations you might consider:

  • Memory Limit: Set the maximum amount of memory PHP can use. Look for the line memory_limit and adjust the value according to your requirements. For example, memory_limit = 256M.

  • File Uploads: Enable or adjust the maximum size for file uploads. Locate upload_max_filesize and post_max_size directives. Modify them to desired values. For example, upload_max_filesize = 20M and post_max_size = 25M for a maximum file upload size of 20 MB.

  • Timezone: Set the default timezone for your PHP scripts. Search for date.timezone and update it with the appropriate timezone value. For instance, date.timezone = America/New_York.

  • Error Reporting: Control the level of error reporting. Find the error_reporting directive and set it to the desired error reporting level. For example, error_reporting = E_ALL.

Once you've made the necessary changes, save the file and exit the text editor.

Step 6: Restart services to apply the changes, restart Apache:

sudo systemctl restart apache2

You now have a LAMP stack installed on your Ubuntu system with PHP configured. You can place your PHP files in the Apache document root directory (/var/www/html) and access them through a web browser.

Conclusion

By following these steps, you can install and configure a LAMP stack on Ubuntu, which provides a powerful environment for hosting PHP-based web applications. Apache serves as the web server, MySQL handles the database management, and PHP allows for dynamic content generation. Additionally, you can customize PHP settings in the php.ini configuration file to suit your specific requirements.

Updated on: 01-Aug-2023

72 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements