Setting up for local development of a website
A very popular choice when setting up an Internet development environment is the LAMP stack. LAMP stands for Linux, Apache, MySQL and PHP. Combining these four software packages makes for a solid and completely open-source base to develop websites and Internet applications on your own computer before publishing them online.
Step 0: Linux
I am going to assume the you have already set up a working computer with some flavor of Linux. The instructions here are for Ubuntu, but other distributions will be very similar.
Step 1: Apache
Apache HTTP Server is an extremely popular open-source web server. We are going to use it to host our local copies of the websites we are working on.
To install Apache on Ubuntu:
sudo apt install apache2
To check if it works, navigate to
http://localhost/ with a browser. You should be greeted by a welcome page with some configuration details and a big friendly “It works!”.
Step 2: MySQL
The next item on our list is the database server. Technically a website doesn’t need a database, but the vast majority certainly do, especially when you start making something a little more complex. MySQL is a very popular choice for a data server.
Install MySQL server:
sudo apt install mysql-server
Whilst installing this may ask you to create a password for the
root user. Pick one and remember it – you’ll need it later.
If it doesn’t, we need to set one. By default, MySQL server 5.7 leaves the
root user password empty, but phpMyAdmin doesn’t allow us to log in without a password, so we need to set it. Summarizing from this guide:
- Log in to MySQL by running
sudo mysql -u root. Notice we don’t need a password for this.
- Prevent user
rootfrom being authenticated with the
auth_socketplugin and reset the password. Run
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'test';, where instead of
testyou’ll have your chosen password.
- Disconnect by running
exitand test by running
mysql -u root -p. This should prompt you for the password you just gave.
Step 3: phpMyAdmin
phpMyAdmin is a very popular database client. This tool allows us to interact with the database through the browser, and create users, tables, etc.
Because phpMyAdmin requires PHP, that will also be installed if you don’t have it already.
sudo apt install phpmyadmin
If you have a web server other than
apache2 installed, this will ask you which one should be configured to work with phpMyAdmin. Select
apache2. Next, it will ask whether it should automatically configure the database. Go ahead and select “Yes”. Finally, you will be prompted to create a password, which phpMyAdmin will use to access the database.
Now if you navigate to
http://localhost/phpmyadmin you’ll most likely get a
404 Not Found error. In order to properly configure Apache to work with phpMyAdmin, we’ll have to add phpMyAdmin’s configuration to Apache’s. This is pretty straightforward, actually: open
/etc/apache2/apache2.conf with any text editor (make sure to use
sudo nano /etc/apache2/apache2.conf
Then add the following line to the bottom of the file, to include phpMyAdmin’s configuration:
# phpMyAdmin Configuration Include /etc/phpmyadmin/apache.conf
Save and close, then restart the Apache server:
sudo service apache2 restart
Hooray! Navigating to
http://localhost/phpmyadmin should now greet you with the login page. You can use the user
root and the password you created earlier when installing MySQL to log in the first time.