Alexandria is believed to have been founded by Alexander the Great in April 332 BC as Ἀλεξάνδρεια (Alexandreía). Alexander's chief architect for the project was Dinocrates. Alexandria was intended to supersede Naucratis as a Hellenistic center in Egypt, and to be the link between Greece and the rich Nile valley. Although it has long been believed only a small village there, recent radiocarbon dating of seashell fragments and lead contamination show significant human activity at the location for two millennia preceding Alexandria's founding 
Alexandria was the intellectual and cultural center of the ancient world for some time. The city and its museum attracted many of the greatest scholars, including Greeks, Jews and Syrians. The city was later plundered and lost its significance.
In the early Christian Church, the city was the center of the Patriarchate of Alexandria, which was one of the major centers of early Christianity in the Eastern Roman Empire. In the modern world, the Coptic Orthodox Church and the Greek Orthodox Church of Alexandria both lay claim to this ancient heritage.
Just east of Alexandria (where Abu Qir Bay is now), there was in ancient times marshland and several islands. As early as the 7th century BC, there existed important port cities of Canopus and Heracleion. The latter was recently rediscovered under water.
An Egyptian city, Rhakotis, already existed on the shore and later gave its name to Alexandria in the Egyptian language (Egyptian *Raˁ-Ḳāṭit, written rˁ-ḳṭy.t, 'That which is built up'). It continued to exist as the Egyptian quarter of the city. A few months after the foundation, Alexander left Egypt and never returned to his city. After Alexander's departure, his viceroy, Cleomenes, continued the expansion. Following a struggle with the other successors of Alexander, his general Ptolemy Lagides succeeded in bringing Alexander's body to Alexandria, though it was eventually lost after being separated from its burial site there.
Although Cleomenes was mainly in charge of overseeing Alexandria's continuous development, the Heptastadion and the mainland quarters seem to have been primarily Ptolemaic work. Inheriting the trade of ruined Tyre and becoming the center of the new commerce between Europe and the Arabian and Indian East, the city grew in less than a generation to be larger than Carthage. In a century, Alexandria had become the largest city in the world and, for some centuries more, was second only to Rome. It became Egypt's main Greek city, with Greek people from diverse backgrounds.
Alexandria was not only a center of Hellenism, but was also home to the largest urban Jewish community in the world. The Septuagint, a Greek version of the Tanakh, was produced there. The early Ptolemies kept it in order and fostered the development of its museum into the leading Hellenistic center of learning (Library of Alexandria), but were careful to maintain the distinction of its population's three largest ethnicities: Greek, Jewish, and Egyptian. By the time of Augustus, the city walls encompassed an area of 5.34 sq.kilometres, and the total population in Roman times was around 500-600,000.
According to Philo of Alexandria, in the year 38 of the Common era, disturbances erupted between Jews and Greek citizens of Alexandria during a visit paid by the Jewish king Agrippa I to Alexandria, principally over the respect paid by the Jewish nation to the Roman emperor, and which quickly escalated to open affronts and violence between the two ethnic groups and the desecration of Alexandrian synagogues. The violence was quelled after Caligula intervened and had the Roman governor, Flaccus, removed from the city.
In AD 115, large parts of Alexandria were destroyed during the Kitos War, which gave Hadrian and his architect, Decriannus, an opportunity to rebuild it. In 215, the emperor Caracalla visited the city and, because of some insulting satires that the inhabitants had directed at him, abruptly commanded his troops to put to death all youths capable of bearing arms. On 21 July 365, Alexandria was devastated by a tsunami (365 Crete earthquake), an event annually commemorated years later as a "day of horror."
Entry of General Bonaparte into Alexandria
, oil on canvas, 365 cm × 500 cm (144 in × 197 in), ca. 1800, Versailles
The Islamic prophet Muhammad's first interaction with the people of Egypt occurred in 628, during the Expedition of Zaid ibn Haritha (Hisma). He sent Hatib bin Abi Baltaeh with a letter to the king of Egypt (in reality Emperor Heraclius) and Alexandria called Muqawqis In the letter Muhammad said: "I invite you to accept Islam, Allah the sublime, shall reward you doubly. But if you refuse to do so, you will bear the burden of the transgression of all the Copts". During this expedition one of Muhammad's envoys Dihyah bin Khalifa Kalbi was attacked, Muhammad sent Zayd ibn Haritha to help him. Dihya approached the Banu Dubayb (a tribe which converted to Islam and had good relations with Muslims) for help. When the news reached Muhammad, he immediately dispatched Zayd ibn Haritha with 500 men to battle. The Muslim army fought with Banu Judham, killed several of them (inflicting heavy casualties), including their chief, Al-Hunayd ibn Arid and his son, and captured 1000 camels, 5000 of their cattle and 100 women and boys. The new chief of the Banu Judham who had embraced Islam appealed to Muhammad to release his fellow tribesmen, and Muhammad released them.
In 619, Alexandria fell to the Sassanid Persians. Although the Byzantine Emperor Heraclius recovered it in 629, in 641 the Arabs under the general 'Amr ibn al-'As captured it during the Muslim conquest of Egypt, after a siege that lasted 14 months.
After the Battle of Ridaniya in 1517, the city was conquered by the Ottoman Turks and remained under Ottoman rule until 1798. Alexandria lost much of its former importance to the Egyptian port city of Rosetta during the 9th to 18th centuries, and only regained its former prominence with the construction of the Mahmoudiyah Canal in 1807.
Alexandria figured prominently in the military operations of Napoleon's expedition to Egypt in 1798. French troops stormed the city on 2 July 1798, and it remained in their hands until the arrival of a British expedition in 1801. The British won a considerable victory over the French at the Battle of Alexandria on 21 March 1801, following which they besieged the city, which fell to them on 2 September 1801. Muhammad Ali, the Ottoman governor of Egypt, began rebuilding and redevelopment around 1810, and by 1850, Alexandria had returned to something akin to its former glory. Egypt turned to Europe in their effort to modernize the country. Greeks, followed by other Europeans and others, began moving to the city. In the early 20th century, the city became a home for novelists and poets.
In July 1882, the city came under bombardment from British naval forces and was occupied.
In July 1954, the city was a target of an Israeli bombing campaign that later became known as the Lavon Affair. On 26 October 1954, Alexandria's Mansheya Square was the site of a failed assassination attempt on Gamal Abdel Nasser.
Europeans began leaving Alexandria following the 1956 Suez Crisis that led to an outburst of Arab nationalism. The nationalization of property by Nasser, which reached its highest point in 1961, drove out nearly all the rest.
Ibn Battuta in Alexandria
In reference to Alexandria, Egypt, Ibn Battuta speaks of great saints that resided here. One of them being Imam Borhan Oddin El Aaraj. He was said to have the power of working miracles. He told Ibn Battuta that he should go find his three brothers, Farid Oddin, who lived in India, Rokn Oddin Ibn Zakarya, who lived in Sindia, and Borhan Oddin, who lived in China. Battuta then made it his purpose to find these people and give them his compliments. Sheikh Yakut was another great man. He was the disciple of Sheikh Abu Abbas El Mursi, who was the disciple of Abu El Hasan El Shadali, who is known to be a servant of God. Abu Abbas was the author of the Hizb El Bahr and was famous for piety and miracles. Abu Abd Allah El Murshidi was a great interpreting saint that lived secluded in the Minyat of Ibn Murshed. He lived alone but was visited daily by emirs, viziers, and crowds that wished to eat with him. The Sultan of Egypt (El Malik El Nasir) visited him, as well. Ibn Battuta left Alexandria with the intent of visiting him.
The most important battles and sieges of Alexandria include: