Installing and Configuring the LAMP Web Server for PHP Development

Many beginner web developers are switching to Linux-based distributions just to create their own stable web server for testing and debugging their projects. And projects are most often, of course, in PHP. In this article, I offer you my way to deploy the LAMP web server (Linux + Apache + MySQL + PHP) in a very accessible form.

I have been using this method for several years on .deb-based distributions. Previously, the web server was installed and worked fine on Debian, Mint, Ubuntu, LMDE (with some corrections) and now works on elementaryOS.

So, let's begin.

We assume in advance that our site should be accessible at mysite.zz, and the folder with the site files is located on the path /home/user/server/mysite.zz. The web server will be installed on ElementaryOS. Therefore, during the setup process, the standard text editor scratch-text-editor will be used. You can use any text editor by replacing “scratch-text-editor” with the name of your editor.

1. Installing the necessary packages


Enter in the terminal
sudo apt-get install apache2 mysql-server php5 phpmyadmin

When installing packages, we will need to pre-configure them in the pseudographic mode of the terminal.
In the first window, we are prompted to enter the password for the MySQL user "root". Enter the password and confirm it:
password entry for MySQL root user
image

password confirmation for MySQL root user

Next is the phpmyadmin setup.
Here we will be asked which web server to use to run phpmyadmin. Mark apache2 with the space bar and press enter:
choosing a web server to run phpmyadmin

On the next screen, read some information and press enter
some information

Next, we confirm the database setup using dbconfig-common:
configuration confirmation with dbconfig-common

Enter the password entered above into
the next three screens






2. Checking the server and phpmyadmin


We pass in any browser to the localhost address . If the server is installed normally, then we should see the server test page:
server test page

To access phpmyadmin, follow the link localhost / phpmyadmin . Enter the login “root” and the password entered earlier:
phpmyadmin login page

You can also change the phpmyadmin interface language there.

If everything is done correctly, then we will move on to managing our bases:
phpmyadmin homepage


3. Server setup


Create a link to phpmyadmin in / var / www
sudo ln -s /etc/phpmyadmin /var/www

Open the server configuration file:
sudo scratch-text-editor /etc/apache2/apache2.conf

and add the line at the end of the file:
ServerName localhost:80

/etc/apache2/apache2.conf


4. Adding our site


Open the hosts file to add our site:
sudo scratch-text-editor /etc/hosts

and add the line to the file
127.0.1.1	mysite.zz

/ etc / hosts


Create a website configuration file with the name “mysite.zz” in any folder with the contents

  ServerAlias mysite.zz www.mysite.zz
  DocumentRoot /home/user/server/mysite.zz
  
    AllowOverride All
  

and copy it with superuser privileges to / etc / apache2 / sites-available
sudo cp полный_путь_к_файлу /etc/apache2/sites-available/

We activate our website:
sudo a2ensite mysite.zz

We activate the mod-rewrite module (necessary for the implementation of the CNC):
sudo a2enmod rewrite

And restart the server:
sudo /etc/init.d/apache2 restart


5. Checking the operation of our site


Create an index.php file in our site’s folder (/home/user/server/mysite.zz), for example, with the following contents:

Next, in any browser, go to mysite.zz
test page of our site

If we see our page, then we did everything right.

6. Possible problems


Phpmyadmin is not available at localhost / phpmyadmin

To fix this error, you must reconfigure phpmyadmin
sudo dpkg-reconfigure phpmyadmin


The following problems were observed by me only in LMDE. But it is possible that they may occur in other distributions.

Access to our site may be denied by the server

To fix this problem, add the .conf extension to the name of the configuration file of our site in / etc / apache2 / sites-available
mysite.zz.conf

the contents of the file should be edited as follows

  ServerAlias mysite.zz www.mysite.zz
  DocumentRoot /home/user/server/mysite.zz
  
    AllowOverride All
    Require all granted
  

And site activation should be done by the name of the config
sudo a2ensite mysite.zz.conf


Login and password are not determined when entering phpmyadmin

To fix this error, make some changes to the phpmyadmin configuration file.
Open it
sudo scratch-text-editor /etc/phpmyadmin/config.inc.php

and add the following lines
$dbuser = 'root';
$dbpass = 'kenny';

after the lines
$cfg['Servers'][$i]['controluser'] = $dbuser;
$cfg['Servers'][$i]['controlpass'] = $dbpass;

Now phpmyadmin should recognize our username and password.

Addition


In this article, the connection of the project to the database was not considered. There are a lot of connection options both in procedural PHP and in object-oriented. The only thing I can say about this is that for any connection to a specific database, you will need to use the “root” user and the password that we specified when configuring the packages when installing them.

Also, the installation of mail north was not considered, since this is the topic of a separate article. Many mail servers are available in the repositories of any distributions, and each with its own nuances.

And in conclusion, I note that the configuration php.ini PHP configuration file is located in the / etc / php5 / apache2 / directory.

Good luck with your projects and clean code!

Also popular now: