Skip to content

Instantly share code, notes, and snippets.

@dipanshuchaubey
Last active March 5, 2024 14:28
Show Gist options
  • Save dipanshuchaubey/757f261cfa805ab8bea0b7ee6d450537 to your computer and use it in GitHub Desktop.
Save dipanshuchaubey/757f261cfa805ab8bea0b7ee6d450537 to your computer and use it in GitHub Desktop.
How to setup LAMP server on Linux

Installing LAMP server on Linux

Step by step guide to install LAMP server on Linux.

Installation

Use the terminal to execute these commands

Install Apache

sudo apt install apache2

Install MySQL

sudo apt install mysql-server

After installation run this command to remove some dangerous defaults and lock down access to your database system.

sudo mysql_secure_installation

This will ask if you want to configure the VALIDATE PASSWORD PLUGIN.

Answer Y for yes, or anything else to continue without enabling.

Remove anonymous users? : Y

Disallow root login remotely? : Y

Remove test database and access to it? : Y

Reload privilege tables now? : Y

Now enter mysql

sudo mysql

View all user accounts using

mysql> SELECT user,authentication_string,plugin,host FROM mysql.user;

Now, to set a new password for root user, replace 'password' with your own password.

mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';

run FLUSH PRIVILEGES which tells the server to reload the grant tables and put your new changes into effect:

mysql> FLUSH PRIVILEGES;
mysql> SELECT user,authentication_string,plugin,host FROM mysql.user;

Exit Mysql

mysql> exit

Install PHP

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

Type this command to open the dir.conf file in a text editor with root privileges:

<IfModule mod_dir.c>
    DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm
</IfModule>

Now restart apache server

sudo systemctl restart apache2

Install phpmyAdmin

sudo apt install phpmyadmin php-mbstring php-gettext

If you get any error after running above code such as:

E: Package 'phpmyadmin' has no installation candicate

Then this means your system does not have the required repository in your system, To add it run

sudo add-apt-repository ppa:phpmyadmin/ppa
sudo apt-get update
sudo apt-get install phpmyadmin

Warning: When the prompt appears, “apache2” is highlighted, but not selected. If you do not hit SPACE to select Apache, the installer will not move the necessary files during installation.

For the server selection, choose apache2

Select Yes when asked whether to use dbconfig-common to set up the database

You will then be asked to choose and confirm a MySQL application password for phpMyAdmin

Finally run:

sudo phpenmod mbstring

And restart the server.

Helpful resources

If you get something like count(); error in your database, refer to this post.

Also refer article for installation.

License

MIT

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment